-
Notifications
You must be signed in to change notification settings - Fork 0
/
fib.txt
75 lines (67 loc) · 963 Bytes
/
fib.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
input r15
stack 1
supermandive
stack 2
store r15 1
literal :back r0
store r0 2
jump :fib
back:
stack -2
getup
load 1 r15
stack -1
output r15
jump :end
fib:
load 1 r13 # argument
load 2 r2 # return address
literal 0 r3 # constant
literal 1 r4 # constant
cmp r13 r3 r5
branch r5
jump :is_zero
jump :not_zero
is_zero:
return r3 3
jump r2
not_zero:
cmp r13 r4 r5
branch r5
jump :is_one
jump :not_one
is_one:
return r4 3
jump r2
not_one:
sub r13 r4 r6 # x - 1
stack 1 # return value
supermandive # save registers
stack 2 # return jump address and argument
store r6 1 # argument
literal :hmmm r0
store r0 2 # this is return jump address
jump :fib # jump to function
hmmm:
stack -2 # function args tatck
getup # restore registers
load 1 r7 # return value
stack -1
stack 1
supermandive
stack 2
sub r6 r4 r8 # x - 1 - 1
store r8 1
literal :hm r0
store r0 2
jump :fib
hm:
stack -2
getup
load 1 r9 # return value
stack -1
add r7 r9 r10
return r10 3
jump r2
end:
eof