I have an exam comming up, and I'm strugling with assembly. I have written some simple C code, gotten its assembly code, and then trying to comment on the assembly code as practice. The C code:
#include <stdio.h> #include <stdlib.h> int main(int argc, char const *argv[]) { int x = 10; char const* y = argv[1]; printf("%s\n",y ); return 0; } Its assembly code:
0x00000000000006a0 <+0>: push %rbp # Creating stack 0x00000000000006a1 <+1>: mov %rsp,%rbp # Saving base of stack into base pointer register 0x00000000000006a4 <+4>: sub $0x20,%rsp # Allocate 32 bytes of space on the stack 0x00000000000006a8 <+8>: mov %edi,-0x14(%rbp) # First argument stored in stackframe 0x00000000000006ab <+11>: mov %rsi,-0x20(%rbp) # Second argument stored in stackframe 0x00000000000006af <+15>: movl $0xa,-0xc(%rbp) # Value 10 stored in x's address in the stackframe 0x00000000000006b6 <+22>: mov -0x20(%rbp),%rax # Second argument stored in return value register 0x00000000000006ba <+26>: mov 0x8(%rax),%rax # ?? 0x00000000000006be <+30>: mov %rax,-0x8(%rbp) # ?? 0x00000000000006c2 <+34>: mov -0x8(%rbp),%rax # ?? 0x00000000000006c6 <+38>: mov %rax,%rdi # Return value copied to 1st argument register - why?? 0x00000000000006c9 <+41>: callq 0x560 # printf?? 0x00000000000006ce <+46>: mov $0x0,%eax # Value 0 is copied to return register 0x00000000000006d3 <+51>: leaveq # Destroying stackframe 0x00000000000006d4 <+52>: retq # Popping return address, and setting instruction pointer equal to it Can a friendly soul help me out wherever I have "??" (meaning I don't understand what is happening or I'm unsure)?
gcc -c -S -fverbose-asm file.c- that should generatefile.swith commented ASM