forked from rhysd/wain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fib.wat
174 lines (174 loc) · 3.5 KB
/
fib.wat
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
(module
(type (;0;) (func (param i32) (result i32)))
(type (;1;) (func (param i32)))
(type (;2;) (func))
(import "env" "putchar" (func $putchar (type 0)))
(func $print_uint (type 1) (param i32)
(local i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
global.get 0
local.set 1
i32.const 16
local.set 2
local.get 1
local.get 2
i32.sub
local.set 3
local.get 3
global.set 0
local.get 3
local.get 0
i32.store offset=12
local.get 3
i32.load offset=12
local.set 4
block ;; label = @1
block ;; label = @2
local.get 4
br_if 0 (;@2;)
br 1 (;@1;)
end
local.get 3
i32.load offset=12
local.set 5
i32.const 10
local.set 6
local.get 5
local.get 6
i32.div_s
local.set 7
local.get 7
call $print_uint
local.get 3
i32.load offset=12
local.set 8
i32.const 10
local.set 9
local.get 8
local.get 9
i32.rem_s
local.set 10
i32.const 48
local.set 11
local.get 10
local.get 11
i32.add
local.set 12
local.get 12
call $putchar
drop
end
i32.const 16
local.set 13
local.get 3
local.get 13
i32.add
local.set 14
local.get 14
global.set 0
return)
(func $fib (type 0) (param i32) (result i32)
(local i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
global.get 0
local.set 1
i32.const 16
local.set 2
local.get 1
local.get 2
i32.sub
local.set 3
local.get 3
global.set 0
i32.const 1
local.set 4
local.get 3
local.get 0
i32.store offset=8
local.get 3
i32.load offset=8
local.set 5
local.get 5
local.set 6
local.get 4
local.set 7
local.get 6
local.get 7
i32.le_s
local.set 8
i32.const 1
local.set 9
local.get 8
local.get 9
i32.and
local.set 10
block ;; label = @1
block ;; label = @2
local.get 10
i32.eqz
br_if 0 (;@2;)
i32.const 1
local.set 11
local.get 3
local.get 11
i32.store offset=12
br 1 (;@1;)
end
local.get 3
i32.load offset=8
local.set 12
i32.const 1
local.set 13
local.get 12
local.get 13
i32.sub
local.set 14
local.get 14
call $fib
local.set 15
local.get 3
i32.load offset=8
local.set 16
i32.const 2
local.set 17
local.get 16
local.get 17
i32.sub
local.set 18
local.get 18
call $fib
local.set 19
local.get 15
local.get 19
i32.add
local.set 20
local.get 3
local.get 20
i32.store offset=12
end
local.get 3
i32.load offset=12
local.set 21
i32.const 16
local.set 22
local.get 3
local.get 22
i32.add
local.set 23
local.get 23
global.set 0
local.get 21
return)
(func $_start (type 2)
(local i32 i32)
i32.const 20
local.set 0
local.get 0
call $fib
local.set 1
local.get 1
call $print_uint
return)
(table (;0;) 1 1 funcref)
(memory (;0;) 2)
(global (;0;) (mut i32) (i32.const 66560))
(export "memory" (memory 0))
(export "_start" (func $_start)))