Hello,
I am beginning learning intel assembly. I am taking simple gcc programs and looking at the assembly. All gcc outputs have a line similar to:
mov DWORD PTR [ebp-4] that I can't figure out.
For example
int main(void)
{
int x = 5;
return 0;
}
gives me
.file "test.c"
.intel_syntax noprefix
.text
.globl main
.type main, @function
main:
push ebp
mov ebp, esp ; memory address of start of stack
sub esp, 16 ; push for room for a word
mov DWORD PTR [ebp-4], 5 ; I'm confused here
mov eax, 0 ; retval of function
leave
ret
.size main, .-main
.ident "GCC: (Ubuntu 4.4.1-4ubuntu9) 4.4.1"
.section .note.GNU-stack,"",@progbits
I know it is putting the value of 5 on the stack, but why at ebp-4? A word is 2 bytes or 16 bits. Is the 4 in bits or bytes? Since, gcc has subtracted 16 from the esp, why not put it at ebp?
Thanks