Internet Engineering

Introduction to WebAssembly

Fall 2026 ยท Amirkabir University of Technology
@1995parham

We, Mohammad and Narges gave a presentation as Introduction to WebAssembly in Internet Engineering course at Shahid Beheshti University. Here you can find the slides and some code example of this presentation for better intuition. Before using the codes, we highly recommend to read the slides.

Slides

Scroll the slides behind this box, or open the PDF.

Tools

  • To convert a .wat file to .wasm, first install wabt, then run the commands below in your terminal. More detailed help is on the wabt GitHub page.

Installation

To install it on your OS, follow the steps here carefully.

Running wat2wasm

some examples:

# parse and typecheck test.wat
$ bin/wat2wasm test.wat

# parse test.wat and write to binary file test.wasm
$ bin/wat2wasm test.wat -o test.wasm

# parse spec-test.wast, and write verbose output to stdout (including the
# meaning of every byte)
$ bin/wat2wasm spec-test.wast -v
	

From .wat to the Page

Ahead of time, wat2wasm turns addTwoNum.wat into the 41-byte addTwoNum.wasm. In the browser, fetch, then arrayBuffer, then WebAssembly.instantiate return a module and an instance, and instance.exports.add(14, 5) returns 19

Run It in the Browser

fetch() cannot read file:// URLs, so opening index.html from disk only prints an error. Serve wat2wasm/ over HTTP instead:

$ cd wat2wasm
$ python3 -m http.server
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
::1 - - [14/Oct/2026 06:31:21] "GET / HTTP/1.1" 200 -
::1 - - [14/Oct/2026 06:31:21] "GET /style.css HTTP/1.1" 200 -
::1 - - [14/Oct/2026 06:31:21] "GET /hello-WebAssembly.js HTTP/1.1" 200 -
::1 - - [14/Oct/2026 06:31:21] "GET /addTwoNum.wasm HTTP/1.1" 200 -

Open http://localhost:8000/: the page reads Addition result: 19.

Inside addTwoNum.wasm

The 41 bytes of addTwoNum.wasm: an 8-byte header with the asm magic number and version 1, then the type, function, export and code sections, each starting with its id and size. The export section names add; the code section holds local.get 0, local.get 1, i32.add, end
Fork me on GitHub