integer-division

EMU8086 dividing 32 bit number by a 16 bit number gives unexpected 0 remainder

不羁岁月 提交于 2021-01-03 07:04:33
问题 I was trying to divide (Unsigned) 8A32F4D5 by C9A5 using emu8086 tool. I expected the quotient to be AF73H and the remainder be 94B6H . After writing the following code, I was getting correct quotient but the remainder became 0000h . Am I missing something? .MODEL SMALL .STACK 100H .DATA .CODE MAIN PROC ; initialize DS MOV AX,@DATA MOV DS,AX ; enter your code here MOV DX, 8A32H MOV AX, 0F4D5H MOV BX, 0C9A5H DIV BX ;exit to DOS MOV AX,4C00H INT 21H MAIN ENDP END MAIN The output in EMU8086: 回答1

signed integer division with rounding in C

て烟熏妆下的殇ゞ 提交于 2020-02-23 10:25:10
问题 I'd like to calculate x/y where x and y are both signed integers, and get a result rounded to the nearest integer. Specifically, I'd like a function rquotient(x, y) using integer-only arithmetic such that: ASSERT(rquotient(59, 4) == 15); ASSERT(rquotient(59, -4) == -15); ASSERT(rquotient(-59, 4) == -15); ASSERT(rquotient(-59, -4) == 15); ASSERT(rquotient(57, 4) == 14); ASSERT(rquotient(57, -4) == -14); ASSERT(rquotient(-57, 4) == -14); ASSERT(rquotient(-57, -4) == 14); I've looked to S.O. for

Extracting Digits from an Integer in C?

你说的曾经没有我的故事 提交于 2020-01-24 20:36:26
问题 void print(int num, int digits) { double mod, divi; int mod1, divi1; mod = pow(10, digits); divi = pow(10, digits-1); mod1 = (int)mod; divi1 = (int)divi; if(digits > 0) { printf("%d\n", ((num%mod1)/divi1)); digits--; print(num, digits); } else { return; } } This function is meant to print the digits from num vertically, however when I run it the only thing it prints are 0's. I know it gets the correct number of digits because it prints the same number of zeroes as there are digits in the