I have made a program that is supposed to check whether a number is positive, negative, or zero.
When I try to compile the code, it gives a improper operand type error, for line 28, which is the cmp opcode. Am I formatting it wrong, or is there some other problem here?
#include <stdio.h>
int input;
int output;
int main (void)
{
scanf("%d", &input);
__asm
{
jmp start
negative:
mov ebx, -1
ret
nuetral:
mov ebx, 0
ret
positive:
mov ebx, 1
ret
start:
mov eax, input
mov ebx, other
cmp 0, eax
jl negative
je neutral
jg positive
mov output, ebx
}
printf("%d\n", output);
}
The first operand of the
cmpinstruction must be a register or a memory location, not an immediate value. You need to usecmp eax, 0instead. This would also be consistent with your conditional jumps (jlwould jump ifeaxis negative, etc.).You may be confusing Intel assembly syntax (which you used) with AT&T syntax, where the order of operands is reversed.
Additionally, your usage of
retis incorrect:retis used to return from a function, but there is no function call here. What you need there is ajmpto themov output, ebxline.