-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebassembly_control_flow.html
More file actions
377 lines (328 loc) · 19.5 KB
/
Copy pathwebassembly_control_flow.html
File metadata and controls
377 lines (328 loc) · 19.5 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html class="wide wow-animation" lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-151192680-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-151192680-1');
</script>
<!-- Site Title-->
<title>WebAssembly Control Flow Instructions</title>
<meta content="WebAssembly Control Flow Instructions."
name="description">
<meta content="webassembly control flow instructions, if, else, loop, br, return, nop, end, br_if, block, br_table"
name="keywords">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<link rel="icon" href="images/favicon.ico" type="image/x-icon">
<!-- Stylesheets-->
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Libre+Franklin:200,300,500,600,300italic">
<!--
<link rel="stylesheet" href="css/bootstrap.css">
-->
<link rel=“preload” href=“fonts//fontawesome-webfont.woff2?v=4.7.0” as=“font”>
<link rel=“preload” href=“fonts//fontawesome-webfont.woff?v=4.7.0” as=“font”>
<link rel=“preload” href=“fonts//fontawesome-webfont.eot?v=4.7.0” as=“font”>
<link rel="preload" href="css/bootstrap.min.css" as="style">
<link rel="preload" href="css/style.css" as="style">
<link rel="preload" href="js/core.min.js" as="script">
<link rel="preload" href="js/script.js" as="script">
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="css/style.css">
<!--[if lt IE 10]>
<div style="background: #212121; padding: 10px 0; box-shadow: 3px 3px 5px 0 rgba(0,0,0,.3); clear: both; text-align:center; position: relative; z-index:1;"><a href="http://windows.microsoft.com/en-US/internet-explorer/"><img src="images/ie8-panel/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today."></a></div>
<script src="js/html5shiv.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Page -->
<div class="page">
<div id="page-loader">
<div class="cssload-container">
<div class="cssload-speeding-wheel"></div>
</div>
</div>
<!-- Page header-->
<header class="page-header">
<!-- RD Navbar-->
<div class="rd-navbar-wrap">
<nav class="rd-navbar" data-layout="rd-navbar-fixed" data-sm-layout="rd-navbar-fixed" data-sm-device-layout="rd-navbar-fixed" data-md-layout="rd-navbar-fixed" data-md-device-layout="rd-navbar-fixed" data-lg-device-layout="rd-navbar-fixed" data-xl-device-layout="rd-navbar-static" data-xxl-device-layout="rd-navbar-static" data-lg-layout="rd-navbar-fixed" data-xl-layout="rd-navbar-static" data-xxl-layout="rd-navbar-static" data-stick-up-clone="false" data-sm-stick-up="true" data-md-stick-up="true" data-lg-stick-up="true" data-xl-stick-up="true" data-xxl-stick-up="true" data-lg-stick-up-offset="69px" data-xl-stick-up-offset="1px" data-xxl-stick-up-offset="1px">
<div class="rd-navbar-inner">
<!-- RD Navbar Panel -->
<div class="rd-navbar-panel">
<button class="rd-navbar-toggle" data-rd-navbar-toggle=".rd-navbar-nav-wrap"><span></span></button>
<!-- RD Navbar Brand-->
<div><a href="index.html" style="color:black;margin-top:2.5px;font-size:22px;">WEBASSEMBLYMAN</a></div>
</div>
<!-- RD Navbar Nav-->
<div class="rd-navbar-nav-wrap">
<ul class="rd-navbar-nav">
<li><a href="index.html">Home</a></li>
<li class="active"><a href="#">WebAssembly</a>
<ul class="rd-navbar-dropdown">
<li><a href="webcomponents.html">WebAssembly Web Components</a></li>
<li><a href="wat_webassembly_text_format.html">WebAssembly Text Format</a></li>
<li><a href="webassembly_wat_hello_world.html">WebAssembly WAT Hello World</a></li>
<li><a href="webassembly_data_types.html">WebAssembly Data Types</a></li>
<li><a href="webassembly_control_flow.html">WebAssembly Control Flow</a></li>
<li><a href="webassembly_front_end_web_development.html">WebAssembly Front-End Development</a></li>
</ul>
</li>
<li class="active"><a href="#">Blazor</a>
<ul class="rd-navbar-dropdown">
<li><a href="blazorhelloworld.html">Blazor Hello World</a></li>
<li><a href="blazor/blazorcomponents.html">Blazor Components</a></li>
<li><a href="blazor/blazoradmindashboard.html">Blazor Dashboard</a></li>
<li><a href="blazor/blazorcharts.html">Blazor Charts</a></li>
<li><a href="blazor/blazordonutchart.html">Blazor Donut Chart</a></li>
<li><a href="blazor/blazorpiechart.html">Blazor Pie Chart</a></li>
<li><a href="blazor/blazorbarchart.html">Blazor Bar Chart</a></li>
<li><a href="blazor/blazorlinechart.html">Blazor Line Chart</a></li>
<li><a href="blazor/blazordatabinding.html">Blazor Data Binding</a></li>
<li><a href="blazor/blazorevents.html">Blazor Events</a></li>
<li><a href="blazor/blazorcascadingvaluesparameters.html">Blazor Cascading Values & Parameters</a></li>
<li><a href="blazor/blazorbuildrendertree.html">Blazor BuildRenderTree</a></li>
<li><a href="blazor/blazorforloop.html">for loop</a></li>
<li><a href="blazor/blazorforeachloop.html">foreach loop</a></li>
<li><a href="blazor/blazorwhiledowhileloop.html">while loop</a></li>
<li><a href="blazor/blazorswitch.html">switch statement</a></li>
<li><a href="blazor/blazorifelseif.html">if, else and else if statement</a></li>
</ul>
</li>
<li class="active"><a href="#">Rust WebAssembly</a>
<ul class="rd-navbar-dropdown">
<li><a href="rust_webassembly_hello_world.html">Rust WebAssembly Hello World</a></li>
<li><a href="rustwasm/frontendframeworksrustwebassembly.html">Rust WebAssembly Front End Frameworks</a></li>
<li><a href="rustwasm/how_to_manipulate_the_dom_in_rust_webassembly.html">DOM manipulation</a></li>
<li><a href="rustwasm/how_to_create_and_access_html_objects_in_rust_webassembly.html">HTML Objects</a></li>
<li><a href="rustwasm/how_to_add_an_onclick_event_to_a_button_in_rust_webassembly.html">Button onclick</a></li>
<li><a href="rustwasm/how_to_add_mouse_events_in_rust_webassembly.html">Mouse events</a></li>
<li><a href="rustwasm/how_to_add_keyboard_events_in_rust_webassembly.html">Keyboard events</a></li>
<li><a href="rustwasm/how_to_log_to_the_console_in_rust_webassembly.html">Console log</a></li>
<li><a href="rustwasm/how_to_add_svg_in_rust_webassembly.html">SVG in Rust WebAssembly</a></li>
<li><a href="rustwasm/rustwasm_svg_donut_chart_webcomponent.html">SVG Donut Chart in Rust WebAssembly</a></li>
</ul>
</li>
<li class="active"><a href="#">rustwasm API</a>
<ul class="rd-navbar-dropdown">
<li><a href="rustwasm/wasm-bindgen.html">wasm-bindgen</a></li>
<li><a href="rustwasm/wasm_bindgen_jsvalue.html">wasm_bindgen::JsValue</a></li>
<li><a href="rustwasm/web-sys.html">web-sys</a></li>
<li><a href="rustwasm/web_sys_console.html">web_sys::console</a></li>
<li><a href="rustwasm/web_sys_document.html">web_sys::Document</a></li>
<li><a href="rustwasm/web_sys_htmlcanvaselement.html">web_sys::HtmlCanvasElement</a></li>
<li><a href="rustwasm/web_sys_canvasrenderingcontext2d.html">web_sys::CanvasRenderingContext2d</a></li>
<li><a href="rustwasm/web_sys_fontface.html">web_sys::FontFace</a></li>
<li><a href="rustwasm/web_sys_svgelement.html">web_sys::SvgElement</a></li>
<li><a href="rustwasm/js-sys.html">js-sys</a></li>
<li><a href="rustwasm/js_sys_array.html">js_sys::Array</a></li>
<li><a href="rustwasm/gloo_events_eventlistener.html">gloo_events::EventListener</a></li>
<li><a href="rustwasm/wasm-bindgen-futures.html">wasm-bindgen-futures</a></li>
<li><a href="rustwasm/wasm_bindgen_futures_jsfuture.html">wasm-bindgen-futures::JsFuture</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
</div>
</header>
<section class="breadcrumbs-custom">
<div class="container">
<div class="breadcrumbs-custom__inner">
<p class="breadcrumbs-custom__title">Man(ual) page for WebAssembly</p>
<ul class="breadcrumbs-custom__path">
<li><a href="index.html">Home</a></li>
<li>WebAssembly</li>
</ul>
</div>
</div>
</section>
<section class="bg-default section-lg">
<div class="container">
<div class="row row-60 justify-content-sm-center">
<div class="col-lg-8 section-divided__main">
<!--
<section class="section-md post-single-body">
<div class="quote-default">
<svg class="quote-default__mark" version="1.1" baseprofile="tiny" x="0px" y="0px" width="30.234px" height="23.484px" viewbox="0 0 30.234 23.484">
<g>
<path d="M12.129,0v1.723c-2.438,0.891-4.348,2.291-5.73,4.201c-1.383,1.911-2.074,3.897-2.074,5.959 c0,0.445,0.07,0.773,0.211,0.984c0.093,0.141,0.199,0.211,0.316,0.211c0.117,0,0.293-0.082,0.527-0.246 c0.75-0.539,1.699-0.809,2.848-0.809c1.336,0,2.519,0.545,3.551,1.635c1.031,1.09,1.547,2.385,1.547,3.885 c0,1.57-0.592,2.953-1.775,4.148c-1.184,1.195-2.619,1.793-4.307,1.793c-1.969,0-3.668-0.809-5.098-2.426 C0.715,19.441,0,17.274,0,14.555c0-3.164,0.972-6,2.918-8.508C4.863,3.539,7.933,1.524,12.129,0z M29.039,0v1.723 c-2.438,0.891-4.348,2.291-5.73,4.201c-1.383,1.911-2.074,3.897-2.074,5.959c0,0.445,0.07,0.773,0.211,0.984 c0.094,0.141,0.199,0.211,0.316,0.211s0.293-0.082,0.527-0.246c0.75-0.539,1.699-0.809,2.848-0.809c1.336,0,2.52,0.545,3.551,1.635 s1.547,2.385,1.547,3.885c0,1.57-0.592,2.953-1.775,4.148s-2.619,1.793-4.307,1.793c-1.969,0-3.668-0.809-5.098-2.426 s-2.145-3.785-2.145-6.504c0-3.164,0.973-6,2.918-8.508C21.773,3.539,24.844,1.524,29.039,0z"></path>
</g>
</svg>
<div class="quote-default__text">
<p class="q heading-4">Samples, references, tutorials and how-to on Blazor and WebAssembly.</p>
</div>
<p class="quote-default__cite">Man page for Blazor & WebAssembly</p>
</div>
</section>
-->
<h4>WebAssembly Control Flow Instructions</h4>
<p>
WebAssembly control flow is expressed in structured instructions such as if, else, br, loop, return and block. Below is a list of the instructions.
</p>
<ul class="list-marked">
<li>if - The beginning of an if instruction.</li>
<li>then - The then block of an if instruction.</li>
<li>else - The else block of an if instruction.</li>
<li>loop - A labeled block used to create loops.</li>
<li>block - A sequence of instructions, often used within expressions. </li>
<li>br - Branch to the given label in a containing instruction or block. </li>
<li>br_if - Identical to a branch, but with a prerequisite condition. </li>
<li>br_table - Branches, but instead of to a label it jumps to a function index in a table. </li>
<li>return - Returns a value from the instruction. </li>
<li>end - Marks the end of a block, loop, if, or a function.</li>
<li>nop - An operation that does nothing. </li>
</ul>
<p>
</p>
<h5>Usage of if then else</h5>
<p>
If the value of $x is less than 10, then return the value of 10, else return the value of $x.
</p>
<div class="quote-bordered" style="text-align:left;background:black">
<pre><code style="color:white;">
(module
(func $min10 (param $x i32) (result i32)
(if (result i32)
(i32.lt_s
(get_local $x)
(i32.const 10)
)
(then
(i32.const 10)
)
(else
(get_local $x)
)
)
)
(export "min10" (func $min10))
)
</code></pre>
</div>
<p>Complete Sample Source code</p>
<ul class="list-marked">
<li><a href=wat/wat_if_then_else.zip>wat if then else</a></li>
</ul>
</div>
<div class="col-lg-4 section-divided__aside section-divided__aside-left">
<section class="section-md">
<h5>WebAssembly</h5>
<ul class="list-linked">
<li><a href="webcomponents.html">WebAssembly Web Components</a></li>
<li><a href="wat_webassembly_text_format.html">WebAssembly Text Format</a></li>
<li><a href="webassembly_wat_hello_world.html">WebAssembly WAT Hello World</a></li>
<li><a href="webassembly_data_types.html">WebAssembly Data Types</a></li>
<li><a href="webassembly_control_flow.html">WebAssembly Control Flow</a></li>
<li><a href="webassembly_front_end_web_development.html">WebAssembly Front-End Development</a></li>
</ul>
</section>
<section class="section-md">
<h5>Blazor Topics</h5>
<ul class="list-linked">
<li><a href="blazorhelloworld.html">Blazor Hello World</a></li>
<li><a href="blazor/blazorcomponents.html">Blazor Components</a></li>
<li><a href="blazor/blazoradmindashboard.html">Blazor Dashboard</a></li>
<li><a href="blazor/blazorcharts.html">Blazor Charts</a></li>
<li><a href="blazor/blazordonutchart.html">Blazor Donut Chart</a></li>
<li><a href="blazor/blazorpiechart.html">Blazor Pie Chart</a></li>
<li><a href="blazor/blazorbarchart.html">Blazor Bar Chart</a></li>
<li><a href="blazor/blazorlinechart.html">Blazor Line Chart</a></li>
<li><a href="blazor/blazordatabinding.html">Blazor Data Binding</a></li>
<li><a href="blazor/blazorevents.html">Blazor Events</a></li>
<li><a href="blazor/blazorcascadingvaluesparameters.html">Blazor Cascading Values & Parameters</a></li>
<li><a href="blazor/blazorbuildrendertree.html">Blazor BuildRenderTree</a></li>
<li>Injection (coming soon)</li>
<li>Layout (coming soon)</li>
</ul>
</section>
<section class="section-md">
<h5>Blazor Syntax</h5>
<ul class="list-linked">
<li><a href="blazor/blazorforloop.html">for loop</a></li>
<li><a href="blazor/blazorforeachloop.html">foreach loop</a></li>
<li><a href="blazor/blazorwhiledowhileloop.html">while loop</a></li>
<li><a href="blazor/blazorswitch.html">switch statement</a></li>
<li><a href="blazor/blazorifelseif.html">if, else and else if statement</a></li>
</ul>
</section>
<section class="section-md">
<h5>Rust WebAssembly</h5>
<ul class="list-linked">
<li><a href="rust_webassembly_hello_world.html">Rust WebAssembly Hello World</a></li>
<li><a href="../rustwasm/frontendframeworksrustwebassembly.html">Front End Frameworks</a></li>
<li><a href="../rustwasm/how_to_manipulate_the_dom_in_rust_webassembly.html">DOM manipulation</a></li>
<li><a href="../rustwasm/how_to_create_and_access_html_objects_in_rust_webassembly.html">HTML Objects</a></li>
<li><a href="../rustwasm/how_to_add_an_onclick_event_to_a_button_in_rust_webassembly.html">Button onclick</a></li>
<li><a href="../rustwasm/how_to_add_mouse_events_in_rust_webassembly.html">Mouse events</a></li>
<li><a href="../rustwasm/how_to_add_keyboard_events_in_rust_webassembly.html">Keyboard events</a></li>
<li><a href="../rustwasm/how_to_log_to_the_console_in_rust_webassembly.html">Console log</a></li>
<li><a href="../rustwasm/how_to_add_svg_in_rust_webassembly.html">SVG in Rust WebAssembly</a></li>
<li><a href="../rustwasm/rustwasm_svg_donut_chart_webcomponent.html">SVG Donut Chart in Rust WebAssembly</a></li>
</ul>
</section>
<section class="section-md">
<h5>rustwasm API</h5>
<ul class="list-linked">
<li><a href="../rustwasm/wasm-bindgen.html">wasm-bindgen</a></li>
<li><a href="../rustwasm/wasm_bindgen_jsvalue.html">wasm_bindgen::JsValue</a></li>
<li><a href="../rustwasm/web-sys.html">web-sys</a></li>
<li><a href="../rustwasm/web_sys_console.html">web_sys::console</a></li>
<li><a href="../rustwasm/web_sys_document.html">web_sys::Document</a></li>
<li><a href="../rustwasm/web_sys_htmlcanvaselement.html">web_sys::HtmlCanvasElement</a></li>
<li><a href="../rustwasm/web_sys_canvasrenderingcontext2d.html">web_sys::CanvasRenderingContext2d</a></li>
<li><a href="../rustwasm/web_sys_fontface.html">web_sys::FontFace</a></li>
<li><a href="../rustwasm/web_sys_svgelement.html">web_sys::SvgElement</a></li>
<li><a href="../rustwasm/js-sys.html">js-sys</a></li>
<li><a href="../rustwasm/js_sys_array.html">js_sys::Array</a></li>
<li><a href="../rustwasm/gloo_events_eventlistener.html">gloo_events::EventListener</a></li>
<li><a href="../rustwasm/wasm-bindgen-futures.html">wasm-bindgen-futures</a></li>
<li><a href="../rustwasm/wasm_bindgen_futures_jsfuture.html">wasm-bindgen-futures::JsFuture</a></li>
</ul>
</section>
</div>
</div>
</div>
</section>
<!-- Divider-->
<div class="container">
<div class="divider"></div>
</div>
<section class="pre-footer-corporate" style="display:none">
<div class="container">
<div class="row justify-content-sm-center justify-content-lg-start row-30 row-md-60">
<ul class="list-inline-xxs">
<li><a class="icon icon-xxs icon-primary fa fa-twitter" href="https://connectcode.twitter.com"></a></li>
</ul>
<div class="col-sm-10 col-md-6 col-lg-3 col-xl-3">
</div>
<div class="col-sm-10 col-md-6 col-lg-5 col-xl-3">
</div>
<div class="col-sm-10 col-md-6 col-lg-4 col-xl-3">
<ul class="list-xs">
</ul>
</div>
</div>
</div>
</section>
<footer class="footer-corporate">
<div class="container">
<div class="footer-corporate__inner">
<p class="rights">Copyright <span>https://www.webassemblyMan.com</span><span> </span>2018 - <span id="copyright-year"></span>.
</p>
</div>
</div>
</footer>
</div>
<!-- Global Mailform Output-->
<div class="snackbars" id="form-output-global"></div>
<script src="js/core.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>