0

c code: return a + b + BASE;

000012a0 <add>:
    12a0:       f3 0f 1e fb             endbr32 
    12a4:       8b 44 24 08             mov    0x8(%esp),%eax
    12a8:       03 44 24 04             add    0x4(%esp),%eax
    12ac:       83 c0 32                add    $0x32,%eax
    12af:       c3                      ret   
0000000000001210 <add>:
    1210:       f3 0f 1e fa             endbr64 
    1214:       8d 44 37 32             lea    0x32(%rdi,%rsi,1),%eax
    1218:       c3                      retq   
    1219:       0f 1f 80 00 00 00 00    nopl   0x0(%rax)

In the 32 bit compilation,

  1. we move the 1st operand from stack to eax
  2. add 2nd operand from stack to the eax
  3. add the BASE value to it

In the 64 bit compilation in a single instruction we are able to do 0x32+rdi+rsi*1 and save in eax

question is whether this single instruction execution is achieved because we use lea or whats the significance of 64bit compilation here.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 32-bit could do the same thing if args were passed in registers like x86-64 does, like with fastcall or `gcc -O3 -m32 -mregparm=3` – Peter Cordes Feb 09 '22 at 04:06
  • so the instruction size doesnt depend on the 32bit vs 64bit compilation? – Krishnakumar Muthukrishnan Feb 09 '22 at 04:17
  • Not sure what you're asking. `8d 44 37 32` would decode as `lea 0x32(%edi,%esi,1),%eax` in 32-bit mode, so the same LEA is still a 4-byte instruction. All the differences stem from the inefficient 32-bit calling convention that means the args start in memory instead of already in registers. – Peter Cordes Feb 09 '22 at 04:27

0 Answers0