How to compute the result of 8086 IDIV instruction?

一个人想着一个人 提交于 2019-12-12 18:22:13

问题


Instructions (numbers in hex):

mov ax, 0832
mov cx, 008a
idiv cl

Documentation says:

when operand is a byte:
AL = AX / operand
AH = remainder (modulus)

Source: http://www.electronics.dit.ie/staff/tscarff/8086_instruction_set/8086_instruction_set.html#IDIV

As far as I understand, I have to check if the leftmost bit isn't 1:

0832 -> 0000.1000.0011.0010
008a -> 0000.0000.1000.1010

Since there's no 1's in highest bits, by using calculator I should get:

0832 mod 008a as remainder and 0832 div 008a as div part. Mod goes to AH and div should go to AH, but I can't get the correct answer. The correct answer is 5CEF. What am I doing wrong?


回答1:


+1 for reading the documentation :)

Note that you need to check the leftmost bit according to the effective operand size. Since you are dividing by CL, which is a 8 bit value, you need to check bit #7, which is 1. As such, the number in CL is negative, namely -118. So,

AL = 0832h / -118 = 2098 / -118 = -17 = EFh
AH = 2098 - (-17 * -118) = 92 = 5Ch


来源:https://stackoverflow.com/questions/33134692/how-to-compute-the-result-of-8086-idiv-instruction

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!