NASM Assembly, Ubuntu, 32-bit program.
Normally, when popping a value from the stack, I'll do
POP somewhere
Into a register or a variable. But sometimes, I simply don't want to put it anywhere - I just want to get rid of the next element in the stack. Doing
POP
Just like that won't work.
A workaround I had was to make a 4-byte variable I don't use at all and dump the POP
into it. Is there a better way to achieve this?
The PUSH means pushing or inserting an element into the stack. The PUSH operation always increments the stack pointer and the POP operation always decrements the stack pointer.
The pop instruction removes the 4-byte data element from the top of the hardware-supported stack into the specified operand (i.e. register or memory location). It first moves the 4 bytes located at memory location [SP] into the specified register or memory location, and then increments SP by 4.
A stack is an array-like data structure in the memory in which data can be stored and removed from a location called the 'top' of the stack. The data that needs to be stored is 'pushed' into the stack and data to be retrieved is 'popped' out from the stack.
Adjust the stack pointer by four bytes (or some other amount), ignoring whatever value was on top:
add esp, 4
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