-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci_modern.mx
More file actions
59 lines (54 loc) · 782 Bytes
/
fibonacci_modern.mx
File metadata and controls
59 lines (54 loc) · 782 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
%include "memory"
%include "control"
%include "procedures"
%include "io"
%func {fibRecursive, 1, 0,
%if { ; if number <= 1: return number-1
%seg:arg(0, lmle 1)
,
%seg:arg(0, ldm)
%returnr(fibRecursive)
}
; push fib(arg-2)
%seg:arg(0,
ldms 2
%stack:pushr()
)
%call(fibRecursive)
; push fib(arg-1)
%seg:arg(0,
ldms 1
%stack:pushr()
)
%call(fibRecursive)
; sum & return
%stack:apply_op(a)
%stack:pop()
}
%void_func {main, 0, 1,
; input prompt
outc 72
outc 111
outc 119
outc 32
outc 109
outc 97
outc 110
outc 121
outc 63
outc 32
%seg:move(%local, 0)
inum ; input
inl
%if { lmle 0, ; prohibit 0
str 1
}
%seg:local(0, ldm)
%for { ; for 0..input
%stack:dup()
%call(fibRecursive)
%stack:pop()
%print_endl(outum)
}
}
%call(main)