rubymonk
rubymonk

Reputation: 143

assembly stack pointer

Stack:

0xDDDD
0xCCCC
0xBBBB
0xAAAA

pop ax Means:

Now, I get this.

0xDDDD
0xCCCC
0xBBBB

I want to save ax's value.

push ax.

0xDDDD
0xCCCC
0xBBBB
0xAAAA

Here I go again.

mov ax, [ss:sp+2]

0xBBBB will be loaded in ax.

After my function is done, I will want to remove both 0xAAAA and 0xBBBB from the stack. First, I will restore ax.

pop ax. (Now loaded with 0xAAAA)

How do I get rid of 0xBBBB from my stack? Do I simply "pop" without arguments (Do this exist?) or do I add sp, 2 ?

Thank you.

Upvotes: 1

Views: 2070

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 224511

Simply adjust the stack pointer to point earlier in the stack, as with add sp, $2. Syntax may vary depending on which assembler you use. $2 is intended to mean “the immediate value 2”.

You can download the Intel 64 and IA-32 Architectures Software Developer’s Manuals.

(Note that using 16-bit registers is rather old. Depending on which platform you are writing for, there might be requirements about maintaining stack alignment to be multiples of four bytes or more, particular when calling or returning from routines.)

Upvotes: 1

Related Questions