0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

wasmで、アセンブラ

0
Last updated at Posted at 2026-10-27

概要

wasmが、スタックマシンらしいので、やってみた。

参考にしたページ

写真

image.png

サンプルコード



let code = `
(module
  (func $add (param $lhs i32) (param $rhs i32) (result i32)
    local.get $lhs
    local.get $rhs
    i32.add)
  (export "add" (func $add))
)
`

WabtModule().then((wabt) => {
  let wasmModule = wabt.parseWat("main.wat", code)
  let buffer = wasmModule.toBinary({
    log: true,
    canonicalize_lebs: true,
    relocatable: false,
    write_debug_names: false
  })
  wasmModule.destroy()
  console.log(buffer.log)
  console.log("bytesize : " + buffer.buffer.byteLength)
  WebAssembly.instantiate(buffer.buffer).then(
    (results) => {
      alert("result: " + results.instance.exports.add(0, 10))
    }
  )
  document.body.insertAdjacentHTML('beforeend', `<p style="color: green; font-weight: bold;">計算結果: <pre>${buffer.log}</pre></p>`);
})



成果物

以上。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?