Presentation Topic :
PUSH, PUSHF, POP, POPF
Presented By :
Contents :
 The Stack
 Push
 Pop
 PushF
 PopF
A stack in one-dimensional data structure. Items are added and
removed from one end of the structure; that is, it is processed
in a “Last-in, first out” manner. The most recent addition to the
stack is called the top of the stack.
A program must set aside a block of memory to hold the stack.
We have been dong this by declaring a stack segment ;
For example :
.STACK 100H
THE STACK
To add a new word to the stack we PUSH it on. The syntax is
PUSH source
Where source is a 16-bit register or memory word.
For example,
PUSH AX
Execution of PUSH causes the following to happen :
1. SP is decreased by 2.
2. A copy of the source content is moved to the address specified
by SS:SP. The source is unchanged.
PUSH AND PUSHF
The instruction PUSHF, which has no operands, pushes
the contents of the FLAGS register onto the stack.
Initially SP contains the offset address of the memory
location immediately following the stack segment; the
first PUSH decreases SP by 2, making it point to the last
word in the stack segment. Because each PUSH
decreases SP, the stack grows toward the beginning of
memory
PUSH AND PUSHF
FIGURE : EMPTY STACK
offset
00F0
00F2
00FA
00F4
00F6
00F8
00FC
00FE
0100
1234
SP
5678
0100
AX
BX
STACK(empty)
SP
FIGURE : AFTER PUSH AX
offset
00F0
00F2
00FA
00F4
00F6
00F8
00FC
00FE
0100
1234
1234
SP
5678
00FE
AX
BX
STACK
SP
FIGURE : AFTER PUSH BX
offset
00F0
00F2
00FA
00F4
00F6
00F8
00FC
00FE
0100
5678
1234
1234
SP
5678
00FC
AX
BX
STACK
SP
To remove the top item from the stack we POP it. The Syntax is
POP destination
Where destination is a 16-bit register (except IP) or memory word. For example,
POP BX
Executing POP causes this to happen:
1. The content of SS:SP (the top the stack) is moved to the destination
2. SP is increased by 2.
POP AND POPF
The instruction POPF pops the top of the stack into the FLAGS
Register. There is no effect of PUSH, PUSHF, POP, POPF on the flags.
Such as
Illegal : PUSH DL
Is illegal. So is a push of immediate data, such as
Illegal : PUSH 2
FIGURE : BEFORE POP
offset
00F0
00F2
00FA
00F4
00F6
00F8
00FC
00FE
0100
5678
1234
FFFF
SP
0001
00FC
CX
DX
STACk
SP
FIGURE : AFTER POP CX
offset
00F0
00F2
00FA
00F4
00F6
00F8
00FC
00FE
0100
5678
1234
5678
SP
0001
00FE
CX
BX
STACK
SP
FIGURE : AFTER POP DX
offset
00F0
00F2
00FA
00F4
00F6
00F8
00FC
00FE
0100
5678
1234
5678
SP
1234
0100
CX
DX
STACK(empty)
SP
THANK YOU
END

Microprocessor & assembly language

  • 2.
    Presentation Topic : PUSH,PUSHF, POP, POPF Presented By :
  • 3.
    Contents :  TheStack  Push  Pop  PushF  PopF
  • 4.
    A stack inone-dimensional data structure. Items are added and removed from one end of the structure; that is, it is processed in a “Last-in, first out” manner. The most recent addition to the stack is called the top of the stack. A program must set aside a block of memory to hold the stack. We have been dong this by declaring a stack segment ; For example : .STACK 100H THE STACK
  • 5.
    To add anew word to the stack we PUSH it on. The syntax is PUSH source Where source is a 16-bit register or memory word. For example, PUSH AX Execution of PUSH causes the following to happen : 1. SP is decreased by 2. 2. A copy of the source content is moved to the address specified by SS:SP. The source is unchanged. PUSH AND PUSHF
  • 6.
    The instruction PUSHF,which has no operands, pushes the contents of the FLAGS register onto the stack. Initially SP contains the offset address of the memory location immediately following the stack segment; the first PUSH decreases SP by 2, making it point to the last word in the stack segment. Because each PUSH decreases SP, the stack grows toward the beginning of memory PUSH AND PUSHF
  • 7.
    FIGURE : EMPTYSTACK offset 00F0 00F2 00FA 00F4 00F6 00F8 00FC 00FE 0100 1234 SP 5678 0100 AX BX STACK(empty) SP
  • 8.
    FIGURE : AFTERPUSH AX offset 00F0 00F2 00FA 00F4 00F6 00F8 00FC 00FE 0100 1234 1234 SP 5678 00FE AX BX STACK SP
  • 9.
    FIGURE : AFTERPUSH BX offset 00F0 00F2 00FA 00F4 00F6 00F8 00FC 00FE 0100 5678 1234 1234 SP 5678 00FC AX BX STACK SP
  • 10.
    To remove thetop item from the stack we POP it. The Syntax is POP destination Where destination is a 16-bit register (except IP) or memory word. For example, POP BX Executing POP causes this to happen: 1. The content of SS:SP (the top the stack) is moved to the destination 2. SP is increased by 2. POP AND POPF
  • 11.
    The instruction POPFpops the top of the stack into the FLAGS Register. There is no effect of PUSH, PUSHF, POP, POPF on the flags. Such as Illegal : PUSH DL Is illegal. So is a push of immediate data, such as Illegal : PUSH 2
  • 12.
    FIGURE : BEFOREPOP offset 00F0 00F2 00FA 00F4 00F6 00F8 00FC 00FE 0100 5678 1234 FFFF SP 0001 00FC CX DX STACk SP
  • 13.
    FIGURE : AFTERPOP CX offset 00F0 00F2 00FA 00F4 00F6 00F8 00FC 00FE 0100 5678 1234 5678 SP 0001 00FE CX BX STACK SP
  • 14.
    FIGURE : AFTERPOP DX offset 00F0 00F2 00FA 00F4 00F6 00F8 00FC 00FE 0100 5678 1234 5678 SP 1234 0100 CX DX STACK(empty) SP
  • 15.