-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFibonacci_instruction.txt
More file actions
37 lines (32 loc) · 1.9 KB
/
Fibonacci_instruction.txt
File metadata and controls
37 lines (32 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//Initialization
001000_00000_00100_0000000000000000 // PC = 0 addi $a0, $r0, 0 $a0 = 0
001000_00000_01000_0000000000000000 // PC = 4 addi $t0, $r0, 0 $t0 = 0
001000_00000_01001_0000000000000001 // PC = 8 addi $t1, $r0, 1 $t1 = 1
001000_00000_10001_0000000000000000 // PC = 12 addi $s1, $r0, 0 $s1 = 0
001000_00000_10010_0000000000000001 // PC = 16 addi $s2, $r0, 1 $s2 = 1
//Load number n from data memory
100011_00100_10000_0000000000000000 // PC = 20 lw $s0, 0($a0)
001000_10000_10100_0000000000000000 // PC = 24 addi $s4, $s0, 0 save input value in $s4
//Calculate the Fibonacci Number
//loop:
000000_10000_01001_10000_00000_100010 // PC = 28 sub $s0, $s0, $t1 subu $s0, 1
000000_10001_10010_10001_00000_100000 // PC = 32 add $s1, $s1, $s2
001000_10010_10011_0000000000000000 // PC = 36 addi $s3, $s2, 0 move $s3, $s2
001000_10001_10010_0000000000000000 // PC = 40 addi $s2, $s1, 0 move $s2, $s1
001000_10011_10001_0000000000000000 // PC = 44 addi $s1, $s3, 0 move $s1, $s3
000100_10000_01000_0000000000000001 // PC = 48 beq $s0, $t0, finish bne $s0, $zero, loop
000010_00000000000000000000000111 // PC = 52 j loop
//Store the result
//finish:
101011_00100_10001_0000000000000100 // PC = 56 sw $s1, 4($a0)
//Calculate the input and output and store
000000_10001_00000_01010_00000_100100 // PC = 60 and $t2, $s1, $r0
000000_10001_00000_01011_00000_100101 // PC = 64 or $t3, $s1, $r0
000000_10001_01100_01100_00000_100000 // PC = 68 add $t4, $s1, $t4
000000_10001_01100_01101_00000_100010 // PC = 72 sub $t5, $s1, $t4
000000_10001_01100_01110_00000_011000 // PC = 76 mul $t6, $s1, $t4
101011_00100_01010_0000000000001000 // PC = 80 sw $t2, 8($a0)
101011_00100_01011_0000000000001100 // PC = 84 sw $t3, 12($a0)
101011_00100_01100_0000000000010000 // PC = 88 sw $t4, 16($a0)
101011_00100_01101_0000000000010100 // PC = 92 sw $t5, 20($a0)
101011_00100_01110_0000000000011000 // PC = 96 sw $t6, 24($a0)