-
Notifications
You must be signed in to change notification settings - Fork 1
/
fib.mem
20 lines (19 loc) · 1.02 KB
/
fib.mem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
00100000000001010000000000000101 // initialize $t5 to be 5 (the argument is currently hardcoded)
00010000101000000000000000001010 // if $t5 == $zero, branch to 10 (11) lines down
00100000000000010000000000000000 // initialize $t1 to be 0
00100000000000100000000000000001 // initialize $t2 to be 1
00100000000001000000000000000001 // initialize $t4 to be 1
00000000000000100001100000100000 // $t3 = $t2
00000000001000100001000000100000 // $t2 = $t1 + $t2
00000000000000110000100000100000 // $t1 = $t3
00100000100001000000000000000001 // $t4 = $t4 + 1 increment the counter
00010000100001010000000000000001 // if $t4 == $t5, branch to 1 (2) lines down
00001000000000000000000000000101 // jump to line 5 (this is only satisfied when when counter is not at the desired number yet)
11111100010111111111111111111111 // print $t2
11111100000111111111111111111111 // print $zero
// This is a fibonacci sequence calculator that "prints" the 5th fibonacci number.
// $t1: n-2
// $t2: n-1
// $t3: temp
// $t4: counter
// $t5: which fibonacci number?