【发布时间】:2012-04-05 08:52:09
【问题描述】:
我对 x86 汇编中的乘法和除法运算如何工作感到很困惑。例如,下面的代码似乎并不太难,因为处理的是 8 位。
8 位乘法:
; User Input:
; [num1], 20
; [num2] , 15
mov ax, [num1] ; moves the 8 bits into AL
mov bx, [num2] ; moves the 8 bits into BL
mul bl ; product stored in AX
print ax
但是当您想将两个 16 位数字相乘时会发生什么?如何将两个 16 位数字相乘,就像用 8 位数字一样?
我很困惑这些值将存储在哪些寄存器中。它们是存储在 AL 和 AH 中,还是只是将 16 位数字存储在 AX 中。表达我的意思:
; User Input:
; [num1], 20
; [num2], 15
mov eax, [num1] ; Does this store the 16-bit number in AL and AH or just in AX
mov ebx, [num2] ; Does this store the 16-bit number in BL and BH or just in BX
mul ??? ; this register relies on where the 16-bit numbers are stored
print eax
有人可以详细说明乘法和除法的工作原理吗? (特别是 16 位和 32 位数字?如果值存储在较低的 AL 和 AH 中,我是否需要轮换位?
或者可以简单地将mov num1和num2分别转换成ax和bx,然后将它们相乘得到eax中的乘积?
【问题讨论】:
-
您是否尝试阅读documentation?
标签: assembly x86 division multiplication