1

I tried to convert and interpret C language code into assembly language with GCC -S option. What is the difference between push %rbp and push rbp?

hidefromkgb
  • 5,537
  • 1
  • 12
  • 41
김우진
  • 11
  • 1
  • 1
    `gcc -masm=intel` will use Intel syntax, the default is `-masm=att`. Pick whichever you find easier to read. See [How to remove "noise" from GCC/clang assembly output?](https://stackoverflow.com/q/38552116) – Peter Cordes May 29 '22 at 08:48

1 Answers1

3

Both statements you gave do the same thing, the main difference is in the syntax.
There are 2 major syntax conventions for X86, the Intel convention and the AT&T convention.
See syntax comparison for details.

[UPD:] Just in case, duplicating the syntax information here:

AT&T Intel
Parameter order Source before the destination.
movl $5, %eax
Destination before source.
mov eax, 5
Parameter size Mnemonics are suffixed with a letter indicating the size of the operands: q for qword, l for long (dword), w for word, and b for byte.
addl $4, %esp
Derived from the name of the register that is used (e.g. rax, eax, ax, al imply q, l, w, b, respectively).
add esp, 4
Sigils Immediate values prefixed with a $, registers prefixed with a %. The assembler automatically detects the type of symbols; i.e., whether they are registers, constants or something else.
Effective addresses General syntax of DISP(BASE,INDEX,SCALE).
movl mem_addr(%ebx,%ecx,4), %eax
Arithmetic expressions in square brackets; additionally, size keywords like byte, word, or dword have to be used if the size cannot be determined from the operands.
mov eax, [ebx + ecx*4 + mem_addr]
hidefromkgb
  • 5,537
  • 1
  • 12
  • 41
  • 1
    https://stackoverflow.com/tags/intel-syntax/info and https://stackoverflow.com/tags/att/info have similar info and syntax examples. Both linked from https://stackoverflow.com/tags/x86/info – Peter Cordes May 29 '22 at 08:47