PDA

Click to See Complete Forum and Search --> : illegal number of operands.


Sam Finch
Oct 21st, 2000, 01:55 PM
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++)



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, 02:22 PM
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.

parksie
Oct 21st, 2000, 02:28 PM
Your problem is with the mul instruction. What it does, is multiply the value in eax by the supplied value. So, just replace with:

mul ebx

for the desired effect.

Sam Finch
Oct 21st, 2000, 02:49 PM
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

parksie
Oct 21st, 2000, 02:52 PM
Be warned - imul multiplies two signed integers...so you may get dodgy results with higher numbers.