-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFibonacci.txt
111 lines (92 loc) · 1.92 KB
/
Fibonacci.txt
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
Fibonacci - C
int fibonacci(int n) {
if(n == 0 && n == 1) return n;
else return (fibonacci(n-1) + fibonacci(n-2));
}
int main() {
int n = 3;
fibonacci(3);
return 0;
}
----------------------------------
int fibo_it(int n) {
int a = 0;
int b = 1;
int temp;
while(b < n)
temp = b + a;
a = b
b = temp;
print("%d", temp);
}
}
--------------------------------
int fibo_it_unrolled(3) {
int a = 0;
int b = 1;
int temp;
temp = b + a; //temp = 1 | i = 0
a = b; //1
b = temp; //1
temp = b + a; //temp = 2 | i = 1
a = b; //1
b = temp; //2
temp = b + a //temp = 3 | i = 2
a = b //2
b = temp //3
mem[] = b;
}
ASSEMBLY - unrolled
0000 movi R0, 0
0001 movi R1, 1
0002 add R0, R1
0003 movrr R2, R0
0004 movrr R0, R1
0005 movrr R1, R2
0006 add R0, R1
0007 movrr R2, R0
0008 movrr R0, R1
0009 movrr R1, R2
000A add R0, R1
000B movrr R2, R0
000C movrr R0, R1
000D movrr R1, R2
0010000000000000
0010000100000001
0000000000000001
0001000000100000
0001000000000001
0001000000010010
0000000000000001
0001000000100000
0001000000000001
0001000000010010
0000000000000001
0001000000100000
0001000000000001
0001000000010010
ASSEMBLY - iteration rolled
0000 movi R0, 0 0010000000000000 2000
0002 movi R1, 1 0010000100000001 2101
0004 movi R3, 3 0010001100000011 2303
0006 add R0, R1 0000000000000001 0001
0008 movrr R2, R0 0001000000100000 1020
000a movrr R0, R1 0001000000000001 1001
000c movrr R1, R2 0001000000010010 1012
000e cmp R3, R1 0000011000110001 0631
0010 jg -5 0100001111111011 43fb
0012 movi R14, 0 0010111000000000 2e00
0014 movi R15, 50 0010111100110010 2f32
0016 movrm R1, MEM 0001001000010000 1210
0010000000000000 2000
0010000100000001 2101
0010001100000011 2303
0000000000000001 0001
0001000000100000 1020
0001000000000001 1001
0001000000010010 1012
0000011000110001 0631
0100001111111011 43fb
0010111000000000 2e00
0010111100110010 2f32
0001001000010000 1210