装配司

ciy*_*iyo 4 x86 assembly division

在我的程序中,十六进制数除以十,其余部分被检查.

第一师表现良好; 然而,在第二次分裂后,程序出错了.我是装配新手,我找不到问题所在......

这是代码段:

ORG 1000

    MOV AX, 0x04B4 (1204 decimal value )
    MOV BX, 0x000A ( 10 decimal value )
    MOV CX, 0x0000

    DIV BX ( After this part, AX is 120 decimal and DX 4 decimal )

    CMP DX, 0x0000
    JE eq1

    ADD CX, 0x0002
    JMP con1

    eq1:    ADD CX, 0x0001  

    con1:

    DIV BX ( But, after this division AX becomes 6677 ( 26231 decimal and DX remains 4 decimal )
    CMP DX, 0x0000
Run Code Online (Sandbox Code Playgroud)

感谢帮助!

Hen*_*olm 11

DIV BX指令将DX:AX中的32位值除以BX.由于你没有初始化DX,被除数的高位字是从前一次计算中留在DX寄存器中的任何垃圾,所以你真的将0x00040078 = 262314除以10.结果是正确的:商数为26231剩下的4.

在第一个分区中一定是纯粹的运气,DX最初恰好是0.