Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 371
Voldemort Avatar asked Oct 17 '13 05:10

Voldemort


People also ask

What happens to stack pointer when you pop an element from bottom of stack?

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.

What does Pop mean in assembly?

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.

How does the stack work in assembly?

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.


1 Answers

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

add esp, 4
like image 183
John Zwinck Avatar answered Nov 15 '22 09:11

John Zwinck