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 
 9 # syscall(read, stdin, X, 1)
10 # . fd = 0 (stdin)
11 bb/copy-to-EBX  0/imm32
12 # . data = X (location to write result to)
13 b9/copy-to-ECX  X/imm32
14 # . size = 1 character
15 ba/copy-to-EDX  1/imm32
16 # . syscall
17 b8/copy-to-EAX  3/imm32/read
18 cd/syscall  0x80/imm8
19 
20 # syscall(write, stdout, X, 1)
21 # . fd = 1 (stdout)
22 bb/copy-to-EBX  1/imm32
23 # . initialize X (location to read from)
24 b9/copy-to-ECX  X/imm32
25 # . size = 1 character
26 ba/copy-to-EDX  1/imm32
27 # . syscall
28 b8/copy-to-EAX  4/imm32/write
29 cd/syscall  0x80/imm8
30 
31 # syscall(exit, EBX)
32 b8/copy-to-EAX  1/imm32/exit
33 cd/syscall  0x80/imm8
34 
35 == data
36 
37 X:
38     00 00 00 00  # space for read() to write to
39 
40 # . . vim:nowrap:textwidth=0