Many decades ago, you programmed computers by flipping switches. It was a slow, error-prone and tedious process. Then came assembly language, which was machine code
that humans could actually read. The great age of assembly came in the early 80s, when it was used to power commercial games for 8-bit boxes such as the CBM-64; since basic interpreters were slow and there were no C compilers, only assembly language code ran fast enough. Still in use today
, assembly remains slow and tedious. In the time it would take you to write ten lines of assembly, you could write ten lines of Python or C# that would accomplish far, far more from a software perspective. (That hasn’t stopped the people who still like to write 8-bit
assembly; there’s even a C compiler
that outputs 6502 machine code for CBM-64/Vic-20, and so on.) The other issue with assembly is the lack of portability. Converting 6502 to Z80 (or some other assembly language) is a non-trivial piece of work, despite some advances in automation. Thirty years ago, it might have taken you a month to convert, test, and release a working program based on 5,000 lines of assembly code. Things are still pretty slow, but assembly does have its uses in legacy systems and software that must deal directly with hardware (i.e., the Internet of Things).
WebAssembly is a low-level binary format, not unlike assembly language. But WebAssembly code isn't the most readable. Can you figure out what this example does?
It's a recursive factorial function, and i64 is a 64-bit integer variable. You can see the original C/C++ source code, plus this and the binary on the text format
page. Only masochists would write programs in wasm (the short name for WebAssembly). Currently, the main programming languages are C/C++, whose programs are compiled by Emscriptem
into wasm; since December 2016, Rust
can also be compiled to wasm. The spec for the WebAssembly VM is available on Github
, with a current version readable online
include numeric variables that are either 32- or 64-bit int or floats; all instructions and operators are explicitly typed with no overloading rules.
Current State of WebAssembly
WebAssembly is still a work in progress. Earlier this year, W3c WebAssembly Community Group announced that the Minimum Viable Product
(MVP) was complete, with approximately the same functionality as asm.js (supported platforms include Chrome and Android 57, Opera 44, Edge 15 (experimental) and Firefox 52.) Mozilla have been very good about documenting WebAssembly’s progress; take a look at the Mozilla WebAssembly
pages. Finally it’s worth noting that WebAssembly is intended to go beyond the web