load: Wasm text instruction

The load memory instructions are used to load a number from a memory onto the stack.

There are load instructions for loading from a memory into an i32, i64, f32, and f64. For the integer numbers, there are separate instruction variants for loading a narrower signed number and unsigned number from memory and extending it into a wider type. For example, you can load an unsigned 8-bit number and convert it into an i32 using i32.load8_u. All the variants are listed below.

Try it

(module

  (memory $memory 1)
  (export "memory" (memory $memory))

  (func (export "load_first_item_in_mem") (param $num i32) (result i32)
    i32.const 0

    ;; load first item in memory and return the result
    i32.load
  )

)
const url = "{%wasm-url%}";
const result = await WebAssembly.instantiateStreaming(fetch(url));
const load_first_item_in_mem = result.instance.exports.load_first_item_in_mem;
const memory = result.instance.exports.memory;

const dataView = new DataView(memory.buffer);
// Store 30 at the beginning of memory
dataView.setUint32(0, 30, true);

console.log(load_first_item_in_mem(100));
// Expected output: 30

Syntax

Load from default memory

wat
;; Load from default memory at offset specified by value on top of stack
i32.const 0 ;; Stack variable containing memory offset (0) of number to be loaded.
i32.load    ;; Load from specified offset in default memory

;; Load from same location using an S-expression
(i32.load (i32.const 0))

Load from specified memory (if multi-memory supported)

wat
;; Load from memory specified by index
i32.const 0 ;; offset in memory to load from (0)
i32.load (memory 1) ;; load from memory index 1

;; Load from memory specified by name
i32.const 1  ;; offset in memory to load from (1)
i32.load (memory $memory1) ;; load from named memory $memory1

;; Load from memory specified by name using an S-expression
(i32.load (memory $memory1) (i32.const 0))

Instructions and opcodes

Instruction Binary opcode
i32.load 0x28
i64.load 0x29
f32.load 0x2a
f64.load 0x2b
i32.load8_s 0x2c
i32.load8_u 0x2d
i32.load16_s 0x2e
i32.load16_u 0x2f
i64.load8_s 0x30
i64.load8_u 0x31
i64.load16_s 0x32
i64.load16_u 0x33
i64.load32_s 0x34
i64.load32_u 0x35

Examples

Loading items from default memory

The first memory added to a Wasm module is the default memory and has index 0. We can load from this memory by adding a variable specifying the offset in the default memory of the number to be loaded onto the stack, and then calling load.

The code below shows a WAT file that demonstrates this:

wat
(module
  ;; Define memory named $memory and export
  (memory $memory 1)  ;; First memory declared is default, with index 0
  (export "memory" (memory $memory))

  ;; Exported function to load first item in default memory
  (func (export "load_first_item_in_mem") (param $num i32) (result i32)
    ;; load 0-offset item in memory and return the result
    i32.const 0
    i32.load
  )
)

Above we didn't need to specify the memory in the load instruction, but we could have done so using either the name or index of the default memory. That's shown in the following example.

For completeness, we can use the compiled version of the above file load_single.wasm with code similar to that shown below:

js
// await on the specified .wasm file to be fetched and loaded
const result = await WebAssembly.instantiateStreaming(
  fetch("load_single.wasm"),
);

// Get the exported function that we will call below
const load_first_item_in_mem = result.instance.exports.load_first_item_in_mem;

// Get the exported memory and store 30 at the 0 offset
const memory = result.instance.exports.memory;
const dataView = new DataView(memory.buffer);
dataView.setUint32(0, 30, true);

// Log the result of calling the exported Wasm function
console.log(load_first_item_in_mem(100)); // 30

Loading items from a specified memory

As memories are defined in a Wasm module they are sequentially allocated an index number from zero. You can load from a specific memory by specifying the memory instruction and the desired index or name after the load instruction. If you don't specify a particular memory the default memory with index 0 is used.

The module below shows how you might directly reference a memory by index.

wat
(module
  ;; Define memory for the module
  (memory $memory0 1)  ;; First (default) memory with memory index 0 (and 1 page)
  (memory $memory1 1)  ;; Second memory with index 1, named $memory1
  (export "memory" (memory $memory1))  ;; Export $memory1

  ;; Exported function to load first item in default memory
  (func (export "load_first_item_in_mem") (param $num i32) (result i32)
    ;; load 0-offset item in memory index 1 and return the result
    i32.const 0
    i32.load (memory 1)
  )
)

The body of the function could also have been written using any of the following options:

wat
i32.const 0
i32.load (memory $memory1)  ;; referencing memory by name

;; Using S-functions
(i32.load (memory 1) (i32.const 0))  ;; reference memory by index
(i32.load (memory $memory1) (i32.const 0)) ;; reference memory by name

We didn't use the default memory in the example. But you can also choose to specify this index if you want:

wat
i32.const 0
i32.load (memory 0)  ;; referencing memory by index

;; Using S-functions
(i32.load (i32.const 0))
(i32.load (memory 0) (i32.const 0))  ;; reference memory by index
(i32.load (memory $memory0) (i32.const 0)) ;; reference memory by name

The WAT files could be loaded using the same JavaScript code as the first example.

Specifications

Specification
Unknown specification
# syntax-instr-memory

Browser compatibility

webassembly.api.Memory

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
Memory
Chrome – Full support
Chrome 57 (Release date: 2017-03-09)
footnote Full support
Edge – Full support
Edge 16 (Release date: 2017-10-17)
footnote Full support
Firefox – Full support
Firefox 52 (Release date: 2017-03-07)
footnote Full support
Opera – Full support
Opera 44 (Release date: 2017-03-21)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 57 (Release date: 2017-03-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 52 (Release date: 2017-03-07)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 57 (Release date: 2017-03-16)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 8 (Release date: 2017-05-30)
footnote Full support
Memory() constructor
Chrome – Full support
Chrome 57 (Release date: 2017-03-09)
footnote Full support
Edge – Full support
Edge 16 (Release date: 2017-10-17)
footnote Full support
Firefox – Full support
Firefox 52 (Release date: 2017-03-07)
footnote Full support
Opera – Full support
Opera 44 (Release date: 2017-03-21)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 57 (Release date: 2017-03-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 52 (Release date: 2017-03-07)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 57 (Release date: 2017-03-16)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 8 (Release date: 2017-05-30)
footnote Full support
shared flag
Chrome – Full support
Chrome 74 (Release date: 2019-04-23)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 78 (Release date: 2020-06-30)
footnote Full support
Opera – Full support
Opera 62 (Release date: 2019-06-27)
footnote Full support
Safari – Full support
Safari 15.2 (Release date: 2021-12-13)
footnote
footnote Shared WebAssembly.Memory is gated behind COOP/COEP. For more detail, read Making your website "cross-origin isolated" using COOP and COEP.
Chrome Android – Full support
Chrome Android 88 (Release date: 2021-01-19)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 63 (Release date: 2021-04-16)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.2 (Release date: 2021-12-13)
footnote
footnote Shared WebAssembly.Memory is gated behind COOP/COEP. For more detail, read Making your website "cross-origin isolated" using COOP and COEP.
Samsung Internet – Full support
Samsung Internet 15 (Release date: 2021-08-13)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 15.2 (Release date: 2021-12-13)
footnote
footnote Shared WebAssembly.Memory is gated behind COOP/COEP. For more detail, read Making your website "cross-origin isolated" using COOP and COEP.
Bun – No support
Bun
footnote No support
Deno – Full support
Deno 1.10 (Release date: 2021-05-11)
footnote Full support
Node.js – Full support
Node.js 16.6 (Release date: 2021-07-29)
footnote Full support
buffer
Chrome – Full support
Chrome 57 (Release date: 2017-03-09)
footnote Full support
Edge – Full support
Edge 16 (Release date: 2017-10-17)
footnote Full support
Firefox – Full support
Firefox 52 (Release date: 2017-03-07)
footnote Full support
Opera – Full support
Opera 44 (Release date: 2017-03-21)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 57 (Release date: 2017-03-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 52 (Release date: 2017-03-07)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 57 (Release date: 2017-03-16)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 8 (Release date: 2017-05-30)
footnote Full support
grow
Chrome – Full support
Chrome 57 (Release date: 2017-03-09)
footnote Full support
Edge – Full support
Edge 16 (Release date: 2017-10-17)
footnote Full support
Firefox – Full support
Firefox 52 (Release date: 2017-03-07)
footnote Full support
Opera – Full support
Opera 44 (Release date: 2017-03-21)
footnote Full support
Safari – Full support
Safari 11 (Release date: 2017-09-19)
footnote Full support
Chrome Android – Full support
Chrome Android 57 (Release date: 2017-03-16)
footnote Full support
Firefox for Android – Full support
Firefox for Android 52 (Release date: 2017-03-07)
footnote Full support
Opera Android – Full support
Opera Android 43 (Release date: 2017-09-27)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11 (Release date: 2017-09-19)
footnote Full support
Samsung Internet – Full support
Samsung Internet 7 (Release date: 2018-03-16)
footnote Full support
WebView Android – Full support
WebView Android 57 (Release date: 2017-03-16)
footnote Full support
WebView on iOS – Full support
WebView on iOS 11 (Release date: 2017-09-19)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 8 (Release date: 2017-05-30)
footnote Full support
toFixedLengthBuffer
Chrome – Full support
Chrome 144 (Release date: 2026-01-13)
footnote Full support
Edge – Full support
Edge 144 (Release date: 2026-01-21)
footnote Full support
Firefox – Full support
Firefox 145 (Release date: 2025-11-11)
footnote Full support
Opera – Full support
Opera 128 (Release date: 2026-02-26)
footnote Full support
Safari – Full support
Safari 26.2 (Release date: 2025-12-12)
footnote Full support
Chrome Android – Full support
Chrome Android 144 (Release date: 2026-01-13)
footnote Full support
Firefox for Android – Full support
Firefox for Android 145 (Release date: 2025-11-11)
footnote Full support
Opera Android – Full support
Opera Android 95 (Release date: 2026-02-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 26.2 (Release date: 2025-12-12)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 144 (Release date: 2026-01-13)
footnote Full support
WebView on iOS – Full support
WebView on iOS 26.2 (Release date: 2025-12-12)
footnote Full support
Bun – No support
Bun
footnote No support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support
toResizableBuffer
Chrome – Full support
Chrome 144 (Release date: 2026-01-13)
footnote Full support
Edge – Full support
Edge 144 (Release date: 2026-01-21)
footnote Full support
Firefox – Full support
Firefox 145 (Release date: 2025-11-11)
footnote Full support
Opera – Full support
Opera 128 (Release date: 2026-02-26)
footnote Full support
Safari – Full support
Safari 26.2 (Release date: 2025-12-12)
footnote Full support
Chrome Android – Full support
Chrome Android 144 (Release date: 2026-01-13)
footnote Full support
Firefox for Android – Full support
Firefox for Android 145 (Release date: 2025-11-11)
footnote Full support
Opera Android – Full support
Opera Android 95 (Release date: 2026-02-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 26.2 (Release date: 2025-12-12)
footnote Full support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 144 (Release date: 2026-01-13)
footnote Full support
WebView on iOS – Full support
WebView on iOS 26.2 (Release date: 2025-12-12)
footnote Full support
Bun – No support
Bun
footnote No support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

webassembly.multiMemory

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
multiMemory
Chrome – Full support
Chrome 120 (Release date: 2023-12-05)
footnote Full support
Edge – Full support
Edge 120 (Release date: 2023-12-07)
footnote Full support
Firefox – Full support
Firefox 125 (Release date: 2024-04-16)
footnote Full support
Opera – Full support
Opera 106 (Release date: 2023-12-19)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 120 (Release date: 2023-12-05)
footnote Full support
Firefox for Android – Full support
Firefox for Android 125 (Release date: 2024-04-16)
footnote Full support
Opera Android – Full support
Opera Android 80 (Release date: 2024-01-25)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 25 (Release date: 2024-04-24)
footnote Full support
WebView Android – Full support
WebView Android 120 (Release date: 2023-12-05)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

Note: The multiMemory compatibility table indicates versions in which load can be used with a specified memory.