0

I study on a tutorial and there is a c code like that

void function(int a, int b, int c) {
   char buffer1[5];
   char buffer2[10];
}

void main() {
   function(1,2,3);
}

He says after compile this code using gcc with -S switch we will get an assembly result like that

pushl $3
pushl $2
pushl $1
call function

However when I compile it my main part looks like

main:
.LFB1:
.cfi_startproc
endbr64
pushq   %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq    %rsp, %rbp
.cfi_def_cfa_register 6
movl    $3, %edx
movl    $2, %esi
movl    $1, %edi
call    function
nop
popq    %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc

Are both meaning the same or am I doing wrong with somewhere?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 7
    You compiled for 64 bit, while the tutorial is for 32. Use `gcc -m32`. Even then there is no guarantee you will get the same output. – Jester Apr 17 '21 at 18:45
  • 1
    there is no reason to expect any two compilers, any version of the same compiler, all the different command line options of a compiler, to produce the same output as any other combination. – old_timer Apr 17 '21 at 21:04
  • the only expectation is that the output is a functional equivalent of the high level language. – old_timer Apr 17 '21 at 21:06
  • Related: [Compiling C to 32-bit assembly with GCC doesn't match a book](https://stackoverflow.com/q/64109864) re: getting GCC to simplify its asm output to match old tutorials (from before `-fpie` was the default, and before 16-byte stack alignment, etc.) – Peter Cordes Apr 17 '21 at 23:26

0 Answers0