Web Assembly

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/12

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

13 Terms

1
New cards

Assembly and Machine Code

knowt flashcard image
2
New cards

What are High Level Languages translated to?

machine code

<p>machine code</p>
3
New cards

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

<p>it is not quite an assembly language because it’s not meant for any specific machine</p><p>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</p>
4
New cards

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

<ul><li><p><span>It is a low-level binary format that runs in web browsers at near-native speed</span></p></li><li><p><span>It allows code written in languages like C/C++ or Rust to run in the browser, just like JavaScript</span></p></li><li><p><span>Designed to be fast, safe, and portable</span></p></li><li><p><span>Run powerful apps (games, video editors, or simulations) in the web browser, almost as fast as on your computer</span></p></li><li><p><span>“WebAssembly lets you run compiled languages in your browser”</span></p></li><li><p><span>Write C, C++ or Rust code</span></p></li><li><p><span>Compile it into WebAssembly module using Emscripten or Rust's wasm-pack</span></p></li><li><p><span>Load that into web application and call it from JavaScript</span></p></li><li><p><span>It’s not a replacement for JavaScript, it works alongside JavaScript</span></p></li></ul><p></p>
5
New cards

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

<ul><li><p><span>High level languages like C, C++ and Rust are compiled into binary format, that is, .wasm and text format .wat</span></p></li><li><p><span>The source code written in C, C++ and Rust is compiled to .wasm using a compiler</span></p></li><li><p><span>You can make use of the Emscripten SDK for compiling C/C++ to .wasm</span></p></li><li><p><span>The .wasm code can be used with the help of javascript in your html file to display the output</span></p></li><li><p><span>Textual format (.wat)</span></p></li><li><p><span>Binary representation (.wasm) deliver to the browser</span></p></li></ul><p></p>
6
New cards

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

7
New cards

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

8
New cards

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

9
New cards

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

10
New cards

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

11
New cards

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

12
New cards

Is WASM Safe?

  • Yes! It runs in a sandboxed environment (like JavaScript)

  • Cannot access your computer or files unless explicitly allowed

13
New cards

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