fill:Wasm 文字指令

fill 記憶體指令將記憶體區域中的所有位元組設定為給定位元組。

該指令不返回值。如果指定的記憶體區域超出邊界,則會觸發陷阱(異常)。

語法

在預設記憶體中填充

wat
;; Fill region at offset/range in default memory with 255
i32.const 200 ;; The pointer to the region to update
i32.const 255 ;; The value to set each byte to (must be < 256)
i32.const 100 ;; The number of bytes to update
memory.fill ;; Fill default memory

;; Fill default memory using an S-function
(memory.fill (i32.const 200) (i32.const 255) (i32.const 100))

填充指定記憶體(如果支援多記憶體)

wat
;; Fill specific memory referenced by its index
i32.const 200 ;; The pointer to the region to update
i32.const 255 ;; The value to set each byte to (must be < 256)
i32.const 100 ;; The number of bytes to update
memory.fill (memory 1) ;; Fill memory with index 1

;; Fill memory referenced by its name
i32.const 200 ;; The pointer to the region to update
i32.const 255 ;; The value to set each byte to (must be < 256)
i32.const 100 ;; The number of bytes to update
memory.fill (memory $memoryName) ;; Fill memory with name "$memoryName"

;; Fill same memory using an S function
(memory.fill (memory $memoryName) (i32.const 200) (i32.const 255) (i32.const 100))

指令和操作碼

指令 二進位制操作碼
memory.fill 0xFC 0x0b

規範

規範
未知規範
# syntax-instr-memory

瀏覽器相容性

webassembly.bulk-memory-operations

webassembly.multiMemory

注意:multiMemory 相容性表格顯示了 fill 可用於指定記憶體的版本。