|
-
Jan 8th, 2005, 09:36 AM
#1
Thread Starter
Ex-Super Mod'rater
How do you do Multiplication?
I'm using 68k and I can't figure out how you do multiplication, at the moment I'm just using left shifts and addition but there must be another way? Also if I needed to do none integer multiplication I don't have a clue how I'd go about that .
Last edited by Electroman; Jan 12th, 2005 at 11:07 AM.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Jan 12th, 2005, 10:28 AM
#2
Thread Starter
Ex-Super Mod'rater
Re: How do you do Multiplication?
Last edited by Electroman; Jan 12th, 2005 at 11:08 AM.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Jan 12th, 2005, 11:07 AM
#3
Thread Starter
Ex-Super Mod'rater
Re: How do you do Multiplication?
Sorry no its not sorted, I get an Opperand 1 error when i use that code .
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Jan 12th, 2005, 01:43 PM
#4
PowerPoster
Re: How do you do Multiplication?
I hear assemble math in some cases is alot faster than regular.
It would be great to have a Vector class built with operators working in ASM.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Jan 12th, 2005, 02:47 PM
#5
Hyperactive Member
Re: How do you do Multiplication?
 Originally Posted by Electroman
I'm using 68k and I can't figure out how you do multiplication, at the moment I'm just using left shifts and addition but there must be another way? Also if I needed to do none integer multiplication I don't have a clue how I'd go about that  .
Well in x86 you would use the FPU to do non-int math.
http://www.ray.masmcode.com/tutorial/index.html
mul for unsigned and imul for signed.
To be honest though, shl and shr is the faster way of doing multiplication and division.
Education is an admirable thing, but it is well to remember from time to time that nothing that is worth knowing can be taught. - Oscar Wilde
-
May 16th, 2005, 02:22 PM
#6
Fanatic Member
Re: How do you do Multiplication?
However, shl and shr only works if you are multiplying by a number that is base 2
"Can't" and "shouldn't" are two totally separate things.
All questions should be answered. All answers should be true. That is why I post.
-
May 16th, 2005, 03:01 PM
#7
Thread Starter
Ex-Super Mod'rater
Re: How do you do Multiplication?
 Originally Posted by Darkwraith
However, shl and shr only works if you are multiplying by a number that is base 2
Yea but as I said the idea was to use Binary shifts to get as close as I could then do a few additions to get to the exact number .
e.g.
a *9
Shift 'a' 3 times to the left
Then add 'a' onto that and you have it .
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
May 18th, 2005, 09:46 AM
#8
Re: How do you do Multiplication?
So similar to:
Code:
LOCAL a:DWORD
LOCAL b:DWORD
push 9
pop a
mov b,a
shl a,3
add b,a
?
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
May 18th, 2005, 06:54 PM
#9
Thread Starter
Ex-Super Mod'rater
Re: How do you do Multiplication?
 Originally Posted by chemicalNova
So similar to:
Code:
LOCAL a:DWORD
LOCAL b:DWORD
push 9
pop a
mov b,a
shl a,3
add b,a
?
chem
Yea apart from there would be code to control how many shifts would be required and even possibly code so that when adding on numbers it could reuse numbers passed on the shifts to make it even more efficient. But That was just my idea of making it with just using limited tools, I was more searching for a better way to do it if it exists in a single statement but it seemed not .
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
May 18th, 2005, 10:32 PM
#10
Re: How do you do Multiplication?
There could possibly be a 1 line statement which performs this, just not in the 8086 / family of instruction sets.
Try searching for different instruction sets/syntaxes, and reading up on their documentation.
chem
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Oct 24th, 2005, 03:24 PM
#11
Re: How do you do Multiplication?
For what its worth I solved this very problem because its a question in my ASM book.
It works on the premise of shifting the multiplicand left by x bits every time you find a 1 in the binary of the multiplier then you just add up all the shifted versions of the multiplicand.
I dare say its farfrom the most efficient longhand method, but it works and I'm proud of it .
Code:
;SYNTAX:
; mov eax, 1357
; mov ebx, 371
; CALL Multiply
;-------------------
Multiply PROC USES ecx edi esi
; Multiplies EAX by EBX and leaves the answer in EAX;
;-------------------
mov esi, 0 ; running total
mov ecx, 0 ; the loop counter and bit test value
L1:
bt ebx, ecx ; test the bit
jnc L2 ; jump if the bit is zero
mov edi, eax ; take a copy of the original eax value
shl edi, cl ; shift left
add esi, edi ; add it to the running total
L2:
inc ecx
cmp ecx, 32 ; stop after 32 bits
jb L1
mov eax, esi
ret
Multiply ENDP
I'm currently grappling with the bizarre way that MUL and DIV work.
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|