2

I am new to assembly and am trying to learn it by disassembling C code. I understand the basics but something has been bothering me for a while now.

Here is the output of an objdump with the -S and -d options used on a simple C program. The C program was compiled using gcc on an x64 machine.

00000000004004ac <main>:
#include<stdio.h>

int main(int argc, char *argv[]){
  4004ac:   55                      push   %rbp
  4004ad:   48 89 e5                mov    %rsp,%rbp
  4004b0:   89 7d fc                mov    %edi,-0x4(%rbp)
  4004b3:   48 89 75 f0             mov    %rsi,-0x10(%rbp)
    return 0;       
  4004b7:   b8 00 00 00 00          mov    $0x0,%eax
}

I added the -S flag so the C code could be seen. What i find strange is the

mov    %rsi,-0x10(%rbp)

statement. I understand that the statement mov %edi,-0x4(%rbp) means that it copied the contents of int argc on the first 4 bytes below the top of the stack. What I dont understand is why the next statement allocated 12 bytes for the char ** parameter when the size of a pointer in C is only 8 bytes. I have noticed this when I pass an int and a pointer as parameters to a function. It always seems to allocate 12 bytes for the pointer instead of the expected 8 bytes. An explanation to this will truly be appreciated :). Thank you.

EDIT

I am new to this and I do not know how and the order at which local variables and parameters are assigned memory from the stack frame. If someone can explain this process or provide resources that I could read on, it will truly be appreciated.

EDIT 2

Thank you for that reference and sorry for the duplicate. I did not have the proper keywords to successfully search that question.

MykelXIII
  • 1,085
  • 1
  • 8
  • 16

0 Answers0