32-bit multiplication with 16-bit registers - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

32-bit multiplication with 16-bit registers

Seijuro_HikoSeijuro_Hiko Posts: 31Member
Not sure how to preceed with this program. Its a program that will multiply 2 32-bit numbers on 16-bit registers. The final outcome will be that registers AX BX CX DX will hold the 32-bit solution. This is what I have so far....Thanks for your help!!
[code]

; num1 Low * num2 Low
mov ax, [num2]
mov bx, [num4]
mul bx
mov [temp], ax
mov [temp1], dx

; num2 low * num1 high
mov ax, [num1]
mov bx, [num4]
mul bx
mov [temp2], ax
mov [temp+6], dx

; num1 low * num2 high
mov ax, [num2]
mov bx, [num3]
mul bx
mov [temp3+3], ax
mov [temp+10], dx

; num1 high * num2 high
mov ax, [num1]
mov bx, [num3]
mul bx
mov [temp4+4]. ax
mov [temp+14], dx

;*********************Addition************************************************

mov ax, [temp1]
mov bx, [temp+6]
mov cx, 0
mov dx, 0
add ax, bx
adc cx, 0
mov word [result], ax

mov ax, [result]
mov bx, [temp+10]
mov cx, 0
mov dx, 0
add ax, bx
adc cx, 0
mov word [result+4], ax

adc ax, cx
adc dx, 0
mov dx, [result+8]
Data:
num1 dw 0xFE1F
num2 dw 0x3699
num3 dw 0x0987
num4 dw 0x6543
result times 20 dw 0x00000000
temp dw 0x00000000
temp1 dw 0x00000000
temp2 dw 0x00000000
temp3 dw 0x00000000
temp4 dw 0x00000000
temp5 dw 0x00000000
[/code]

Comments

  • PharabeePharabee Posts: 84Member
    : Not sure how to preceed with this program. Its a program that will multiply 2 32-bit numbers on 16-bit registers. The final outcome will be that registers AX BX CX DX will hold the 32-bit solution. This is what I have so far....Thanks for your help!!
    : [code]
    :
    : ; num1 Low * num2 Low
    : mov ax, [num2]
    : mov bx, [num4]
    : mul bx
    : mov [temp], ax
    : mov [temp1], dx
    :
    : ; num2 low * num1 high
    : mov ax, [num1]
    : mov bx, [num4]
    : mul bx
    : mov [temp2], ax
    : mov [temp+6], dx
    :
    : ; num1 low * num2 high
    : mov ax, [num2]
    : mov bx, [num3]
    : mul bx
    : mov [temp3+3], ax
    : mov [temp+10], dx
    :
    : ; num1 high * num2 high
    : mov ax, [num1]
    : mov bx, [num3]
    : mul bx
    : mov [temp4+4]. ax
    : mov [temp+14], dx
    :
    : ;*********************Addition************************************************
    :
    : mov ax, [temp1]
    : mov bx, [temp+6]
    : mov cx, 0
    : mov dx, 0
    : add ax, bx
    : adc cx, 0
    : mov word [result], ax
    :
    : mov ax, [result]
    : mov bx, [temp+10]
    : mov cx, 0
    : mov dx, 0
    : add ax, bx
    : adc cx, 0
    : mov word [result+4], ax
    :
    : adc ax, cx
    : adc dx, 0
    : mov dx, [result+8]
    : Data:
    : num1 dw 0xFE1F
    : num2 dw 0x3699
    : num3 dw 0x0987
    : num4 dw 0x6543
    : result times 20 dw 0x00000000
    : temp dw 0x00000000
    : temp1 dw 0x00000000
    : temp2 dw 0x00000000
    : temp3 dw 0x00000000
    : temp4 dw 0x00000000
    : temp5 dw 0x00000000
    : [/code]
    :

    If you mul a word register the value is stored at DX:AX.

  • Seijuro_HikoSeijuro_Hiko Posts: 31Member
    : : Not sure how to preceed with this program. Its a program that will multiply 2 32-bit numbers on 16-bit registers. The final outcome will be that registers AX BX CX DX will hold the 32-bit solution. This is what I have so far....Thanks for your help!!
    : : [code]
    : :
    : : ; num1 Low * num2 Low
    : : mov ax, [num2]
    : : mov bx, [num4]
    : : mul bx
    : : mov [temp], ax
    : : mov [temp1], dx
    : :
    : : ; num2 low * num1 high
    : : mov ax, [num1]
    : : mov bx, [num4]
    : : mul bx
    : : mov [temp2], ax
    : : mov [temp+6], dx
    : :
    : : ; num1 low * num2 high
    : : mov ax, [num2]
    : : mov bx, [num3]
    : : mul bx
    : : mov [temp3+3], ax
    : : mov [temp+10], dx
    : :
    : : ; num1 high * num2 high
    : : mov ax, [num1]
    : : mov bx, [num3]
    : : mul bx
    : : mov [temp4+4]. ax
    : : mov [temp+14], dx
    : :
    : : ;*********************Addition************************************************
    : :
    : : mov ax, [temp1]
    : : mov bx, [temp+6]
    : : mov cx, 0
    : : mov dx, 0
    : : add ax, bx
    : : adc cx, 0
    : : mov word [result], ax
    : :
    : : mov ax, [result]
    : : mov bx, [temp+10]
    : : mov cx, 0
    : : mov dx, 0
    : : add ax, bx
    : : adc cx, 0
    : : mov word [result+4], ax
    : :
    : : adc ax, cx
    : : adc dx, 0
    : : mov dx, [result+8]
    : : Data:
    : : num1 dw 0xFE1F
    : : num2 dw 0x3699
    : : num3 dw 0x0987
    : : num4 dw 0x6543
    : : result times 20 dw 0x00000000
    : : temp dw 0x00000000
    : : temp1 dw 0x00000000
    : : temp2 dw 0x00000000
    : : temp3 dw 0x00000000
    : : temp4 dw 0x00000000
    : : temp5 dw 0x00000000
    : : [/code]
    : :
    :
    : If you mul a word register the value is stored at DX:AX.
    :
    :
    Actually I figured it out. You don't declare the data values as dw, but as dd that way the data is stored as 8-bits. Then you just have to multiply then add. Pretty Simple :P Thanks for the help!
Sign In or Register to comment.