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?
What does % mean on register names in assembly language?
215 Views Asked by 김우진 AtThere are 2 best solutions below
On
In AT&T syntax, push rbp would be a push of a memory operand, with symbol name rbp, like if you compiled some C code that used long rbp; as a global variable.
rbp doesn't have a % so the assembler knows you aren't referring to the register of the same name; that's how AT&T syntax disambiguates this case. If you do want the register, you must use % like %rbp.
- Questions about AT&T x86 Syntax design
- What was the original reason for the design of AT&T assembly syntax?
rbp is an absolute addressing mode; normally you'd use pushq rbp(%rip) if you actually wanted to push the contents of a global. Push-memory with any other addressing mode looks like pushq (%rdi, %rsi, 8). In 32-bit code it is normal to access global variables with their bare symbol name, like mov foo, %eax to load from one.
But more likely you meant push rbp as the Intel-syntax version of push %rbp, pushing the register like a normal person.
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?
For more details on syntax differences, see @hidefromkgb's answer, and:
- https://stackoverflow.com/tags/intel-syntax/info
- https://stackoverflow.com/tags/att/info
- Both are linked from https://stackoverflow.com/tags/x86/info which has lots of useful links to manuals and guides.
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:
movl $5, %eaxmov eax, 5addl $4, %espadd esp, 4movl mem_addr(%ebx,%ecx,4), %eaxmov eax, [ebx + ecx*4 + mem_addr]