Up and running ASM.js in browser

emcc -v

emcc is transcompiler to compile C/C++ code to javascript code.

alt text

  • Create C/C++ test file

mkdir asmdemo
cd asmdemo
copy NUL hello-world.c (create hello-world.c)

Copy following content into newly created hello-world.c

#include<stdio.h>
int main() {
  printf("hello, world!\n");
  return 0;
}
  • Compile C/C++ code using emcc

emcc hello-world.c

it will create file name a.out.js

  • Run

node a.out.js

alt text

  • ASM.js in Browser

  • We want HTML so that we can view it in the browser. Enter this command to specify and HTML document.
emcc hello-world.c -o hello.html
  • Open hello.html that with your browser, and you can see it as a web page.

alt text

Written on July 10, 2016