Skip to content
Tech News
← Back to articles

WASM is not quite a stack machine

read original get WebAssembly Developer Book → more articles
Why This Matters

This article clarifies that WebAssembly (Wasm) is often mistaken as a pure stack machine, but in reality, it operates more like a register machine. Understanding this distinction is crucial for developers working with Wasm, as it impacts performance optimization and debugging. Recognizing Wasm's hybrid nature can lead to more efficient code and better tooling in the evolving web and system programming landscape.

Key Takeaways

Wasm is not quite a stack machine

April 27, 2026

Everyone knows Wasm is a stack machine. Wikipedia says so, the official Wasm design specification says so, you get it. I thought so too.

That is, until I started writing Wasm code – not compiling for Wasm, but writing the instructions by hand. And I found out that there exists a major difference between Wasm and all other stack-based languages, that makes this claim misleading.

Register vs stack

Let’s back up a bit. What is a stack machine, even?

Say you write a program in a high-level language, and at some point you want to calculate 2 * 3 + 5 * 7 . Low-level languages don’t have a notion of compound expressions: they can only perform one operation at a time. So you need to do two multiplications, save their results, and then perform addition.

Many low-level languages, like x86 assembly, would represent these steps as follows:

a = 2

b = 3

... continue reading