Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly x86汇编乘法和除法指令操作数,16位及更高_Assembly_X86_Division_Multiplication - Fatal编程技术网

Assembly x86汇编乘法和除法指令操作数,16位及更高

Assembly x86汇编乘法和除法指令操作数,16位及更高,assembly,x86,division,multiplication,Assembly,X86,Division,Multiplication,我对乘法和除法运算在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

我对乘法和除法运算在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中,还是只存储在AX中的16位数字。为了说明我的意思:

; 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
中的乘积吗?

快速浏览一下,就会发现
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     |
------------------------------------------------------

你试着读了吗?我看了一下,知道值在
mul
之后存储在哪里。我想知道,当我在
eax
中存储值时(在
mul
之前),它是否存储在低位(AL和AH),而不是高位(AX)。如果它确实将它们存储在低位,我是否能够将它们旋转到AX,然后将AX和BX相乘,并打印出答案(我相信它会在EAX中)?如果你在
eax
中存储了一个值,那么它在所有
eax
中都存储了。我不确定我是否理解。我想你可能会混淆
eax
的哪些部分是
ah
al
ax
。你可以在同一文档的第1卷中看到图表。特别是,
ax
是指同一个bits as
ah:al
,而不是“上部”16位
eax
。关闭,但产品将位于
DX:AX
。检查我的答案中的表格。确实如此-DX是16位,AX是16位。这使DX:AX成为32位数字。16+16=32,对吗?AX已经在那里-它是eax的底部16位。您需要将DX的一半向上移动到eax的上半部分,是的。