Why is it that when you push a value onto the stack, the ESP register is decreased (as opposed to increased) and when you pop a value, the ESP register is increased (as opposed to decreased)? This is counter intuitive to me at this point.
Thats because that way the stack "grows" from top to bottom, opposed to the heap, which is allocated bottom up.
On architectures with a limited address space this was a design decision, you can use them both more flexible - only the sum of both allocated memory regions must not exceed a certain limit.
Nowadays the stack and heap address space is kept in separate memory regions anyway, but they decided to keep the backwards growing stack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With