Repository navigation
Expand file tree
/
Copy pathindex.md
More file actions
99 lines (72 loc) · 2.91 KB
/
Copy pathindex.md
File metadata and controls
99 lines (72 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
title: "store: Wasm Speicherinstruktion"
short-title: store
slug: WebAssembly/Reference/Memory/store
l10n:
sourceCommit: 6e99dbce48ff569afb34ad36a5aa4129a945af31
---
Die **`store`** [Speicherinstruktionen](/de/docs/WebAssembly/Reference/Memory) werden verwendet, um eine Zahl auf dem Stapel in einem Speicher zu speichern.
Es gibt `store`-Instruktionen zum Speichern von `i32`, `i64`, `f32` und `f64` im Speicher. Für die ganzen Zahlen gibt es separate Instruktionsvarianten, um eine weit typisierte Zahl in eine schmalere Zahl im Speicher zu speichern. Zum Beispiel können Sie eine 32-Bit-Zahl in einen 8-Bit-Platz im Speicher mit `i32.store8` speichern. Wenn die Zahl nicht in den schmaleren Zahlentyp passt, wird sie umgebrochen. Alle Varianten sind [unten aufgelistet](#instruktionen_und_opcodes).
{{InteractiveExample("Wat Demo: store", "tabbed-taller")}}
```wat interactive-example
(module
(memory $memory 1)
(export "memory" (memory $memory))
(func (export "store_in_mem") (param $num i32)
i32.const 0
local.get $num
;; store $num at position 0
i32.store
)
)
```
```js interactive-example
const url = "{%wasm-url%}";
const result = await WebAssembly.instantiateStreaming(fetch(url));
const store_in_mem = result.instance.exports.store_in_mem;
const memory = result.instance.exports.memory;
store_in_mem(100);
const dataView = new DataView(memory.buffer);
const first_number_in_mem = dataView.getUint32(0, true);
console.log(first_number_in_mem);
// Expected output: 100
```
## Syntax
Speichern im Standardspeicher
```wat
;; Store value in default memory at particular offset
i32.const 0 ;; stack variable with offset in memory to store the number
i32.const 20 ;; stack variable with the number to store
i32.store ;; store in default memory
;; Store using S-expression (same values and offset)
(i32.store (i32.const 0) (i32.const 20))
```
Speichern in einem spezifizierten Speicher (wenn Multi-Memory unterstützt wird)
```wat
;; Store in memory referenced by its index
i32.const 0 ;; offset in memory to store the number
i32.const 20 ;; the number to store
i32.store (memory 2) ;; store in memory with index 2
;; Store in memory referenced by its name
i32.const 0 ;; offset to store the number
i32.const 20 ;; the number to store
i32.store (memory $memoryName) ;; store in memory with name "$memoryName"
;; Store in same memory using an S-expression
(i32.store (memory $memoryName) (i32.const 0) (i32.const 20))
```
### Instruktionen und Opcodes
| Instruktion | Binärer Opcode |
| ------------- | -------------- |
| `i32.store` | `0x36` |
| `i64.store` | `0x37` |
| `f32.store` | `0x38` |
| `f64.store` | `0x39` |
| `i32.store8` | `0x3a` |
| `i32.store16` | `0x3b` |
| `i64.store8` | `0x3c` |
| `i64.store16` | `0x3d` |
| `i64.store32` | `0x3e` |
## Spezifikationen
{{Specifications}}
## Browser-Kompatibilität
{{Compat}}