Section B
• (10 Points) Complete the method below to join the Computer class code from the homework. You must use Eclipse IDE and write code that is logically and syntactically correct. You cannot change the method signature. Copy and paste the code here once you are done (only this method).
public void executeJSRR()
• (15 Points) Write the JUnit test methods to test the code above in Problem 2. You must use JUnit 4 framework and test methods must be logically and syntactically correct. Copy and paste the tests here once you are done. Only the test methods.
• (10 Points) Write a routine to ShiftLeft the contents of register R0. In other words, if R0 contains #8, it should become #16. Assume that R0 is already loaded with data, do not write code for loading data. Comment your routine for full credit. You may use LC3 to write this code. It must be logically and syntactically correct for credit. Copy and paste the code here once you are done. You must save and restore any registers that shouldn’t be modified. The only register that should be modified is R2 by the routine. Main is provided below.
.ORIG x3000
AND R0, R0, #0
ADD R0, R0, #8
JSR ShiftLeft
HALT
• (Extra Credit: Java to LC3 Assembly – 5 Points)
Assume that the program is syntactically correct. Use the following program to answer the questions i,ii below:
public static void main(String[] args)
{
int number;
int answer;
number = 10;
answer = factorial(number);
System.out.printf(“The factorial of %d is %d\n”, number, answer);
}
public static int factorial(int n)
{
int i;
int result = 1;
for (i = 1; i <= n; i++) result = result * i; return result; } i) Draw the activation record for factorial. ii) Write the LC3 assembly code for the following loop in the factorial method above. You must use appropriate registers and offsets based on the activation record from i). for (i = 1; i <= n; i++) result = result * i;