Wasm Builders 🧱

Silvana
Silvana

Posted on

Doing basic operations using WebAssembly with C

At the beginning of any learning process you face a kind of adventure, when you learn a concept like WebAssembly you start a beautiful adventure.

Think like Indiana Jones discovering a new treasure, it's not easy but it's so fantastic. You will learn new tools, concepts and even meet some enthusiasts like you.

Image description

First we start by trying to use simple commands, short algorithms and then you can do a little bit more.

I will show how I made my first steps with WebAssembly.

At first I created a file using C language, in this file I wrote code that has as an output a basic operation using " -, +, * and /". The dynamic is, you give the operation and then you can see the result.

Image description

After saving my file, I opened my prompt to start the process of compiling.

  1. The first step is to use gcc command

  2. Second, you can use ./a.out to see your output.

  3. Then you will use the "wasicc" command like this:

wasicc YourFile.c -o YourFile.wasm

while executing this command, it might generate some warnings but you can ignore them.

Image description

Executing it using WASM Runtime to see it as wasm

Image description

This is the result! Cool, isn't?

Of course we fail sometimes, we face some problems, but I was helped by other adventurers. Luckily we are not Indiana Jones and if we failed we don't die in a cave full of poisonous snakes and beetles.

However, we can still enjoy our treasure...

Image description

Top comments (0)