问题描述
我相当困惑的乘法和除法运算在x86汇编是如何工作的。例如,code以下似乎并不因为8位交易太难了。
8位乘法:
;用户输入:
; [NUM1] 20
; [NUM2] 15MOV AX,[NUM1]的8位移动到AL
MOV BX,[NUM2];移动8位转换成BLMUL BL;产品存放在AX打印斧
但是,当你想将两个16位数字会发生什么?如何将一个乘以同样的方式两个16位的数字,因为它已经与8位数字做了什么?
我很困惑,什么寄存器的值将被存储在。他们会被储存在AL和AH或将其简单地存放在AX中的16位数字。为了说明我的意思:
;用户输入:
; [NUM1] 20
; [NUM2] 15MOV EAX,[NUM1]这是否商店AL和AH或者只是在AX中的16位数字
MOV EBX,[NUM2];这是否存储了16位数字的BL和BH或只是在BXMUL? ;该寄存器依赖于16位数字的存储位置打印EAX
可能有人阐述如何乘法和分裂的作品一点? (具体地,16位和32位数字?会我需要旋转位如果值被存储在低Al和AH
,也可以一边简 MOV NUM1
和 NUM2
到斧
和 BX
分别再乘他们获得 EAX
?
一个快速浏览一下documentation显示,有4种可能的操作数大小 MUL
。输入和输出中总结了一个方便的表
-------------------------------------- ----------------
|操作数大小|源1 |源2 |目的地|
-------------------------------------------------- ----
|字节| AL | R / M8 | AX |
|单词| AX | R / M16 | DX:AX |
|双字| EAX | R / M32 | EDX:EAX |
|四字| RAX | R / M64 | RDX:RAX |
-------------------------------------------------- ----
I'm rather confused about how the multiply and divide operations work in x86 assembly. For example, the code below doesn't seem too difficult since deals with 8-bit.
8-Bit Multiplication:
; 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
But what happens when you want to multiply two 16-bit numbers? How would one multiply two 16 bit numbers the same way as it has been done with the 8 bit numbers?
I'm confused as to what registers the values would be stored in. Would they be stored in AL and AH or would it simply store the 16-bit number in AX. To show what I mean:
; 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
Could someone elaborate a bit on how the multiplying and dividing works? (specifically with 16-bit and 32-bit numbers? Would I need to rotate bits if the values are stored in the lower AL and AH?
Or can one simply mov num1
and num2
into ax
and bx
respectively and then multiply them to get the product in eax
?
A quick glance at the documentation shows that there are 4 possible operand sizes for MUL
. The inputs and outputs are summarized in a handy table:
------------------------------------------------------
| 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 |
------------------------------------------------------
这篇关于x86汇编乘法和除法指令操作数,16位和更高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!