0000000000400546 <main>: 400546: push rbp 400547: mov rbp,rsp 40054a: sub rsp,0x10 40054e: mov rax,QWORD PTR fs:0x28 400555: 00 00 400557: mov QWORD PTR [rbp-0x8],rax 40055b: xor eax,eax 40055d: mov DWORD PTR [rbp-0x10],0x1 400564: mov DWORD PTR [rbp-0xc],0x2 40056b: mov eax,0x0 400570: mov rdx,QWORD PTR [rbp-0x8] 400574: xor rdx,QWORD PTR fs:0x28 40057b: 00 00 40057d: je 400584 <main+0x3e> 40057f: call 400420 <__stack_chk_fail@plt> 400584: leave 400585: ret 400586: nop WORD PTR cs:[rax+rax*1+0x0] 40058d: 00 00 00
The first three instructions are part of the function prologue and these instructions are executed every time a function is called. Please note that the RBP register points to the base of the stack frame and all the function parameters and the local variables are accessed with the help of this RBP register. The RSP register points to the top of the stack.
After that, we are moving the stack guard value fs:0x28 to RAX and the value of the RAX register is stored in the stack frame at [RBP – 0x8].
If we look at the stack frame of the function, the stack frame will look like the following:
The complete explanation of the above assembly code is given here: How to construct C code from x86 assembly for arrays? I would request interested readers to go through the article for the explanation.
Please note the following instructions that are executed when the function returns:






0 Comments