-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfib.cc
More file actions
39 lines (28 loc) · 810 Bytes
/
fib.cc
File metadata and controls
39 lines (28 loc) · 810 Bytes
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
# include <HERA.h>
void HERA_main()
{
// VARIABLES
CBON()
SET(R2, 3) // n - Where "n" is the nth number in the Fibonacci sequence to be calculated
SET(R3, 2) // i
SET(R4, 0) // a
SET(R5, 1) // b
SET(R6, 0) // f - Where f is the desired nth number in the Fibonacci sequence
SET(R7, 1) // Used to check if "n" is 0
// FUNCTION DEFINITION
DLABEL(fib_begin)
SUB(R8, R2, R7) // If R8 == 0, then n <= 1
BZ(fib_end)
DLABEL(loop_begin) // for(i=2; i<=n: i++)
SUB(R9, R2, R3) // If R9 <= 0, then i<=n
BZ(loop_end)
ADD(R6, R4, R5)// f = a + b
LOAD(R4, 0, R5)// a = b
LOAD(R5, 0, R6)// b = f
INC(R3, 1) // Increment loop by 1
DEC(R2, 1) // Decrement n
BR(loop_begin)
DLABEL(loop_end)
DLABEL(fib_end)
HALT()
}