List any modifications to the code so that it will execute properly by stating the line number and the change, or you can clearly mark up your edits onto the code directly.

1. (15 points) Write a subroutine that calulates the nth term of a fibonacci sequence (not using recursion). The nth term is the only input received from the calling function. The input is the exact value of the number and not the location.

2. (15 points) Write a subroutine that calulates the factiorial of an input. This input is recieved as a memory location that is stored as an interger. The program should store the answer back into a variable of the same type but not overwrite the original value. ie:
void main(){
int x = 5;
int y = factorial(x);
}
int factorial(int& x){
int answer;
… some code…
return answer;
}

3. (15 points) Suppose we had a routine to determine how many inputs are greater than 0x0ff and that the
input values follow in-line after the call instruction. The first argument provides the number of inputs that follow. The routine should pass back the result to the calling routine. List any modifications to the code so that it will execute properly by stating the line number and the change, or you can clearly mark up your edits onto the code directly. If you have to add a line of code after say line 9, then call it line 9.1, 9.2, . Hint: There are 5 mistakes.
1 call subr1
2 nop
3 0x04
4 0x0c21
5 0x0b3a2
6 0x07c4
7 0x05d
8 mov %o5, %result

9 subr1: save %sp, -61 , %sp
10 mov 12, %i2
11 mov 0, %i5
12 ld [%i7 + %i2], %i3
13 again: cmp %i3, 0
14 ble done
15 nop
16 add %i2, 4, %i2
17 ld [%fp + %i2], %i4
18 cmp %i4, 0x0ff
19 bg skip
20 nop
21 add %i5, 1, %i5
22 skip: ba again
23 nop
24 done: add %i2, 4, %i2
25 jmpl %i7 + %i2, %g0
26 restore

4. (20 points) Encode the following 4 instructions. Show all your work.
0x40004061

0x92102043

0x14800009

0x81c7e008

5. (20 points) Convert the following 4 lines into hexadecimal instructions: 0x10660, 0x00688, 0x10668,
0x10674. Show all your work.

0x10654 <main>: save %sp, -64, %sp
0x10658 : mov %g0, %l0
0x1065c : st %l0, [ %fp + -4 ]
0x10660 : call 0x00680 <subro>
0x10664 : nop
0x10668 : cmp %l0, %g0
0x1066c : bge 0x10674 <loop>
0x10670 : dec %l0
0x10674 :<loop> ld [ %fp + -4 ], %l2
0x10678 : ret
0x1067c : restore

0x00680 :<subro> save %sp, -16, %sp
0x00684 ret
0x00688 : restore

6. (15 points) Write a program to initialize each element of an integer array containing 8 elements to the factorial of the subscript. You can use any subroutine already written on this test, but you cannot call
any other subroutines, ie .mul and .div.

Type of paper Academic level Subject area
Number of pages Paper urgency Cost per page:
 Total: