簡體   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