The PUSH and POP instructions

Pushing onto the stack and popping off the stack.

The PUSH instruction format

InstructionDescription
PUSH reg/mem16Push reg/mem16 onto the stack.
PUSH reg16Push reg16 onto the stack.
PUSH CSPush CS onto the stack.
PUSH SSPush SS onto the stack.
PUSH DSPush DS onto the stack.
PUSH ESPush 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

InstructionDescription
POP reg/mem16Load the value from the top of the stack into mem16; increment SP.
POP reg16Load the value from the top of the stack into reg16; increment SP.
POP DSLoad the value from the top of the stack into DS; increment SP.
POP ESLoad the value from the top of the stack into ES; increment SP.
POP SSLoad 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 Author: Evgeny Sergeevich Dovgopolov

.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 Author: Evgeny Sergeevich Dovgopolov

.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
No
PF
No
AF
No
ZF
No
SF
No
TF
No
IF
No
DF
No
OF
No