简体   繁体   English

汇编 8088:使用 16 位寄存器进行加法和位操作的 32 位有符号乘法

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

I am trying to write assembly program to multiply two 32-bit signed numbers and store the answer in 64-bit number but my code only gives me the correct answer up to 32-bits.我正在尝试编写汇编程序来将两个 32 位有符号数相乘并将答案存储在 64 位数字中,但我的代码只给了我最多 32 位的正确答案。 I have goggled it and searched many sites but can't satisfy myself.我已经对它进行了检查并搜索了许多网站,但无法满足自己。 I can't get the problem although i debugged it many times.This is my first question as a student so I am really sorry if I am unclear.Thanks :)虽然我调试了很多次,但我无法解决问题。这是我作为学生的第一个问题,所以如果我不清楚,我真的很抱歉。谢谢:)

; 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

I think my logic is right but then i can't get what the error is.我认为我的逻辑是正确的,但后来我无法理解错误是什么。 Any help is appreciated.任何帮助表示赞赏。 :) :)

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

You setup 64 bit space but your code modifies 128 bit space!!您设置了 64 位空间,但您的代码修改了 128 位空间!!

Also because of little endeanness you should swap the dwords of the multiplicand.也因为很少的endeanness,你应该交换被乘数的双字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM