除法

div 指令,是除法的縮寫,用於將一個數除以另一個數,類似於其他語言中的 / 運算子。

試一試

(module
  (import "console" "log" (func $log (param i32)))
  (func $main
    ;; load `12` and `3` onto the stack
    i32.const 12
    i32.const 3

    i32.div_u ;; divide one number by the other
    call $log ;; log the result
  )
  (start $main)
)
const url = "{%wasm-url%}";
await WebAssembly.instantiateStreaming(fetch(url), { console });

語法

wat
;; load two numbers onto the stack
i32.const 12
i32.const 3

;; divide one number by the other
i32.div_u

;; the top item on the stack will now be 4 (12 / 3 = 4)
指令 二進位制操作碼
i32.div_s 0x6d
i32.div_u 0x6e
i64.div_s 0x7f
i64.div_u 0x80
f32.div 0x95
f64.div 0xa3