Computing.Net > Forums > Programming > 32 bit multiplication

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

32 bit multiplication

Reply to Message Icon

Original Message
Name: noonie
Date: September 28, 2002 at 14:44:00 Pacific
Subject: 32 bit multiplication
OS: windows
CPU/Ram: 256 mb
Comment:

what is the algorithm for performing 32 bit multiplication on an 8 bit processor?
given 4 registers ax,bx,cx,dx
Please help....
Thanks


Report Offensive Message For Removal


Response Number 1
Name: cup
Date: September 28, 2002 at 17:07:20 Pacific
Reply:

What processor are you using? Are ax, bx, cx and dx 16-bit or 8-bit registers?

On Intel 8085, they are A,B,C,D,E,H and L. On Intel 8086, which happens to be 16 bit, the 8 bit registers are AH, AL, BH, BL, CH, CL, DH, DL. AX etc are 16-bit registers.

The algorithm depends on the shift and rotate instructions available. Also, whether it has a multiply instruction or not (Motorola 6809 has but 6802 hasn't).


Report Offensive Follow Up For Removal

Response Number 2
Name: bitbyte
Date: September 28, 2002 at 19:57:47 Pacific
Reply:

is that what you want?

32bitvalue: [ax][bx] cx=multiplicator

assume cs:code,ds:code;
assume es:nothing,ss:nothing;
code segment
org 100h
start:
mov ax,0fh
mov bx,0ffffh
mov cx,3

mov oldbx,bx
mov oldax,ax
cmp cx,0
je @exit
@nxt0:
dec cx
cmp cx,0
je @exit
@nxt1:
add bx,oldbx
jnc @nxt2
inc ax
@nxt2:
add ax,oldax
jmp @nxt0
@exit:
int 3
int 20h
oldax dw ?
oldbx dw ?
code ends
end start

you can download the source from my page if needed
http://plop.at

see ya

greetings to all asm coder


Report Offensive Follow Up For Removal

Response Number 3
Name: bitbyte
Date: September 28, 2002 at 20:13:48 Pacific
Reply:

SORRY i forgot an explanation
my source makes a multiplication with
ax=hi of 32bit
bx=low of 32bit
cx=multipl.

FFFFFh * 3

output is in ax=hi bx=low
the source at my page shows it better



Report Offensive Follow Up For Removal

Response Number 4
Name: Jim
Date: September 29, 2002 at 00:30:59 Pacific
Reply:

You can do it much the same as you do longhand multiplication, only you'll be doing it base 256 instead of base 10.

Assuming ABCDEFG and H are 8 bit values, to do a 32 bit multiply you're going to multiply two 4-byte values, and potentially get an 8-byte result.

ABCD
EFGH
----
ABCD * H
ABCD * G * 100h
ABCD * F * 10000h
ABCD * E * 1000000h
-----------------------
Add them all up and you'll get the total. Notice that you don't really multiply by 100h and such, you just manipulate the index where you're storing the results in the product space.

Now, how to get ABCD * H

ABCD
H
----
D * H
C * H * 100h
B * H * 10000h
A * H * 1000000h
-----------------
Add them all up.

This would look a lot better in a picture. I'm sure if you've ever done longhand multiplication it would make lots of sense to you. There's really a pretty elegant way of putting it into assembly code. Really it's just a matter of multiplying each byte in one factor by each byte in the other factor, and adding the results into the proper place in your product. You do have to worry about carries quite a bit with your adds, but other than that it's pretty straightforward.


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home



Results for: 32 bit multiplication

16 bit programs runing on 32 bit machine
    Summary: For one thing Intel kept each generation of the 8086 microprocessor almost fully backwards- compatible. For example each 32- bit instruction has a prefix, and normal reigister use is permitted by usin...
www.computing.net/answers/programming/16-bit-programs-runing-on-32-bit-machine/65.html

Protected Mode And 32-bit Real Mode
    Summary: I'm writing my own operating system and I made lots of attempts to switch to Protected Mode, always crashing the system. Can someone tell me a good URL about switching to Protected Mode? Another quest...
www.computing.net/answers/programming/protected-mode-and-32bit-real-mode/10917.html

16 or 32 bits asm language
    Summary: Hi, I don't about 16 bits asm langugq, but i don't know how to write in 32-bits. eg. i can write a program which simple print a "Hello world" message, but how to write it in 32-bit asm language ? Well...
www.computing.net/answers/programming/16-or-32-bits-asm-language/1827.html








Which MP3 player do you have?

iPod/iPhone
Zune
Something Else
None


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History






Data Recovery Software