1/12
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Assembly and Machine Code
What are High Level Languages translated to?
machine code
What is WASM meant for?
it is not quite an assembly language because it’s not meant for any specific machine
It’s for the browsers, and when we’re delivering code to be executed in the browser, we don’t know what kinds of machines will our code be running on
What is WebAssembly (WASM)?
It is a low-level binary format that runs in web browsers at near-native speed
It allows code written in languages like C/C++ or Rust to run in the browser, just like JavaScript
Designed to be fast, safe, and portable
Run powerful apps (games, video editors, or simulations) in the web browser, almost as fast as on your computer
“WebAssembly lets you run compiled languages in your browser”
Write C, C++ or Rust code
Compile it into WebAssembly module using Emscripten or Rust's wasm-pack
Load that into web application and call it from JavaScript
It’s not a replacement for JavaScript, it works alongside JavaScript
Workings of WebAssembly
High level languages like C, C++ and Rust are compiled into binary format, that is, .wasm and text format .wat
The source code written in C, C++ and Rust is compiled to .wasm using a compiler
You can make use of the Emscripten SDK for compiling C/C++ to .wasm
The .wasm code can be used with the help of javascript in your html file to display the output
Textual format (.wat)
Binary representation (.wasm) deliver to the browser
WASM Interfacing with a Web Page
You have to load in external modules that allow you to interface a webpage, typically via the JavaScript runtime in the browser, which also acts as the Bridge
JavaScript loads, initializes, and calls functions from the WebAssembly module
Instructions and Data
WASM has all the kinds of instructions you would expect from an assembly language type language
Add/sub/mul and similar maths operations
Bit operations, bitmasks, rotations
Load/store, Comparisons
Vector operations
But also has some structured instructions like loop and if.
Unlike assembly language, data in WASM has types
Can identify a big class of errors in using the wrong type
Can aid efficiency to help math things through to the underlying machine
WASM Program Formats
Typically represented by being compiled down into a binary format (.wasm)
But there is also a textual format (.wat)
It’s kind of like assembly language, but slightly higher level
Why WebAssembly?
It was created to get better performance on the web
It’s a low-level binary format that has a small size, so it’s fast
to load and execute
Code Reuse: Port existing C/C++ codebases to the browser
Web-Friendly: Integrates seamlessly with JavaScript and HTML
High-Performance Applications that WebAssembly supports
High-performance web games
Real-time video editing tools
Scientific simulations
Porting desktop apps to the browser (run SW in browser)
Don’t need to install anything , Runs on any device with a browser and Can be updated instantly online
Real Examples
App | What WASM does |
Figma | Fast graphics and UI rendering |
AutoCAD Web | Loads complex CAD files efficiently |
Unity Web Games | Compiles C# to WASM for browser games |
Adobe Photoshop Web | Processes large images in-browser |
Is WASM Safe?
Yes! It runs in a sandboxed environment (like JavaScript)
Cannot access your computer or files unless explicitly allowed
Developers Love WASM Because…
They can reuse existing C/C++ code
It gives better performance than JavaScript in heavy tasks
It’s portable and runs on any browser that supports WASM