繁体   English   中英

x86汇编对16位及更高位的指令操作数进行乘法和除法

[英]x86 assembly multiply and divide instruction operands, 16-bit and higher

我对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 num1num2分别移动到axbx ,然后将它们相乘以获得eax的产品?

快速浏览一下文档就会发现MUL有4种可能的操作数大小。 输入和输出汇总在一个方便的表格中:

------------------------------------------------------
| Operand Size | Source 1 | Source 2   | Destination |
------------------------------------------------------
| Byte         | AL       | r/m8       | AX          |
| Word         | AX       | r/m16      | DX:AX       |
| Doubleword   | EAX      | r/m32      | EDX:EAX     |
| Quadword     | RAX      | r/m64      | RDX:RAX     |
------------------------------------------------------

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM