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/ex3.subx.html | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 html/examples/ex3.subx.html (limited to 'html/examples/ex3.subx.html') diff --git a/html/examples/ex3.subx.html b/html/examples/ex3.subx.html new file mode 100644 index 00000000..8c0f1642 --- /dev/null +++ b/html/examples/ex3.subx.html @@ -0,0 +1,101 @@ + + + + +Mu - subx/examples/ex3.subx + + + + + + + + + + +https://github.com/akkartik/mu/blob/master/subx/examples/ex3.subx +
+ 1 # Add the first 10 numbers, and return the result in the exit code.
+ 2 #
+ 3 # To run (from the subx directory):
+ 4 #   $ ./subx translate examples/ex3.subx -o examples/ex3
+ 5 #   $ ./subx run examples/ex3
+ 6 # Expected result:
+ 7 #   $ echo $?
+ 8 #   55
+ 9 
+10 == code 0x09000000
+11 #   instruction                     effective address                                                   register    displacement    immediate
+12 # . op          subop               mod             rm32          base        index         scale       r32
+13 # . 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
+14 
+15 Entry:
+16     # result: EBX = 0
+17     bb/copy-to-EBX  0/imm32
+18     # counter: ECX = 1
+19     b9/copy-to-ECX  1/imm32
+20 
+21 $loop:
+22     # if (counter > 10) break
+23     81          7/subop/compare     3/mod/direct    1/rm32/ECX    .           .             .           .           .               0xa/imm32         # compare ECX
+24     7f/jump-if-greater  $exit/disp8
+25     # result += counter
+26     01/add                          3/mod/direct    3/rm32/EBX    .           .             .           1/r32/ECX   .               .                 # add ECX to EBX
+27     # ++counter
+28     41/increment-ECX
+29     # loop
+30     eb/jump  $loop/disp8
+31 
+32 $exit:
+33     # syscall(exit, EBX)
+34     b8/copy-to-EAX  1/imm32/exit
+35     cd/syscall  0x80/imm8
+36 
+37 == data 0x0a000000
+38 
+39 # . . vim:nowrap:textwidth=0
+
+ + + -- cgit 1.4.1-2-gfad0