Movatterモバイル変換


[0]ホーム

URL:


  1. WebAssembly
  2. Reference
  3. WebAssembly numeric instructions
  4. shr

shr: Wasm text instruction

Theshr instructions, short forshift-right, are used for performing a bitwise right-shift, similar to the>>> operator in other languages.

Try it

(module  (func (export "shift_right") (param $num i32) (param $by i32) (result i32)    ;; load the number to shift and the by how many spots    local.get $num    local.get $by    ;; shift and return the result    i32.shr_u  ))
const url = "{%wasm-url%}";await WebAssembly.instantiateStreaming(fetch(url), { console }).then(  (result) => {    const shift_right = result.instance.exports.shift_right;    const res = shift_right(0b00000000_00000000_00000000_00000111, 1);    console.log(numToBin(res));    // Expected output: "00000000_00000000_00000000_00000011"  },);function numToBin(num) {  return (num >>> 0)    .toString(2)    .padStart(32, "0")    .match(/.{1,8}/g)    .join("_");}

Syntax

wat
;; load two numbers onto the stacki32.const 7   ;; 00000111i32.const 1   ;; right shift one spot;; perform a bitwise right-shifti32.shr_u;; the top item on the stack will now be 3 (00000011)
InstructionBinary opcode
i32.shr_s0x75
i32.shr_u0x76
i64.shr_s0x87
i64.shr_u0x88

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp