banner
meanc

meanc

twitter
github
discord server

2 Minutes to Understand WebAssembly

It's obvious that this is an English word, and it's a compound word,
web + assembly
Many Chinese people don't know what assembly means, but if I tell you its translation, you will immediately know, it is assembly language.

As the name suggests, WebAssembly is assembly language on the web,
So theoretically, all high-level languages that can be compiled into assembly language can be converted to wasm through a compiler.

wasm has two suffixes .wat and .wasm
wat is the WebAssembly text presentation mode
The content looks something like this

(module (func $mul (param $factor1 i32) (param $factor2 i32) (result i32) local.get $factor1 local.get $factor2 i32.mul) (export "mul" (func $mul)))

wasm is a binary format
![Pasted image 20240216144348.png]

You can use Emscripten to compile high-level language code to wasm

$ emcc hello.c -o hello.html

This will return the compiled binary file and an html wrapper container, you can view the wasm execution status by opening the console in the html

Or you can also use a js wrapper container, you can run it directly in a nodejs environment, I usually use the run code plugin in vscode

$ emcc hello.c -o hello.js

This is the usage of wasm, as it can provide high performance close to native assembly level, it is often used to calculate tasks with high consumption in js, which also helps maintain mobile device battery life and provide a better running experience.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.