1 ## print out a (global variable) string to stdout
 2 #
 3 # To run (from the subx directory):
 4 #   $ subx translate examples/ex6.subx -o examples/ex6
 5 #   $ subx run examples/ex6
 6 #   Hello, world!
 7 
 8 == code
 9 # instruction                     effective address                                                   operand     displacement    immediate
10 # op          subop               mod             rm32          base        index         scale       r32
11 # 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes
12 
13   # write(stdout, x, size)
14     # fd = 1 (stdout)
15   bb/copy                         .               .             .           .             .           .           .               1/imm32           # copy to EBX
16     # initialize x (location to write result to)
17   b9/copy                         .               .             .           .             .           .           .               x/imm32           # copy to ECX
18     # initialize size
19   8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           2/r32/EDX   size/disp32     .                 # copy *size to EDX
20     # write(fd, x, size)
21   b8/copy                         .               .             .           .             .           .           .               4/imm32/write     # copy to EAX
22   cd/syscall  0x80/imm8
23 
24   # exit(EBX)
25   b8/copy                         .               .             .           .             .           .           .               1/imm32/exit      # copy to EAX
26   cd/syscall  0x80/imm8
27 
28 == data
29 size:  # size of string
30   0e 00 00 00  # 14
31 x:  # string to print
32   48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 0a       00
33 # H  e  l  l  o  ,  ␣  w  o  r  l  d  !  newline  null
34 
35 # vim:ft=subx:nowrap