Exercise 3.1 from Patterson and Hennessey book.
2. [30 points]
int fib(int n)
{
if(n == 1)
return 1;
else if(n == 2)
return 1;
else
return fib(n-1) + fib(n-2);
}
Convert the following piece of C code into symbolic LC-2200 instructions:
int fact (int n)
{
int answer;
answer = 1;
while (n != 0) {
answer = answer * n;
n--;
}
return answer;
}
3. [20 Points]
Convert the following LC-2200 symbolic instructions into
hexadecimal.
Here are some examples
to help you.
(address 0) lw 0 1 seven (address 1) lw 1 2 5 (address 2) lw 1 5 6 (address 3) jalr 5 3 (address 4) nand 1 0 7 (address 5) start add 1 2 1 (address 6) beq 0 1 1 (address 7) beq 0 0 start (address 8) sw 0 2 14 (address 9) noop (address 10) halt (address 11) seven .fill 7 (address 12) neg13 .fill -1 (address 13) pos4 .fill 4 (address 14) store .fill 0