S
S
sddvxd2019-04-09 13:52:46
assembler
sddvxd, 2019-04-09 13:52:46

Why does it make sense to subtract from ESP?

Good afternoon
ESP is known to point to the top of the stack, I'm reading a book:

The contents of the stack frame can be accessed
using addresses "attached" to the address at which
the return address is contained, that is, in other words, the memory cell from which
the return address was pushed onto the stack is used as its
kind of reference point. So, if three four-byte parameters are put on the stack
, and then the procedure is called, then the return address will be in
memory at the address [esp] , but the parameters, obviously, will be available
at the addresses [esp+4] , [esp+8 ] and [esp+12] . If you place local four-byte variables on the stack
, they will be available at
addresses [esp-4] , [esp-8], etc.

I was confused by the last sentence: why did the author indicate that it is possible to address above the stack? Is there nothing there?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2019-04-09
@sddvxd

It is enough to debug some HelloWorld and it immediately becomes clear where the arguments are on the stack, and where are the local variables.
This is the calculation, there is nothing to spoil, so you can put your time.

J
jcmvbkbc, 2019-04-22
@jcmvbkbc

Если же разместить в стеке
    локальные четырёхбайтные переменные, то они окажутся доступны по
    адресам [esp-4] , [esp-8] и т. д.

I was confused by the last sentence: why did the author indicate that it is possible to address above the stack?

Correctly confused, the author wrote garbage. It is enough to look into any ABI to make sure that the stack area below (at addresses less than) the stack pointer is reserved and should not be changed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question