-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfib_tr.asm
More file actions
executable file
·83 lines (62 loc) · 883 Bytes
/
fib_tr.asm
File metadata and controls
executable file
·83 lines (62 loc) · 883 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
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
// Main
// Push parameters
// n
LDR0 13
PUSH
// b
LDR0 1
PUSH
// a
LDR0 0
PUSH
CALL FIB // R1 := return val
// Release parameters
POP
POP
POP
SWAP
PRINT
HALT
FIB:
// N.B.
// n is (Frame+4)
// b is (Frame+3)
// a is (Frame+2)
// return address is (Frame+1)
// locals
PUSH // result (Frame+0)
// End initialisation
// result := a
LSR0 2
SSR0 0
// IF (n != 0)
// (unless n == 0)
LSR0 4 // R0 := n
JZ FIB_END_IF
// Push parameters
// n - 1
LSR0 4
DEC
PUSH // (+1 from stack frame)
// a + b
LSR0 3 // account for push (2+1)
LSR1 4 // account for push (3+1)
ADD
PUSH // (+2 from stack frame)
// b
LSR0 5 // account for push (3+2)
PUSH
// recurse
CALL FIB
// release parameters
POP
POP
POP
// result := R1
SSR1 0
FIB_END_IF:
// R1 := result
LSR1 0
// release result
POP
RET