fill: Wasm text instruction
The fill
memory instruction sets all bytes in a memory region to a given byte.
The instruction returns no value. It traps (exception) if the indicated memory region is out of bounds.
Syntax
Fill within default memory
wasm
;; 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))
Fill specified memory (if multi-memory supported)
wasm
;; 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))
Instructions and opcodes
Instruction | Binary opcode |
---|---|
memory.fill |
0xFC 0x0b |
Specifications
Specification |
---|
Unknown specification # syntax-instr-memory |
Browser compatibility
BCD tables only load in the browser
Note: Memory support in Wasm modules matches the WebAssembly.Memory
JavaScript API.
The multiMemory key indicates versions in which store
can be used with a specified memory.