fill: Wasm text instruction
Thememory.fillmemory 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.
In this article
Syntax
Fill within default memory
wat
;; Fill region at offset/range in default memory with 255i32.const 200 ;; The pointer to the region to updatei32.const 255 ;; The value to set each byte to (must be < 256)i32.const 100 ;; The number of bytes to updatememory.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)
wat
;; Fill specific memory referenced by its indexi32.const 200 ;; The pointer to the region to updatei32.const 255 ;; The value to set each byte to (must be < 256)i32.const 100 ;; The number of bytes to updatememory.fill (memory 1) ;; Fill memory with index 1;; Fill memory referenced by its namei32.const 200 ;; The pointer to the region to updatei32.const 255 ;; The value to set each byte to (must be < 256)i32.const 100 ;; The number of bytes to updatememory.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
>webassembly.bulk-memory-operations
webassembly.multiMemory
Note:ThemultiMemory compatibility table indicates versions in whichfill can be used with a specified memory.