<<< Saving Operands on the Stack | Index | Popping Values from Stack >>> |
The ESP register serves as an indirect memory operand pointing to the top of the stack at any time.
As program adds data to the stack, the stack grows downward from high memory to low memory.
When items removed from the stack, stack shrinks upward from low to high memory.
When a word value is pushed onto the stack, the assembler decreases the ESP (Stack Pointer) register by 2.
When a word value is popped off the stack, the assembler increases the ESP register by 2.
When a double word value is pushed/popped off the stack, the assembler decreases/increases the ESP register by 4.
Thus, ESP register changes in multiples of two or four.
If there is ambiguity about the size of the operand (as would be with a small immediate value), then you can use PUSHW or PUSHD mnemonics to specify a word or doubleword size operands, respectively.
For example the following two instructions are the same:
push dword -240 pushd -240
If operand is immediate value, such as single byte -240, is stored in the instruction, it is sign-extended to a doubleword that is actually stored on the stack.
The byte-size operand results in a smaller instruction, but does not reduce stack space consumption at execution time.
No PUSH or POP instruction affects any flag bits.
There is a separate pair of instructions, PUSHF and POPF, for pushing and popping the EFLAGS register.
Execution of PUSHD and PUSHW instructions:
pushw 1000h pushd eax
<<< Saving Operands on the Stack | Index | Popping Values from Stack >>> |