Sta*_*ovy 10 x86 assembly multiplication division
我对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
Run Code Online (Sandbox Code Playgroud)
但是当你想要乘以两个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
Run Code Online (Sandbox Code Playgroud)
有人可以详细说明乘法和除法的工作原理吗?(特别是16位和32位数字?如果值存储在较低的AL和AH中,我是否需要旋转位?
或者可以简单地一个mov num1
和num2
成ax
和bx
分别再乘他们得到的产品中eax
?
Car*_*rum 15
快速浏览文档可以看出,有4种可能的操作数大小MUL
.输入和输出汇总在一个方便的表格中:
------------------------------------------------------
| 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 |
------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
21307 次 |
最近记录: |