Professional Documents
Culture Documents
chap9-StacksAndProcedures (Compatibility Mode)
chap9-StacksAndProcedures (Compatibility Mode)
• The .stack directive hides an array allocation statement that looks like
this
• The_Stack DB Stack_Size dup (?)
• On program load…
• SS is set to a segment address containing this array (usually The_Stack
starts at offset 0)
• SP is set to the offset of The_Stack+Stack_Size which is one byte
past the end of the stack array
• This is the condition for an empty stack
SS:0340 SP:000C
• The stack grows backwards through memory towards the start of the
stack segment
SS:0340 SP:0008
• PUSH source
• source is (almost) any 16/32-bit general or segment register or the address of
a word or doubleword
• PUSHF or PUSHFD
• Pushes the FLAGS register onto the stack
• A PUSH instruction subtracts 2/4 from SP and then stores the source
data at SS:SP
SS:0340 SP:0008
PUSH AX
AX: 0123
3C 09 A4 40 2C FF A2 23 01 06 4C 2A 09 46
SS:0340 SP:0006
• POP destination
• destination is (almost) any 16/32-bit general or segment register or the
address of a word or doubleword
• POPF or POPFD
• Pops the top of stack to the FLAGS register
• A POP instruction copies the data at SS:SP to destination, then adds
2/4 to SP
3C 09 A4 40 2C FF A2 23 01 06 4C 2A 09 46
SS:0340 SP:0006
POP ES
3C 09 A4 40 2C FF A2 23 01 06 4C 2A 09 46
SS:0340 SP:0008
ES: 0123
SP:0336 SS:0340
• Stack Overflow
• Stack Underflow
SS:0340 SP:000D
Pushpar A
Pushpar B
Pushpar C