Managing the stack

The following set of instructions make it possible to manage elements on the stack. They make it possible to duplicate the element at the top of the stack, remove the top element from the stack, clear the stack, swap the top two stack elements, determine the number of elements currently on the stack, copy a specified element to the top of the stack, move a specified element to the top of the stack, and rearrange the order of the top three elements on the stack.

Duplicate top stack element

DUP[ ]

Code Range

0x20

Pops

e: stack element (ULONG)

Pushes

e, e (two ULONGs)


Duplicates the element at the top of the stack.

POP top stack element

POP[ ]

Code Range

0x21

Pops

e: stack element (ULONG)

Pushes


Pops the top element of the stack.

Clear the entire stack

CLEAR[ ]

Code Range

0x22

Pops

all the items on the stack (ULONGs)

Pushes


Clears all elements from the stack.

SWAP the top two elements on the stack

SWAP[ ]

Code Range

0x23

Pops

e2: stack element (ULONG)

e1: stack element (ULONG)

Pushes

e1, e2 (pair of ULONGs)


Swaps the top two elements of the stack making the old top element the second from the top and the old second element the top element.

Returns the DEPTH of the stack

DEPTH[ ]

Code Range

0x24

Pops

Pushes

n: number of elements (ULONG)


Pushes n, the number of elements currently in the stack onto the stack.

Example:

Copy the INDEXed element to the top of the stack

CINDEX[ ]

Code Range

0x25

Pops

k : stack element number

Pushes

ek: indexed element (ULONG)


Puts a copy of the kth stack element on the top of the stack.

Example:

CINDEX[ ]

Move the INDEXed element to the top of the stack

MINDEX[ ]

Code Range

0x26

Pops

k: stack element number

Pushes

ek: indexed element


Moves the indexed element to the top of the stack.

MINDEX[ ]

ROLL the top three stack elements

ROLL[ ]

Code Range

0x8a

Pops

a, b, c (top three stack elements)

Pushes

b, a, c (elements reordered)


Performs a circular shift of the top three objects on the stack with the effect being to move the third element to the top of the stack and to move the first two elements down one position. ROLL is equivalent to MINDEX[ ] 3.