I’m trying to convert some c code to assmebly, and I need some help.
char encode(char plain){
__asm{
mov eax, plain
add eax, 2
ret
}
//C code
/*
char code;
code = plain+2;
return code;*/
}
First problem is that visual studio complains that the register size doesn’t match, i.e. eax is too small/large for char. I was under the impression that they were both DWORDs. Also, if I leave the variable in eax, and ret in assembly, it’ll actually return that variable, right?
Yes, at least with most C compilers on x86 (though it’s not theoretically guaranteed) whatever you put in [[e]a]x will be treated as a 1/2/4 byte return value.
No, char won’t (normally) be a dword — it’ll be a byte.