Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASM - Pushing/Popping

Tags:

x86

assembly

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.

like image 354
user1203441 Avatar asked Dec 29 '25 20:12

user1203441


1 Answers

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.

like image 169
Gunther Piez Avatar answered Jan 01 '26 10:01

Gunther Piez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!