总装科 [英] Assembly Division

查看:170
本文介绍了总装科的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的节目,一个十六进制数被除以10,其余的检查。

In my program, a hex number is divided by ten and the remainder is checked.

第一次分裂的表现不错;然而,第二次分裂后,程序出错。我是新来组装,而我找不到问题出在哪里?

First division is performed well; however, after the second division, the program goes wrong. I am new to assembly, and I couldn't find where the problem is...

下面是code段:

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

感谢您的帮助!

推荐答案

DIV BX 指令把在 32位在DX值:通过BX AX。既然你不进行初始化DX,被除数的高位字是什么垃圾留在从previous计算DX寄存器,所以你真的除以0x00040078 = 10。262314的结果是正确的:一个商数的26231与4的余数。

The DIV BX instruction divides the 32-bit value in DX:AX by BX. Since you're not initializing DX, the upper word of the dividend is whatever garbage was left in the DX register from the previous computation, so you're really dividing 0x00040078=262314 by 10. The result is correct: a quotient of 26231 with a remainder of 4.

在第一次分裂是一定是幸运,DX正好是0开始。

In the first division is must have been pure luck that DX happened to be 0 initially.

这篇关于总装科的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆