Search code examples
x86stacknasmstack-memorystack-pointer

Can I POP a value from the stack, but put it nowhere in NASM Assembly?


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?


Solution

  • Adjust the stack pointer by four bytes (or some other amount), ignoring whatever value was on top:

    add esp, 4