I have the below snippet of code, and here I want to pass the value of variable num
by register rax, but it seems in the assembly code, clang doesn't use rax directly. Rather, it saves the value of num
on the stack and then passes the value on the stack to the rsi
register which the behavior is different from GCC. Why? BTW, I didn't use any optimization flags in the compilation command.
C Code:
#include <stdio.h>
int main(void) {
register long num asm("rax") = 0x100000000;
printf("%ld\n", num);
return 0;
}
Assembly Code (Clang):
main: # @main
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
movl $0, -4(%rbp)
movabsq $4294967296, %rax # imm = 0x100000000
movq %rax, -16(%rbp)
movq -16(%rbp), %rsi # <- here, for calling printf, the parameter is not passed directly from register, -
# but indirectly from a stack location. Why?
movabsq $.L.str, %rdi
movb $0, %al
callq printf
xorl