I am currently learning assembly for Intel processors. Since the stack 'grows down', why do we have to add in order to access a specific element
[ebp + 8] ;; This will access the first param
I konw we have to skip the old ebp value and the return address and that's why we use 8 ( because each are 4 bytes long ). This is kinda strange.
Also, if ebp is a backup copy for esp, what is ebp's value in the main function Ex:
_start:
;; what's ebp value here ?
push eax
push ebx
call someFunction ;; this will create a stack frame
+-----------+
| param1 |
+-----------+
| param0 | <--- this is [ebp + 8] ( assuming mov ebp, esp )
+-----------+
|ret_address|
+-----------+
| ebp |
+-----------+ <--- esp
And also when we allocate memory for locals, we have to substract from ebp ... Please give a non-ambiguous answer. Thank you!