簡體   English   中英

匯編 8088:使用 16 位寄存器進行加法和位操作的 32 位有符號乘法

[英]Assembly 8088: 32-bit signed Multiplication with addition and bit manipulation using 16-bit registers

我正在嘗試編寫匯編程序來將兩個 32 位有符號數相乘並將答案存儲在 64 位數字中,但我的代碼只給了我最多 32 位的正確答案。 我已經對它進行了檢查並搜索了許多網站,但無法滿足自己。 雖然我調試了很多次,但我無法解決問題。這是我作為學生的第一個問題,所以如果我不清楚,我真的很抱歉。謝謝:)

; 32bit multiplication 
[org 0x0100]
multiplicand dd 0,9000008             ; 32bit multiplicand 64bit space 
multiplier: dd 45009                  ; 32bit multiplier 
result: dd 0,0                        ; 64bit result 
start:
    mov cx,32                         ; initialize bit count to 32
    mov bx, [multiplier]              ; load multiplier in dx and bx
    mov dx, [multiplier+2]            

checkbit:
    sar dx,1                          ; move right most bit in carry 
    rcr bx,1
    jnc skip                          ; skip addition if bit is zero
    mov ax,[multiplicand]
    add word[result],ax
    mov ax,[multiplicand+2]
    adc word[result+2],ax
    mov ax,[multiplicand+4]
    adc word[result+4],ax
    mov ax,[multiplicand+6]
    adc word[result+6],ax
    mov ax,[multiplicand+8]
    adc word[result+8],ax
    mov ax,[multiplicand+10]
    adc word[result+10],ax
    mov ax,[multiplicand+12]
    adc word[result+12],ax
    mov ax,[multiplicand+14]
    adc word[result+14],ax

skip:
    shl word [multiplicand],1
    rcl word [multiplicand+2],1
    rcl word [multiplicand+4],1
    rcl word [multiplicand+6],1
    rcl word [multiplicand+8],1
    rcl word [multiplicand+10],1
    rcl word [multiplicand+12],1
    rcl word [multiplicand+14],1
    dec cx
    jnz checkbit

mov ax,0x4c00                         ; terminate program
int 0x21

我認為我的邏輯是正確的,但后來我無法理解錯誤是什么。 任何幫助表示贊賞。 :)

multiplicand dd 0,9000008             ; 32bit multiplicand 64bit space  

您設置了 64 位空間,但您的代碼修改了 128 位空間!!

也因為很少的endeanness,你應該交換被乘數的雙字。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM