wat
(module
  ;; Import the required fd_write WASI function which will write the given io vectors to stdout
  ;; The function signature for fd_write is:
  ;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written
  (import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))

  (memory 1)
  (export "memory" (memory 0))

  ;; Write 'hello world\n' to memory at an offset of 8 bytes
  ;; Note the trailing newline which is required for the text to appear
  (data (i32.const 16) "hello world\n")

  (func $main (export "_start")
    ;; Creating a new io vector within linear memory
    (i32.store (i32.const 0)  (i32.const 16))  ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string
    (i32.store (i32.const 4)  (i32.const 12))  ;; iov.iov_len - The length of the 'hello world\n' string
    (i32.store (i32.const 8)  (i32.const 28))  ;; iov.iov_base - This is a pointer to the start of the 'hello world\n' string
    (i32.store (i32.const 12) (i32.const  1))  ;; iov.iov_len - The length of the 'hello world\n' string

    (i32.store (i32.const 28) (i32.const 48))
    (i32.store (i32.const 32) (i32.const 0))

    (call $fd_write
      (i32.const 1) ;; file_descriptor - 1 for stdout
      (i32.const 0) ;; *iovs - The pointer to the iov array, which is stored at memory location 0
      (i32.const 2) ;; iovs_len - We're printing 1 string stored in an iov - so one.
      (i32.const 36) ;; nwritten - A place in memory to store the number of bytes written
    )
    drop ;; Discard the number of bytes written from the top of the stack
  )
)

magical:
0061 736d

version
0100 0000

section type (01) de taille 12 (0c)
01 0c
  vec de taille 2 (02)
  02
    type de $fd_write
      functype (60) avec 4 parametres (04) de type i32 (7f)
      60 04 7f 7f 7f 7f
      fd_write rend une valeur (01) contenant le type i32 (7f)
      01 7f 
    type de _start
      functype (60) avec 0 parametres (00) et 0 resultat (00)
      60 00 00

section imports (02) de taille 26 (1a)
02 1a
  vec de taille 1 (01) contenant un import
  01 
    module, string de 13 caracteres (0d)
    0d
      "wasi_unstable"
      77 61 73 69 5f 75 6e 73 74 61 62 6c 65
    name, string de 8 caracteres (08)
    08
      "fd_write"
      66 64 5f 77 72 69 74 65
    description, fonction (00) avec l'indice de type 0 (00): fd_write
    00 00

section fonctions (03) de taille 2 (02)
03 02
  vec de taille 1 (01) contenant l'indice de type 1 (01): _start
  01 01

section memoire (05) de taille 3 (03)
05 03
  vec de taille 1 (01) contenant un memtype n'ayant pas de maximum (00) et un minimum de 1 (01)
  01 00 01

secion export (07) de taille 19 (13)
07 13
  vec contenant 2 (02) exports
  02
    export 0
      un name de taille 6 (06)
      06
        "memory"
        6d 65 6d 6f 72 79
      indice memoire (02) 0 (00)
      02 00
    export 1
      un name de taille 6 (06)
      06
        "_start"
        5f 73 74 61 72 74
      indice de fonction (00) 1 (01)
      00 01

section code (0a) de taille 57 (39)
  0a 39
  vec contenant 1 (01) code
    01
    taille du code 55 (37)
      37
      vec de 0 (00) locals
      00
      i32.const (41) 0 (00)
      41 00
      i32.const (41) 16 (10)
      41 10
      i32.store (36) avec un alignement de 2 (02) et pas d'offset (00)
      36 02 00
      i32.const (41) 4 (04)
      41 04
      i32.const (41) 12 (0c)
      41 0c
      i32.store (36) avec un alignement de 2 (02) et pas d'offset (00)
      36 02 00
      i32.const (41) 8 (08)
      41 08
      i32.const (41) 28 (1c)
      41 1c
      i32.store (36) avec un alignement de 2 (02) et pas d'offset (00)
      36 02 00
      i32.const (41) 12 (0c)
      41 0c
      i32.const (41) 1 (01)
      41 01
      i32.store (36) avec un alignement de 2 (02) et pas d'offset (00)
      36 02 00 
      i32.const (41) 28 (1c)
      41 1c
      i32.const (41) 48 (30)
      41 30
      i32.store (36) avec un alignement de 2 (02) et pas d'offset (00)
      36 02 00
      i32.const (41) 32 (20)
      41 20
      i32.const (41) 0 (00)
      41 00
      i32.store (36) avec un alignement de 2 (02) et pas d'offset (00)
      36 02 00
      i32.const (41) 1 (01)
      41 01
      i32.const (41) 0 (00)
      41 00
      i32.const (41) 2 (02)
      41 02
      i32.const (41) 36 (24)
      41 24
      call (10) a l'indice de fonction 0 (00)
      10 00
      drop (1a)
      1a
      end (0b)
      0b

section data (0b) de taille 18 (12)
0b 12
  vec de 1 (01) donnee
  01
    expression (00) i32.const (41) 16 (10)
    00 41 10
    end
    0b
    vec de 12 (0c) bytes
      0c
      "hello world\n"
      68 65 6c 6c 6f 20 77 6f 72 6c 64 0a 
