I am trying to write code to read from a register, and this is what I still have:
unsigned int readEBX(void) {
register unsigned int reg asm("ebx");
return reg;
}
The function works, but it compiles into something strange:
readEBX():
mov eax, ebx
push ebx
pop ebx
ret
Why do this when you use push-then-pop ebx? Doesn't that mean anything? When I replace ebxwith a different register (say eaxor ecx), then it produces cleaner code (just a retand a mov eax, ecx; retrespectively).
See this example result of Godbolt .
source
share