Skip to content

Instantly share code, notes, and snippets.

@yurydelendik
Last active November 27, 2024 22:11
Show Gist options
  • Select an option

  • Save yurydelendik/2061007fc0f8736d30f554bdeba10df0 to your computer and use it in GitHub Desktop.

Select an option

Save yurydelendik/2061007fc0f8736d30f554bdeba10df0 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script>
var memory;
var env = {
sys: {
print(ptr) {
let p = ptr;
while (memory[p]) p++;
console.log(String.fromCharCode(...memory.subarray(ptr, p)));
}
}
};
fetch('helloworld2.wasm')
.then(req => req.arrayBuffer())
.then(buf => WebAssembly.instantiate(buf, env))
.then(({instance}) => {
memory = new Uint8Array(instance.exports.memory.buffer);
instance.exports.main();
});
</script>
<h1>base64 helloworld2.wasm</h1>
<p>AGFzbQ0AAAABiICAgAACYAF/AGAAAAKNgICAAAEDc3lzBXByaW50AAADgoCAgAABAQWGgICAAAEByAHIAQeRgICAAAIGbWVtb3J5AgAEbWFpbgABCoyAgIAAAYaAgIAAAEEAEAALC5OAgIAAAQBBAAsNSGVsbG8sIHdvcmxkAA==</p>
<h1>wasm-dis helloworld2.wasm | tee helloworld2.wast</h1>
<pre>
(module
(memory (export "memory") 200 200)
(data (i32.const 0) "Hello, world\00")
(import $print "sys" "print" (param i32))
(func (export "main")
(call $print
(i32.const 0)
)
)
)
</pre>
</body>
</html>
@lin7sh
Copy link
Copy Markdown

lin7sh commented Mar 17, 2017

thanks for sharing. good wasm guide is very rare

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment