Tuesday, March 9, 2010

Sample final exam questions - part 2

These aren't from old final exams, but are sorts of things I could ask in the midterm Friday.

For these, assume a computer with a load/store architecture (that is, operands of any instruction other than load or store must be a register), and the following instructions  (rX are registers, mem are memory addresses, ";" introduces a comment till the end of the line
ADD  r0, r1, r2   ;; r0 := r1 + r2
SUB  r0, r1, r2   ;; r0 := r1 - r2
BZ   label    ;;  Branch if result of last operation was zero
BN  label     ;; Branch if result of last operation was negative
BNZ label   ;; Branch if result of last operation was not negative
LD  r0,mem  ;; r0 := Memory[mem]
ST  r0,mem  :: Memory[mem] := r

Assume an unlimited set of registers (i.e., assume that register allocation will be a separate step after generating code).

1a. Show an AST and then assembly code for  the following   (which might be Java or C or some similar language).

x = x + y;
y = y - x;

1b.  If your answer is not already in register SSA form (SSA except for memory references), show the assembly code in register SSA form.

2.  Show an AST and then assembly code for the following.

while (x < 0 || x < y) {
   x = x + y;
}

No comments:

Post a Comment