From c8998b51e1995c307ddf831bff65309d57c25386 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 19 Oct 2019 18:49:40 -0700 Subject: 5707 --- html/apps/factorial2.subx.html | 229 +++++++++++++++++++++-------------------- html/apps/factorial3.subx.html | 152 ++++++++++++++------------- html/apps/factorial4.subx.html | 163 +++++++++++++++-------------- 3 files changed, 278 insertions(+), 266 deletions(-) (limited to 'html/apps/*.subx.html') diff --git a/html/apps/factorial2.subx.html b/html/apps/factorial2.subx.html index 5dd07391..a8685c80 100644 --- a/html/apps/factorial2.subx.html +++ b/html/apps/factorial2.subx.html @@ -60,119 +60,122 @@ if ('onhashchange' in window) {
   1 ## compute the factorial of 5, and return the result in the exit code
   2 #
-  3 # To run:
-  4 #   $ ./ntranslate init.linux 0*.subx apps/factorial.subx -o apps/factorial
-  5 #   $ ./subx run apps/factorial
-  6 # Expected result:
-  7 #   $ echo $?
-  8 #   120
-  9 #
- 10 # You can also run the automated test suite:
- 11 #   $ ./subx run apps/factorial test
- 12 # Expected output:
- 13 #   ........
- 14 # Every '.' indicates a passing test. Failing tests get a 'F'.
- 15 
- 16 == code
- 17 
- 18 Entry:  # run tests if necessary, compute `factorial(5)` if not
- 19     # . prologue
- 20     89/<- %ebp 4/r32/esp
- 21 
- 22     # initialize heap
- 23     # . Heap = new-segment(Heap-size)
- 24     # . . push args
- 25     68/push Heap/imm32
- 26     68/push Heap-size/imm32
- 27     # . . call
- 28     e8/call new-segment/disp32
- 29     # . . discard args
- 30     81 0/subop/add %esp 8/imm32
- 31 
- 32     # - if argc > 1 and argv[1] == "test", then return run_tests()
- 33     # if (argc <= 1) goto run-main
- 34     81 7/subop/compare *ebp 1/imm32
- 35     7e/jump-if-lesser-or-equal $run-main/disp8
- 36     # if (!kernel-string-equal?(argv[1], "test")) goto run-main
- 37     # . eax = kernel-string-equal?(argv[1], "test")
- 38     # . . push args
- 39     68/push "test"/imm32
- 40     ff 6/subop/push *(ebp+8)
- 41     # . . call
- 42     e8/call kernel-string-equal?/disp32
- 43     # . . discard args
- 44     81 0/subop/add %esp 8/imm32
- 45     # . if (eax == 0) goto run-main
- 46     3d/compare-eax-and 0/imm32
- 47     74/jump-if-equal $run-main/disp8
- 48     # run-tests()
- 49     e8/call run-tests/disp32
- 50     # syscall(exit, *Num-test-failures)
- 51     8b/-> *Num-test-failures 3/r32/ebx
- 52     eb/jump $main:end/disp8
- 53 $run-main:
- 54     # - otherwise return factorial(5)
- 55     # eax = factorial(5)
- 56     # . . push args
- 57     68/push 5/imm32
- 58     # . . call
- 59     e8/call factorial/disp32
- 60     # . . discard args
- 61     81 0/subop/add %esp 4/imm32
- 62     # syscall(exit, eax)
- 63     89/<- %ebx 0/r32/eax
- 64 $main:end:
- 65     b8/copy-to-eax 1/imm32/exit
- 66     cd/syscall 0x80/imm8
- 67 
- 68 factorial:  # n : int -> int/eax
- 69     # . prologue
- 70     55/push-ebp
- 71     89/<- %ebp 4/r32/esp
- 72     53/push-ebx
- 73     # if (n <= 1) return 1
- 74     b8/copy-to-eax 1/imm32
- 75     81 7/subop/compare *(ebp+8) 1/imm32
- 76     7e/jump-if-<= $factorial:end/disp8
- 77     # ebx = n-1
- 78     8b/-> *(ebp+8) 3/r32/ebx
- 79     4b/decrement-ebx
- 80     # eax = factorial(n-1)
- 81     # . . push args
- 82     53/push-ebx
- 83     # . . call
- 84     e8/call factorial/disp32
- 85     # . . discard args
- 86     81 0/subop/add %esp 4/imm32
- 87     # return n * factorial(n-1)
- 88     f7 4/subop/multiply-into-eax *(ebp+8)
- 89     # TODO: check for overflow
- 90 $factorial:end:
- 91     # . epilogue
- 92     5b/pop-to-ebx
- 93     89/<- %esp 5/r32/ebp
- 94     5d/pop-to-ebp
- 95     c3/return
- 96 
- 97 test-factorial:
- 98     # factorial(5)
- 99     # . . push args
-100     68/push 5/imm32
-101     # . . call
-102     e8/call factorial/disp32
-103     # . . discard args
-104     81 0/subop/add %esp 4/imm32
-105     # check-ints-equal(eax, 120, msg)
-106     # . . push args
-107     68/push "F - test-factorial"/imm32
-108     68/push 0x78/imm32/expected-120
-109     50/push-eax
-110     # . . call
-111     e8/call check-ints-equal/disp32
-112     # . . discard args
-113     81 0/subop/add %esp 0xc/imm32
-114     # end
-115     c3/return
+  3 # Uses syntax sugar for:
+  4 #   rm32 operands
+  5 #
+  6 # To run:
+  7 #   $ ./ntranslate init.linux 0*.subx apps/factorial.subx -o apps/factorial
+  8 #   $ ./subx run apps/factorial
+  9 # Expected result:
+ 10 #   $ echo $?
+ 11 #   120
+ 12 #
+ 13 # You can also run the automated test suite:
+ 14 #   $ ./subx run apps/factorial test
+ 15 # Expected output:
+ 16 #   ........
+ 17 # Every '.' indicates a passing test. Failing tests get a 'F'.
+ 18 
+ 19 == code
+ 20 
+ 21 Entry:  # run tests if necessary, compute `factorial(5)` if not
+ 22     # . prologue
+ 23     89/<- %ebp 4/r32/esp
+ 24 
+ 25     # initialize heap
+ 26     # . Heap = new-segment(Heap-size)
+ 27     # . . push args
+ 28     68/push Heap/imm32
+ 29     68/push Heap-size/imm32
+ 30     # . . call
+ 31     e8/call new-segment/disp32
+ 32     # . . discard args
+ 33     81 0/subop/add %esp 8/imm32
+ 34 
+ 35     # - if argc > 1 and argv[1] == "test", then return run_tests()
+ 36     # if (argc <= 1) goto run-main
+ 37     81 7/subop/compare *ebp 1/imm32
+ 38     7e/jump-if-lesser-or-equal $run-main/disp8
+ 39     # if (!kernel-string-equal?(argv[1], "test")) goto run-main
+ 40     # . eax = kernel-string-equal?(argv[1], "test")
+ 41     # . . push args
+ 42     68/push "test"/imm32
+ 43     ff 6/subop/push *(ebp+8)
+ 44     # . . call
+ 45     e8/call kernel-string-equal?/disp32
+ 46     # . . discard args
+ 47     81 0/subop/add %esp 8/imm32
+ 48     # . if (eax == 0) goto run-main
+ 49     3d/compare-eax-and 0/imm32
+ 50     74/jump-if-equal $run-main/disp8
+ 51     # run-tests()
+ 52     e8/call run-tests/disp32
+ 53     # syscall(exit, *Num-test-failures)
+ 54     8b/-> *Num-test-failures 3/r32/ebx
+ 55     eb/jump $main:end/disp8
+ 56 $run-main:
+ 57     # - otherwise return factorial(5)
+ 58     # eax = factorial(5)
+ 59     # . . push args
+ 60     68/push 5/imm32
+ 61     # . . call
+ 62     e8/call factorial/disp32
+ 63     # . . discard args
+ 64     81 0/subop/add %esp 4/imm32
+ 65     # syscall(exit, eax)
+ 66     89/<- %ebx 0/r32/eax
+ 67 $main:end:
+ 68     b8/copy-to-eax 1/imm32/exit
+ 69     cd/syscall 0x80/imm8
+ 70 
+ 71 factorial:  # n : int -> int/eax
+ 72     # . prologue
+ 73     55/push-ebp
+ 74     89/<- %ebp 4/r32/esp
+ 75     53/push-ebx
+ 76     # if (n <= 1) return 1
+ 77     b8/copy-to-eax 1/imm32
+ 78     81 7/subop/compare *(ebp+8) 1/imm32
+ 79     7e/jump-if-<= $factorial:end/disp8
+ 80     # ebx = n-1
+ 81     8b/-> *(ebp+8) 3/r32/ebx
+ 82     4b/decrement-ebx
+ 83     # eax = factorial(n-1)
+ 84     # . . push args
+ 85     53/push-ebx
+ 86     # . . call
+ 87     e8/call factorial/disp32
+ 88     # . . discard args
+ 89     81 0/subop/add %esp 4/imm32
+ 90     # return n * factorial(n-1)
+ 91     f7 4/subop/multiply-into-eax *(ebp+8)
+ 92     # TODO: check for overflow
+ 93 $factorial:end:
+ 94     # . epilogue
+ 95     5b/pop-to-ebx
+ 96     89/<- %esp 5/r32/ebp
+ 97     5d/pop-to-ebp
+ 98     c3/return
+ 99 
+100 test-factorial:
+101     # factorial(5)
+102     # . . push args
+103     68/push 5/imm32
+104     # . . call
+105     e8/call factorial/disp32
+106     # . . discard args
+107     81 0/subop/add %esp 4/imm32
+108     # check-ints-equal(eax, 120, msg)
+109     # . . push args
+110     68/push "F - test-factorial"/imm32
+111     68/push 0x78/imm32/expected-120
+112     50/push-eax
+113     # . . call
+114     e8/call check-ints-equal/disp32
+115     # . . discard args
+116     81 0/subop/add %esp 0xc/imm32
+117     # end
+118     c3/return
 
diff --git a/html/apps/factorial3.subx.html b/html/apps/factorial3.subx.html index 1a9566d5..7080e5cb 100644 --- a/html/apps/factorial3.subx.html +++ b/html/apps/factorial3.subx.html @@ -59,81 +59,85 @@ if ('onhashchange' in window) {
  1 ## compute the factorial of 5, and return the result in the exit code
  2 #
- 3 # To run:
- 4 #   $ ./ntranslate init.linux 0*.subx apps/factorial.subx -o apps/factorial
- 5 #   $ ./subx run apps/factorial
- 6 # Expected result:
- 7 #   $ echo $?
- 8 #   120
- 9 #
-10 # You can also run the automated test suite:
-11 #   $ ./subx run apps/factorial test
-12 # Expected output:
-13 #   ........
-14 # Every '.' indicates a passing test. Failing tests get a 'F'.
-15 
-16 == code
-17 
-18 Entry:  # run tests if necessary, compute `factorial(5)` if not
-19     # . prologue
-20     89/<- %ebp 4/r32/esp
+ 3 # Uses syntax sugar for:
+ 4 #   rm32 operands
+ 5 #   function calls
+ 6 #
+ 7 # To run:
+ 8 #   $ ./ntranslate init.linux 0*.subx apps/factorial.subx -o apps/factorial
+ 9 #   $ ./subx run apps/factorial
+10 # Expected result:
+11 #   $ echo $?
+12 #   120
+13 #
+14 # You can also run the automated test suite:
+15 #   $ ./subx run apps/factorial test
+16 # Expected output:
+17 #   ........
+18 # Every '.' indicates a passing test. Failing tests get a 'F'.
+19 
+20 == code
 21 
-22     # initialize heap
-23     (new-segment Heap-size Heap)
-24 
-25     # - if argc > 1 and argv[1] == "test", then return run_tests()
-26     # if (argc <= 1) goto run-main
-27     81 7/subop/compare *ebp 1/imm32
-28     7e/jump-if-lesser-or-equal $run-main/disp8
-29     # if (!kernel-string-equal?(argv[1], "test")) goto run-main
-30     (kernel-string-equal? *(ebp+8) "test")  # => eax
-31     # . if (eax == 0) goto run-main
-32     3d/compare-eax-and 0/imm32
-33     74/jump-if-equal $run-main/disp8
-34     #
-35     (run-tests)
-36     # syscall(exit, *Num-test-failures)
-37     8b/-> *Num-test-failures 3/r32/ebx
-38     eb/jump $main:end/disp8
-39 $run-main:
-40     # - otherwise
-41     (factorial 5)  # => eax
-42     # syscall(exit, eax)
-43     89/<- %ebx 0/r32/eax
-44 $main:end:
-45     b8/copy-to-eax 1/imm32/exit
-46     cd/syscall 0x80/imm8
-47 
-48 factorial:  # n : int -> int/eax
-49     # . prologue
-50     55/push-ebp
-51     89/<- %ebp 4/r32/esp
-52     # save registers
-53     53/push-ebx
-54     # if (n <= 1) return 1
-55     b8/copy-to-eax 1/imm32
-56     81 7/subop/compare *(ebp+8) 1/imm32
-57     7e/jump-if-<= $factorial:end/disp8
-58     # ebx = n-1
-59     8b/-> *(ebp+8) 3/r32/ebx
-60     4b/decrement-ebx
-61     #
-62     (factorial %ebx)  # => eax
-63     # return n * factorial(n-1)
-64     f7 4/subop/multiply-into-eax *(ebp+8)
-65     # TODO: check for overflow
-66 $factorial:end:
-67     # restore registers
-68     5b/pop-to-ebx
-69     # . epilogue
-70     89/<- %esp 5/r32/ebp
-71     5d/pop-to-ebp
-72     c3/return
-73 
-74 test-factorial:
-75     (factorial 5)
-76     (check-ints-equal %eax 0x78 "F - test-factorial")
-77     c3/return
+22 Entry:  # run tests if necessary, compute `factorial(5)` if not
+23     # . prologue
+24     89/<- %ebp 4/r32/esp
+25 
+26     # initialize heap
+27     (new-segment Heap-size Heap)
+28 
+29     # - if argc > 1 and argv[1] == "test", then return run_tests()
+30     # if (argc <= 1) goto run-main
+31     81 7/subop/compare *ebp 1/imm32
+32     7e/jump-if-lesser-or-equal $run-main/disp8
+33     # if (!kernel-string-equal?(argv[1], "test")) goto run-main
+34     (kernel-string-equal? *(ebp+8) "test")  # => eax
+35     # . if (eax == 0) goto run-main
+36     3d/compare-eax-and 0/imm32
+37     74/jump-if-equal $run-main/disp8
+38     #
+39     (run-tests)
+40     # syscall(exit, *Num-test-failures)
+41     8b/-> *Num-test-failures 3/r32/ebx
+42     eb/jump $main:end/disp8
+43 $run-main:
+44     # - otherwise
+45     (factorial 5)  # => eax
+46     # syscall(exit, eax)
+47     89/<- %ebx 0/r32/eax
+48 $main:end:
+49     b8/copy-to-eax 1/imm32/exit
+50     cd/syscall 0x80/imm8
+51 
+52 factorial:  # n : int -> int/eax
+53     # . prologue
+54     55/push-ebp
+55     89/<- %ebp 4/r32/esp
+56     # save registers
+57     53/push-ebx
+58     # if (n <= 1) return 1
+59     b8/copy-to-eax 1/imm32
+60     81 7/subop/compare *(ebp+8) 1/imm32
+61     7e/jump-if-<= $factorial:end/disp8
+62     # ebx = n-1
+63     8b/-> *(ebp+8) 3/r32/ebx
+64     4b/decrement-ebx
+65     #
+66     (factorial %ebx)  # => eax
+67     # return n * factorial(n-1)
+68     f7 4/subop/multiply-into-eax *(ebp+8)
+69     # TODO: check for overflow
+70 $factorial:end:
+71     # restore registers
+72     5b/pop-to-ebx
+73     # . epilogue
+74     89/<- %esp 5/r32/ebp
+75     5d/pop-to-ebp
+76     c3/return
+77 
+78 test-factorial:
+79     (factorial 5)
+80     (check-ints-equal %eax 0x78 "F - test-factorial")
+81     c3/return
 
diff --git a/html/apps/factorial4.subx.html b/html/apps/factorial4.subx.html index d8cdec7d..2ebb9930 100644 --- a/html/apps/factorial4.subx.html +++ b/html/apps/factorial4.subx.html @@ -59,87 +59,92 @@ if ('onhashchange' in window) {
  1 ## compute the factorial of 5, and return the result in the exit code
  2 #
- 3 # To run:
- 4 #   $ ./ntranslate init.linux 0*.subx apps/factorial.subx -o apps/factorial
- 5 #   $ ./subx run apps/factorial
- 6 # Expected result:
- 7 #   $ echo $?
- 8 #   120
- 9 #
-10 # You can also run the automated test suite:
-11 #   $ ./subx run apps/factorial test
-12 # Expected output:
-13 #   ........
-14 # Every '.' indicates a passing test. Failing tests get a 'F'.
-15 
-16 == code
-17 
-18 Entry:  # run tests if necessary, compute `factorial(5)` if not
-19     # . prologue
-20     89/<- %ebp 4/r32/esp
-21 
-22     # initialize heap
-23     (new-segment 0x10000 Heap)
-24 
-25     # - if argc > 1, then return run_tests()
-26     {
-27       # if (argc <= 1) break
-28       81 7/subop/compare *ebp 1/imm32
-29       7e/jump-if-lesser-or-equal break/disp8
-30       # if (!kernel-string-equal?(argv[1], "test")) break
-31       (kernel-string-equal? *(ebp+8) "test")  # => eax
-32       3d/compare-eax-and 0/imm32
-33       74/jump-if-equal break/disp8
-34       #
-35       (run-tests)
-36       # eax = *Num-test-failures
-37       8b/-> *Num-test-failures 3/r32/ebx
-38     }
-39     # if (argc <= 1) factorial(5)
-40     {
-41       # if (argc > 1) break
-42       81 7/subop/compare *ebp 1/imm32
-43       7f/jump-if-greater break/disp8
-44       # eax = factorial(5)
-45       (factorial 5)
-46       # syscall(exit, eax)
-47       89/<- %ebx 0/r32/eax
-48     }
-49 
-50     b8/copy-to-eax 1/imm32/exit
-51     cd/syscall 0x80/imm8
-52 
-53 factorial:  # n : int -> int/eax
-54     # . prologue
-55     55/push-ebp
-56     89/<- %ebp 4/r32/esp
-57     # save registers
-58     53/push-ebx
-59     # if (n <= 1) return 1
-60     81 7/subop/compare *(ebp+8) 1/imm32
-61     {
-62       7f/jump-if-greater break/disp8
-63       b8/copy-to-eax 1/imm32
-64     }
-65     # if (n > 1) return n * factorial(n-1)
+ 3 # Uses syntax sugar for:
+ 4 #   rm32 operands
+ 5 #   function calls
+ 6 #   control flow
+ 7 #
+ 8 # To run:
+ 9 #   $ ./ntranslate init.linux 0*.subx apps/factorial.subx -o apps/factorial
+10 #   $ ./subx run apps/factorial
+11 # Expected result:
+12 #   $ echo $?
+13 #   120
+14 #
+15 # You can also run the automated test suite:
+16 #   $ ./subx run apps/factorial test
+17 # Expected output:
+18 #   ........
+19 # Every '.' indicates a passing test. Failing tests get a 'F'.
+20 
+21 == code
+22 
+23 Entry:  # run tests if necessary, compute `factorial(5)` if not
+24     # . prologue
+25     89/<- %ebp 4/r32/esp
+26 
+27     # initialize heap
+28     (new-segment 0x10000 Heap)
+29 
+30     # - if argc > 1, then return run_tests()
+31     {
+32       # if (argc <= 1) break
+33       81 7/subop/compare *ebp 1/imm32
+34       7e/jump-if-lesser-or-equal break/disp8
+35       # if (!kernel-string-equal?(argv[1], "test")) break
+36       (kernel-string-equal? *(ebp+8) "test")  # => eax
+37       3d/compare-eax-and 0/imm32
+38       74/jump-if-equal break/disp8
+39       #
+40       (run-tests)
+41       # eax = *Num-test-failures
+42       8b/-> *Num-test-failures 3/r32/ebx
+43     }
+44     # if (argc <= 1) factorial(5)
+45     {
+46       # if (argc > 1) break
+47       81 7/subop/compare *ebp 1/imm32
+48       7f/jump-if-greater break/disp8
+49       # eax = factorial(5)
+50       (factorial 5)
+51       # syscall(exit, eax)
+52       89/<- %ebx 0/r32/eax
+53     }
+54 
+55     b8/copy-to-eax 1/imm32/exit
+56     cd/syscall 0x80/imm8
+57 
+58 factorial:  # n : int -> int/eax
+59     # . prologue
+60     55/push-ebp
+61     89/<- %ebp 4/r32/esp
+62     # save registers
+63     53/push-ebx
+64     # if (n <= 1) return 1
+65     81 7/subop/compare *(ebp+8) 1/imm32
 66     {
-67       7e/jump-if-lesser-or-equal break/disp8
-68       8b/-> *(ebp+8) 3/r32/ebx
-69       4b/decrement-ebx
-70       (factorial %ebx)  # => eax
-71       f7 4/subop/multiply-into-eax *(ebp+8)
-72     }
-73     # restore registers
-74     5b/pop-to-ebx
-75     # . epilogue
-76     89/<- %esp 5/r32/ebp
-77     5d/pop-to-ebp
-78     c3/return
-79 
-80 test-factorial:
-81     (factorial 5)
-82     (check-ints-equal %eax 0x78 "F - test-factorial")
+67       7f/jump-if-greater break/disp8
+68       b8/copy-to-eax 1/imm32
+69     }
+70     # if (n > 1) return n * factorial(n-1)
+71     {
+72       7e/jump-if-lesser-or-equal break/disp8
+73       8b/-> *(ebp+8) 3/r32/ebx
+74       4b/decrement-ebx
+75       (factorial %ebx)  # => eax
+76       f7 4/subop/multiply-into-eax *(ebp+8)
+77     }
+78     # restore registers
+79     5b/pop-to-ebx
+80     # . epilogue
+81     89/<- %esp 5/r32/ebp
+82     5d/pop-to-ebp
 83     c3/return
+84 
+85 test-factorial:
+86     (factorial 5)
+87     (check-ints-equal %eax 0x78 "F - test-factorial")
+88     c3/return
 
-- cgit 1.4.1-2-gfad0