From 480fd9958abbd9b3b8443190ece755504cacdf9c Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Wed, 14 Oct 2020 13:42:03 -0700 Subject: 7032 --- html/apps/factorial4.subx.html | 140 ++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 70 deletions(-) (limited to 'html/apps/factorial4.subx.html') diff --git a/html/apps/factorial4.subx.html b/html/apps/factorial4.subx.html index b40586bf..7c770ea7 100644 --- a/html/apps/factorial4.subx.html +++ b/html/apps/factorial4.subx.html @@ -15,13 +15,12 @@ body { font-size:12pt; font-family: monospace; color: #000000; background-color: a { color:inherit; } * { font-size:12pt; font-size: 1em; } .subxComment { color: #005faf; } -.subxFunction { color: #af5f00; text-decoration: underline; } +.SpecialChar { color: #d70000; } .LineNr { } .subxTest { color: #5f8700; } .subxS1Comment { color: #0000af; } -.SpecialChar { color: #d70000; } +.subxFunction { color: #af5f00; text-decoration: underline; } .Constant { color: #008787; } -.subxH1Comment { color: #005faf; text-decoration: underline; } --> @@ -76,75 +75,76 @@ if ('onhashchange' in window) { 17 # Expected output: 18 # ........ 19 # Every '.' indicates a passing test. Failing tests get a 'F'. -20 -21 == code +20 # +21 # Compare apps/factorial3.subx 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 *Heap-size 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-<= 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/false -38 74/jump-if-= 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-> break/disp8 -49 # eax = factorial(5) -50 (factorial 5) -51 # syscall(exit, eax) -52 89/<- %ebx 0/r32/eax -53 } -54 -55 e8/call syscall_exit/disp32 -56 -57 factorial: # n: int -> int/eax -58 # . prologue -59 55/push-ebp +23 == code +24 +25 factorial: # n: int -> int/eax +26 # . prologue +27 55/push-ebp +28 89/<- %ebp 4/r32/esp +29 # save registers +30 51/push-ecx +31 # if (n <= 1) return 1 +32 81 7/subop/compare *(ebp+8) 1/imm32 +33 { +34 7f/jump-if-> break/disp8 +35 b8/copy-to-eax 1/imm32 +36 } +37 # if (n > 1) return n * factorial(n-1) +38 { +39 7e/jump-if-<= break/disp8 +40 # var tmp/ecx: int = n-1 +41 8b/-> *(ebp+8) 1/r32/ecx +42 49/decrement-ecx +43 (factorial %ecx) # => eax +44 f7 4/subop/multiply-into-eax *(ebp+8) +45 } +46 # restore registers +47 59/pop-to-ecx +48 # . epilogue +49 89/<- %esp 5/r32/ebp +50 5d/pop-to-ebp +51 c3/return +52 +53 test-factorial: +54 (factorial 5) +55 (check-ints-equal %eax 0x78 "F - test-factorial") +56 c3/return +57 +58 Entry: # run tests if necessary, compute `factorial(5)` if not +59 # . prologue 60 89/<- %ebp 4/r32/esp -61 # save registers -62 51/push-ecx -63 # if (n <= 1) return 1 -64 81 7/subop/compare *(ebp+8) 1/imm32 -65 { -66 7f/jump-if-> break/disp8 -67 b8/copy-to-eax 1/imm32 -68 } -69 # if (n > 1) return n * factorial(n-1) -70 { -71 7e/jump-if-<= break/disp8 -72 # var tmp/ecx: int = n-1 -73 8b/-> *(ebp+8) 1/r32/ecx -74 49/decrement-ecx -75 (factorial %ecx) # => eax -76 f7 4/subop/multiply-into-eax *(ebp+8) -77 } -78 # restore registers -79 59/pop-to-ecx -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 +61 +62 # initialize heap (needed by tests elsewhere) +63 (new-segment *Heap-size Heap) +64 +65 # if (argc <= 1) return factorial(5) +66 { +67 # if (argc > 1) break +68 81 7/subop/compare *ebp 1/imm32 +69 7f/jump-if-> break/disp8 +70 # ebx = factorial(5) +71 (factorial 5) # => eax +72 89/<- %ebx 0/r32/eax +73 } +74 # otherwise if an arg exists and is "test", then return run_tests() +75 { +76 # if (argc <= 1) break +77 81 7/subop/compare *ebp 1/imm32 +78 7e/jump-if-<= break/disp8 +79 # if (!kernel-string-equal?(argv[1], "test")) break +80 (kernel-string-equal? *(ebp+8) "test") # => eax +81 3d/compare-eax-and 0/imm32/false +82 74/jump-if-= break/disp8 +83 # +84 (run-tests) +85 # ebx = *Num-test-failures +86 8b/-> *Num-test-failures 3/r32/ebx +87 } +88 +89 e8/call syscall_exit/disp32 -- cgit 1.4.1-2-gfad0