In the following C code:
#include <stdio.h>
int main(void){getchar();}
It produces the following asm:
main:
push rbp
mov rbp, rsp
# no extra instruction here when header is included
call getchar
mov eax, 0
pop rbp
ret
However, if I don't include stdio.h
in the file, then it still compiles, but adds in what looks like a random mov eax, 0
instruction:
Here is Compiler Explorer: https://godbolt.org/z/3fTcss. Is this just part of "undefined behavior", or is there a particular reason that the instruction before call getchar
is added there?
al
. – Grimesal
only means the number of vector registers used which is maximum 8 (xmm0-xmm7). The rest of the arguments go on the stack. – Grimesxor
to cleareax
. – Fellmonger-O2
and above.mov
ing a zero in there is just the unoptimized, obvious, close-to-C version. – Rasia