title: How to use load and store in WebAssembly
body: <p>Most of the demos in WebAssembly are still in C/C++ and don't show much <code>wat</code>. The few examples so far show things such as this:</p>
  
  <pre><code>;; Convert this to add.wasm by running:
  ;;
  ;;   wat2wasm add.wat -o add.wasm
  ;;
  (module
    (func (export "add") (param i32 i32) (result i32)
      get_local 0
      get_local 1
      i32.add))
  </code></pre>
  
  <p>That uses <em>local</em> variables and calls a native function. I know there's <code>get_global</code> and such too.</p>
  
  <p>What I'm wondering is how to use <a href="http://webassembly.org/docs/semantics/#linear-memory-accesses" rel="nofollow noreferrer">load and store</a> to manage global(?) memory. I am having trouble understanding how to use the functions.</p>
  
  <p>As an example, how would you load in an array of strings from JavaScript into WebAssembly, then print them out. Something like this:</p>
  
  <pre><code>const fs = require('fs')
  const buf = fs.readFileSync('./add.wasm')
  WebAssembly.instantiate(new Uint8Array(buf)).then(function(results){
    var lib = results.instance.exports
    lib.storeArray(['hello', 'world'])
    lib.logArray()
    // hello
    // world
  })
  </code></pre>
  
  <p>With assembly along the lines of:</p>
  
  <pre><code>(module
    (func (export "storeArray") (param ?) (result ?)
      iterate and i32.store somehow)
  
    (func (export "logArray") (param ?) (result ?)
      i32.load ? iterate through something
      console.log(item)))
  </code></pre>
  
  <p>Specifically wondering how to reference the memory addresses (loading/storing values) and use that feature.</p>