When I first sent Marius Milner some e-mail about taking over the VIOTW web page I told him I would give in depth discourses on insructions like POP; here it is. PUSH and POP are common to all assembly languages as they are the commands used to utilize a stack. What's a stack?

Definition: Stack. A stack is a data strucure used for storing and retrieving data. A stack is called a stack because the data is stored stacked on top of the data already in the stack; i.e., you PUSH it on the stack. Furthermore the data can only be accessed sequentially. I.e., you can only access the last data put on the stack; you POP it off. This last in first out nature of stacks inspired the name LIFO stack.

Empty Slot
Empty Slot
Entry n
Entry n - 1>
. . .
Entry 1
Entry 0

How does the computer know where element n is? When you create a stack the computer points to the top of it with the stack pointer SP; register 14 (R14). Say you PUSH a longword (32 bits) on the stack (PUSHL) then the computer subtracts 4 (4 bytes = 32 bits) from the value contained in SP (R14). Why subtract? Stacks sit upside down in memory; i.e., they grow towards memory location 0. Now we can see how PUSH and POP work:

PUSHL R6      ; save the contents of register 6 on the stack

MOVL R6,-(SP) ; this is equivalent to PUSHL R6

I need to explain the last statement; it's called autodecrement mode. The value contained in SP is decremented by the size of the first operand, R6; 4 bytes in this case. Next the value contained in R6 is moved into the memory location that is now stored in SP. Obviously we can't PUSHL anymore when the value in SP gets to 0 (or less then 4).

POPL R6  ;retrieve the value at the top of the stack into R6
      	 ;remember that the top of the stack is it's lowest point
         ;in memory.

MOVL (SP)+, R6 ;this is equivalent to POPL R6

When we POP we are using autoincrement mode. Here we move the value in the memory location pointed to by the value in SP to R6. Next we increment the value in SP by 4.

So there is no PUSH instruction!!!!!!!!!!!!!!!!!!!!!!!

There is no POP instuction!!!!!!!!!!!!!!!!!!!!!!!!!!

MACRO-32 has a POP and PUSH command (POPL for longwords (4 bytes), POPW for words (2 bytes)) but the VAX processor doesn't have a PUSH or POP instruction. The VAX processor makes use of autoincrementing and autodecementing so the single POP (or PUSH) command corresponds to a single instruction (we still have a 1:1 correspondence between the instruction set and assembly language commands); assembly commands are supposed to be mnemonics for machine instructions. But the PUSH and POP mnemonics are only there to make stack handling seem natural to programmers already familiar with other assemblers.

Return to VAX Instruction of the Week