CSc 109 Final Examination
18 May 2001
Suppose we added the symbol ">>" to the syntax of bool expression in
the Simple Language.
In particular, <exp1> >> <exp2> would be true if the
absolute value of <exp1> is >= the absolute value of <exp2).
that the virtual stack starts at FF and "goes down" in memory. Finally,
suppose that the values of <exp1> and <exp2> are stored on the virtual
stack, <exp1> at StkPtr+2 and <exp2> at StkPtr+1. Write the function
GREATABS() which stores in a file the Simple Machine code which
should be generated for the expression
IF <exp1> >> <exp2> GOTO ONE
where the code for evaluating and storing <exp1> and <exp2>) on the virtual
stack has already been generated.
The call to GREATABS() would take the
where "out" is of type ostream, StkPtr, PC, and ONE_ADD are integers.
gives the current value of the program counter (the number of words of
Simple Machine code generated so far), and ONE_ADD is the address
corresponding to the Simple Language variable "ONE".
This question is
similar to question 4 on test 2.
There you were asked to write the
sasm code; here you are asked to write the C++ code which generates the
simple machine code.
You would be wise to write some functions to call.
const int LOAD=3,MULT=7, SUB=6, BRANCHGE=10;
//pop values of <exp1> and <exp2> off the virtual stack
(This question and question 3 are related. Design your answer to this
question so that it can be used in question 3.) Write a template class
PRay for "protected arrays."
A protected array does not let you access