c - What do the instructions mov %edi and mov %rsi do? -
i've written basic c program defines integer variable x, sets 0 , returns value of variable:
#include <stdio.h> int main(int argc, char **argv) { int x; x = 0; return x; }
when dump object code using objdump (compiled on linux x86-64 gcc):
0x0000000000400474 <main+0>: push %rbp 0x0000000000400475 <main+1>: mov %rsp,%rbp 0x0000000000400478 <main+4>: mov %edi,-0x14(%rbp) 0x000000000040047b <main+7>: mov %rsi,-0x20(%rbp) 0x000000000040047f <main+11>: movl $0x0,-0x4(%rbp) 0x0000000000400486 <main+18>: mov -0x4(%rbp),%eax 0x0000000000400489 <main+21>: leaveq 0x000000000040048a <main+22>: retq
i can see function prologue, before set x 0 @ address 0x000000000040047f
there 2 instructions move %edi , %rsi onto stack. these for?
in addition, unlike set x 0, mov instruction shown in gas syntax not have suffix.
if suffix not specified, , there no memory operands instruction, gas infers operand size size of destination register operand.
in case, -0x14(%rsbp)
, -0x20(%rbp)
both memory operands , sizes? since %edi 32 bit register, 32 bits moved -0x14(%rsbp)
whereas since %rsi 64 bit register, 64 bits moved %rsi,-0x20(%rbp)
?
in simple case, why don't ask compiler directly? gcc, clang , icc there's -fverbose-asm
option.
main: pushq %rbp # movq %rsp, %rbp #, movl %edi, -20(%rbp) # argc, argc movq %rsi, -32(%rbp) # argv, argv movl $0, -4(%rbp) #, x movl -4(%rbp), %eax # x, d.2607 popq %rbp # ret
so, yes, save argv
, argv
onto stack using "old" frame pointer method since new architectures allow subtracting/adding from/to stack pointer directly, omitting frame pointer (-fomit-frame-pointer
).
Comments
Post a Comment