Exchanging the X– and Y–Registers in the Stack

Another key that manipulates the stack contents is [(x exchange y). This key swaps the contents of the X– and Y–registers without affecting the rest of the stack. Pressing [twice restores the original order of the X– and Y–register contents.

The [function is used primarily to swap the order of numbers in a calculation. For example, one way to calculate 9 (13 8):

Press 13 ‘8 z9 [q.The keystrokes to calculate this expression from left–to–rightare:9 ‘13 ‘8 zq.

Note

Always make sure that there are no more than four numbers in the

 

stack at any given time — the contents of the T–register (the top

 

register) will be lost whenever a fifth number is entered.

 

 

Arithmetic – How the Stack Does It

The contents of the stack move up and down automatically as new numbers enter the X–register (lifting the stack) and as operators combine two numbers in the X– and Y–registers to produce one new number in the X–register (dropping the stack).

Suppose the stack is filled with the numbers 1, 2, 3, and 4. See how the stack drops and lifts its contents while calculating

1.The stack "drops" its contents. The T–(top) register replicates its contents.2.The stack "lifts" its contents. The T–register's contents are lost.
2–4RPN: The Automatic Memory Stack