-
Notifications
You must be signed in to change notification settings - Fork 0
/
fib.umt
71 lines (56 loc) · 733 Bytes
/
fib.umt
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
v.declfn
()
(
int ; 0: start
int ; 1: end
)
i.const 0
set_l 0 ; start = 0
i.memsz
i.const 2
i.shr.u
set_l 1 ; end = memsz>>2
block
loop
get_l 0
get_l 1
i.eq
br_if 1 ; while(end != start)
get_l 0
get_l 0
i.ld32
call 1 ; fib(mem32[start])
str32 ; mem32[start] = fib(mem32[start])
i.const 1
get_l 0
i.add
set_l 0 ; start += 1
br 0 ; continue
end
end
ret
end
i.declfn ; 1: int fib(int n)
(
int ; 0: n
)
()
block
get_l 0
i.const 1
i.le.u
br_if 0 ; if (n <= 1) goto end
get_l 0
i.const 1
i.sub
call 1 ; fib(n-1)
get_l 0
i.const 2
i.sub
call 1 ; fib(n-2)
i.add
ret ; return fib(n-2)+fib(n-1)
end ; end: return n
get_l 0
ret
end