|
-
Oct 21st, 2000, 12:55 PM
#1
Thread Starter
Frenzied Member
I'm just starting with this crazy language and in theory this is a function that calculates the factorial of an integer (I'm using inline assembly in VC++)
Code:
int factorial(int number)
{
int i;
__asm
{
mov eax, 1 ; eax is the return value (start at 1)
mov ebx, 0 ; ebx is the counter
mov ecx, number ; ecx is the number we are counting to
strt: ; Start of loop
add ebx, 1 ; add 1 to the counter
mul eax, ebx ; multiply by the counter (at this point eax = ebx!)
cmp ebx, ecx ;*************
jl strt ; If the counter is less than number go back to the start of the loop
}
}
but it refuses to complile, it claims there is an error (illegal number of operands) on the
cmp ebx, ecx
line (marked with a big load of stars)
i'm pretty sure it requires 2 operands, and I'm pretty sure I gave it 2 operands, so why won't it work
-
Oct 21st, 2000, 01:22 PM
#2
When VC++ compiler inline asm, and it gives an error on line 57, the actual error is one line up. So the error would be on 56, or the next line up with code. I dont know how to help your problem, but i thought youd like to know this.
-
Oct 21st, 2000, 01:28 PM
#3
Monday Morning Lunatic
Your problem is with the mul instruction. What it does, is multiply the value in eax by the supplied value. So, just replace with:
for the desired effect.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 21st, 2000, 01:49 PM
#4
Thread Starter
Frenzied Member
Thanx, I'd actually solved it by changing mul to imul, which did the same thing. but now I know what the mul function does. and I'm eternally greatful
-
Oct 21st, 2000, 01:52 PM
#5
Monday Morning Lunatic
Be warned - imul multiplies two signed integers...so you may get dodgy results with higher numbers.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
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
|