I have just converted this piece of code in assembly:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
return (1);
}
Here are my questions:
- Once you push the base-pointer value on to the stack, RSP will decrement automatically (to a lower address). This will also happen when memory was allocated for argc and argv ("mov dword" and "mov qword"). Is this correct? I don't see any instruction to move the stack-pointer up the stack, so I am assuming this is done implicitly.
- The instruction "mov dword [rbp-4H], edi" is 4 bytes less than the address in RBP, this is as expected since DWORD is 4 bytes in length. What I am confused about is why "mov qword [rbp-10H], rsi" is 10H (16 bytes)? Isn't QWORD 8 bytes in length? I was expecting the instruction to be "mov qword [rbp-CH], rsi", since 4+8=12 bytes.
- Can you explain to me what the comments on the right-side are?
Below is the assembly code generated from my c program:
SECTION .text align=1 execute ; section number 1, code
main: ; Function begin
push rbp ; 0000 _ 55
mov rbp, rsp ; 0001 _ 48: 89. E5
mov dword [rbp-4H], edi ; 0004 _ 89. 7D, FC
mov qword [rbp-10H], rsi ; 0007 _ 48: 89. 75, F0
mov eax, 1 ; 000B _ B8, 00000001
pop rbp ; 0010 _ 5D
ret ; 0011 _ C3
; main End of function
SECTION .data align=1 noexecute ; section number 2, data
SECTION .bss align=1 noexecute ; section number 3, bss