Results 1 to 5 of 5

Thread: illegal number of operands.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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

  2. #2
    Guest
    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.

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Your problem is with the mul instruction. What it does, is multiply the value in eax by the supplied value. So, just replace with:
    Code:
    mul ebx
    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

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    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

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width