The PUSH and POP instructions
Pushing onto the stack and popping off the stack.
The PUSH instruction format
| Instruction | Description |
|---|---|
| PUSH reg/mem16 | Push reg/mem16 onto the stack. |
| PUSH reg16 | Push reg16 onto the stack. |
| PUSH CS | Push CS onto the stack. |
| PUSH SS | Push SS onto the stack. |
| PUSH DS | Push DS onto the stack. |
| PUSH ES | Push ES onto the stack. |
Decrements the stack pointer (SP) by 2 and places the word from the source at the top of the stack, which SP now points to.
The POP instruction format
| Instruction | Description |
|---|---|
| POP reg/mem16 | Load the value from the top of the stack into mem16; increment SP. |
| POP reg16 | Load the value from the top of the stack into reg16; increment SP. |
| POP DS | Load the value from the top of the stack into DS; increment SP. |
| POP ES | Load the value from the top of the stack into ES; increment SP. |
| POP SS | Load the value from the top of the stack into SS; increment SP. |
Loads the word from the top of the stack, which SP points to, into the destination, and then increments SP by 2.
Example 1: PUSH and POP of a register
title .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov ax, 1234h ; Copy the value 1234h into the ax register push ax ; Push the value of the ax register onto the top of the stack pop bx ; Pop the value from the top of the stack into the bx register mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Example 2: PUSH of a value from memory
title .model small .stack 100h data segment public value dw 1234h data ends code segment public ; Start of the code segment assume ds:data, cs:code main proc ; Start of the main procedure mov ax, seg data ; Get the data segment address and store it in the ax register mov ds, ax ; Pass the data segment address from ax to ds push ds:[value] ; Push the value of the variable value onto the top of the stack mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".
Processor status flags
CF
NoPF
NoAF
NoZF
NoSF
NoTF
NoIF
NoDF
NoOF
No