汇编语言部门 - 剩余DX寄存器

时间:2012-02-28 08:15:41

标签: c assembly x86 inline-assembly division

我的程序差不多完成了。我试图将CBA0123h除以B000h。商出来了。但是,应该在dx寄存器中的余数应该是:EA61(http://www.miniwebtool.com/hex-calculator/?number1=CBA0123&operate=4&number2=B000),而是它的A123 。我认为这与小端或其他东西有关。但我需要解决这个问题。我怎么能够?我旋转位?我以前从未见过如何做到这一点。如何从这个除法问题中得到正确的余数?

int main(int argc, char* argv[])
{
unsigned short int IDQUO = 0x0;
unsigned short int IDREM = 0x0;

    mov     dx, 0CBAh       
    mov     ax, 0123h       
    mov     bx, 0B000h      
    div     bx              
    mov     IDQUO, ax       
    mov     IDREM, dx       
return(0);
}

2 个答案:

答案 0 :(得分:7)

CBA0123h = B000h * 1282 + A123h。 DX值是正确的。

答案 1 :(得分:3)

为什么你认为余数应该是0xea610xa123the correct answer

#include <stdio.h>

int main(void)
{
    printf("%x\n", 0xCBA0123 % 0xB000);
}

输出:a123

相关问题