How to use WASM or WebAssembly

Follow this short and quick tutorial on how to use WASM!

From top to bottom- we have 10 different steps in order to get a Hello World from C without writing anything in our js file.

  1. We will select an Empty C Project although you can use C++ and Rust for using WASM aka High Level Languages.
  2. You will get three files, main.c main.html and main.js
  3. If you open the js file- you will see that the frist line of code is fetching the WASM that will later be instantiated into the wasm code
  4. As you can see we cleaned up the code and started using async
  5. Then we will run the code and get the result for output build running and build is complete
  6. After running it for the ou you will see a main.wasm file
  7. By checking the console you will see a related object named instance and module
  8. In the c file we have a reference to the js that calls the function
  9. We will next create a simple c code to run the Hello World
  10. Sadly we will have a null pointer so we will fix that
  11. Next step will be to get the memory buffer
  12. Fnally we will create a for function in order to get our string hello world variable
  13. Calling it and getting ID will print our Hello World named WASM
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s