2
votes

when I disassembled following simple program in C:

int main ()
{
 int a = 'a';
return 0;
}

I got this:

Dump of assembler code for function main:
0x0000000100000f20 <main+0>:    push   rbp
0x0000000100000f21 <main+1>:    mov    rbp,rsp
0x0000000100000f24 <main+4>:    mov    BYTE PTR [rbp-0x9],0x61
0x0000000100000f28 <main+8>:    mov    DWORD PTR [rbp-0x8],0x0
0x0000000100000f2f <main+15>:   mov    eax,DWORD PTR [rbp-0x8]
0x0000000100000f32 <main+18>:   mov    DWORD PTR [rbp-0x4],eax
0x0000000100000f35 <main+21>:   mov    eax,DWORD PTR [rbp-0x4]
0x0000000100000f38 <main+24>:   pop    rbp
0x0000000100000f39 <main+25>:   ret    
End of assembler dump.
  1. why rsp is not setted (sub rep 0xa)
  2. why there is assignment 0 -> [rbp-0x8] -> eax -> [rbp-0x4] -> eax
1

1 Answers

2
votes

why rsp is not setted (sub rep 0xa)

Since there isn't any call from this function (this is a leaf function), there isn't any need to adjust the stack.

why there is assignment 0 -> [rbp-0x8] -> eax -> [rbp-0x4] -> eax

I suspect these come from an intermediate representation in some SSA (Static Single Assignment) form. In SSA form, you can only assign once to each variable, and you use loads of variables. SSA is a nice representation to work with, which is why compilers tend to use it. The temporary assignments will disappear once you raise your optimization level.