diff --git a/understanding-text-format/multi-memory.html b/understanding-text-format/multi-memory.html new file mode 100644 index 0000000..c457c23 --- /dev/null +++ b/understanding-text-format/multi-memory.html @@ -0,0 +1,70 @@ + + + +
+ +Log:
+ + + + + + diff --git a/understanding-text-format/multi-memory.wasm b/understanding-text-format/multi-memory.wasm new file mode 100644 index 0000000..a620012 Binary files /dev/null and b/understanding-text-format/multi-memory.wasm differ diff --git a/understanding-text-format/multi-memory.wat b/understanding-text-format/multi-memory.wat new file mode 100644 index 0000000..6e01c51 --- /dev/null +++ b/understanding-text-format/multi-memory.wat @@ -0,0 +1,45 @@ +(module + (import "console" "log" (func $log (param i32 i32 i32))) + + (import "js" "mem0" (memory 1)) + (import "js" "mem1" (memory 1)) + + ;; Create and export a third memory + (memory $mem2 1) + (export "memory2" (memory $mem2)) + + (data (memory 0) (i32.const 0) "Memory 0 data") + (data (memory 1) (i32.const 0) "Memory 1 data") + (data (memory 2) (i32.const 0) "Memory 2 data") + + ;; Add text to default (0-index) memory + (data (i32.const 13) " (Default)") + + (func $logMemory (param $memIndex i32) (param $memOffSet i32) (param $stringLength i32) + local.get $memIndex + local.get $memOffSet + local.get $stringLength + call $log + ) + + (func (export "logAllMemory") + ;; Log memory index 0, offset 0 + (i32.const 0) ;; memory index 0 + (i32.const 0) ;; memory offset 0 + (i32.const 23) ;; string length 23 + (call $logMemory) + + ;; Log memory index 1, offset 0 + i32.const 1 ;; memory index 1 + i32.const 0 ;; memory offset 0 + i32.const 20 ;; string length 20 - overruns the length of the data for illustration + call $logMemory + + ;; Log memory index 2, offset 0 + i32.const 2 ;; memory index 2 + i32.const 0 ;; memory offset 0 + i32.const 13 ;; string length 13 + call $logMemory + ) + +)