Machine Problem 4

22C:18, Summer 1996

Due Thursday July 17, 1997, in class

Douglas W. Jones

Add the following new instructions to your RPN calculator:

( - begin loop
) - end loop
The parentheses cause no change in the contents of the stack, but they add a control structure, the infinite loop. Whenever an end parenthesis is encountered, the calculator should jump back to the matching begin parenthesis. The begin and end parentheses must be on the same line of calculator input!

> - if (pop() > 0) exit loop
< - if (pop() < 0) exit loop
= - if (pop() = 0) exit loop
! - exit loop unconditionally
The loop exit commands cause the calculator to jump to the end of the current loop. This is not the nearest end-paren because of the possibility that loops are nested!

P - print( pop() )
Print and pop one item from the stack.

D - t = pop(); push(t); push(t)
Duplicate the top item on the stack.

X - x = pop(); y = pop(); push(x); push(y)
Exchange the top items on the stack.
Other than the addition of these commands, the calculator should operate as it did in MP3! A very serious debugging suggestion: Add the P, D and X commands first! Only then should you worry about loops!

Here is an example illustrating the new features:

input: E6 (D < DP E1-)
output: 6 5 4 3 2 1 0
stack: -1
Turn in:
  1. An assembly listings of your main program and any subprograms.
  2. The linker's map of the combined results.