1 ## read a character from stdin, save it to a global, write it to stdout
 2 #
 3 # To run (from the subx directory):
 4 #   $ subx translate examples/ex4.subx -o examples/ex4
 5 #   $ subx run examples/ex4
 6 
 7 == code
 8 # syscall(read, stdin, x, 1)
 9   # fd = 0 (stdin)
10 bb/copy-to-EBX  0/imm32
11   # initialize x (location to write result to)
12 b9/copy-to-ECX  x/imm32
13   # size = 1 character
14 ba/copy-to-EDX  1/imm32
15   # syscall
16 b8/copy-to-EAX  3/imm32/read
17 cd/syscall  0x80/imm8
18 
19 # syscall(write, stdout, x, 1)
20   # fd = 1 (stdout)
21 bb/copy-to-EBX  1/imm32
22   # initialize x (location to read from)
23 b9/copy-to-ECX  x/imm32
24   # size = 1 character
25 ba/copy-to-EDX  1/imm32
26   # syscall
27 b8/copy-to-EAX  4/imm32/write
28 cd/syscall  0x80/imm8
29 
30 # syscall(exit, EBX)
31 b8/copy-to-EAX  1/imm32/exit
32 cd/syscall  0x80/imm8
33 
34 == data
35 x:
36   00 00 00 00  # space for read() to write to
37 
38 # vim:nowrap:textwidth=0