assembly - 如何计算8086 IDIV指令的结果?

标签 assembly x86-16

说明(十六进制数字):

mov ax, 0832
mov cx, 008a
idiv cl

文档说:

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

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

据我了解,我必须检查最左边的位是否不是 1:

0832 -> 0000.1000.0011.0010
008a -> 0000.0000.1000.1010

由于最高位没有 1,通过使用计算器我应该得到:

0832 mod 008a 作为余数,0832 div 008a 作为 div 部分。 Mod 转到 AHdiv 应该转到 AH,但我无法得到正确的答案。正确答案是5CEF。我做错了什么?

最佳答案

+1 用于阅读文档:)

注意,需要根据有效操作数大小检查最左边的位。由于您要除以 CL(这是一个 8 位值),因此您需要检查位 #7,即 1。因此,CL 中的数字为负数,即 -118。所以,

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

关于assembly - 如何计算8086 IDIV指令的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33134692/

相关文章:

assembly - 在 8086 中使用 16 位寄存器操作 32 位数字

if-statement - 代码执行条件错误?

assembly - x86 的汇编程序如何获取在 jmp 指令引用后定义的标签地址?

c++ - 图形驱动程序如何以编程方式从 CPU 到 GPU 进行通信?

assembly - 如何检查emu8086中CF标志是否为1?

assembly - 向量汇编中的元素求和

c - 将C函数转换为MIPS程序集

c - 在内联汇编器中使用寄存器

c - outportb和8086汇编中的out指令有明显区别吗?

assembly - 划分EMU 8086组装错误