From 6e1eeeebfb453fa7c871869c19375ce60fbd7413 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 27 Jul 2019 16:01:55 -0700 Subject: 5485 - promote SubX to top-level --- html/examples/ex4.subx.html | 102 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 html/examples/ex4.subx.html (limited to 'html/examples/ex4.subx.html') diff --git a/html/examples/ex4.subx.html b/html/examples/ex4.subx.html new file mode 100644 index 00000000..caa0fe5e --- /dev/null +++ b/html/examples/ex4.subx.html @@ -0,0 +1,102 @@ + + + + +Mu - subx/examples/ex4.subx + + + + + + + + + + +https://github.com/akkartik/mu/blob/master/subx/examples/ex4.subx +
+ 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 == data 0x0a000000
+ 8 
+ 9 # the global variable we save to
+10 X:
+11     0/imm32  # space for read() to write to
+12 
+13 == code 0x09000000
+14 
+15 Entry:
+16 # syscall(read, stdin, X, 1)
+17 # . fd = 0 (stdin)
+18 bb/copy-to-EBX  0/imm32
+19 # . data = X (location to write result to)
+20 b9/copy-to-ECX  X/imm32
+21 # . size = 1 character
+22 ba/copy-to-EDX  1/imm32
+23 # . syscall
+24 b8/copy-to-EAX  3/imm32/read
+25 cd/syscall  0x80/imm8
+26 
+27 # syscall(write, stdout, X, 1)
+28 # . fd = 1 (stdout)
+29 bb/copy-to-EBX  1/imm32
+30 # . initialize X (location to read from)
+31 b9/copy-to-ECX  X/imm32
+32 # . size = 1 character
+33 ba/copy-to-EDX  1/imm32
+34 # . syscall
+35 b8/copy-to-EAX  4/imm32/write
+36 cd/syscall  0x80/imm8
+37 
+38 # syscall(exit, EBX)
+39 b8/copy-to-EAX  1/imm32/exit
+40 cd/syscall  0x80/imm8
+41 
+42 # . . vim:nowrap:textwidth=0
+
+ + + -- cgit 1.4.1-2-gfad0