From 3d1c4216ede8c628558c9fe700fb2be1aa08b473 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 2 Nov 2020 21:24:53 -0800 Subject: 7162 --- html/apps/factorial4.subx.html | 105 ++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 53 deletions(-) (limited to 'html/apps/factorial4.subx.html') diff --git a/html/apps/factorial4.subx.html b/html/apps/factorial4.subx.html index 7c770ea7..ac994117 100644 --- a/html/apps/factorial4.subx.html +++ b/html/apps/factorial4.subx.html @@ -80,7 +80,7 @@ if ('onhashchange' in window) { 22 23 == code 24 -25 factorial: # n: int -> int/eax +25 factorial: # n: int -> _/eax: int 26 # . prologue 27 55/push-ebp 28 89/<- %ebp 4/r32/esp @@ -91,60 +91,59 @@ if ('onhashchange' in window) { 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 -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 +36 eb/jump $factorial:end/disp8 +37 } +38 # n > 1; return n * factorial(n-1) +39 8b/-> *(ebp+8) 1/r32/ecx +40 49/decrement-ecx +41 (factorial %ecx) # => eax +42 f7 4/subop/multiply-into-eax *(ebp+8) +43 # TODO: check for overflow +44 $factorial:end: +45 # restore registers +46 59/pop-to-ecx +47 # . epilogue +48 89/<- %esp 5/r32/ebp +49 5d/pop-to-ebp +50 c3/return +51 +52 test-factorial: +53 (factorial 5) +54 (check-ints-equal %eax 0x78 "F - test-factorial") +55 c3/return +56 +57 Entry: # run tests if necessary, compute `factorial(5)` if not +58 # . prologue +59 89/<- %ebp 4/r32/esp +60 +61 # initialize heap (needed by tests elsewhere) +62 (new-segment *Heap-size Heap) +63 +64 # if (argc <= 1) return factorial(5) +65 { +66 # if (argc > 1) break +67 81 7/subop/compare *ebp 1/imm32 +68 7f/jump-if-> break/disp8 +69 # ebx = factorial(5) +70 (factorial 5) # => eax +71 89/<- %ebx 0/r32/eax +72 eb/jump $main:end/disp8 73 } -74 # otherwise if an arg exists and is "test", then return run_tests() +74 # otherwise if first arg 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 +76 # if (!kernel-string-equal?(argv[1], "test")) break +77 (kernel-string-equal? *(ebp+8) "test") # => eax +78 3d/compare-eax-and 0/imm32/false +79 74/jump-if-= break/disp8 +80 # +81 (run-tests) +82 # exit(*Num-test-failures) +83 8b/-> *Num-test-failures 3/r32/ebx +84 eb/jump $main:end/disp8 +85 } +86 bb/copy-to-ebx 0/imm32 +87 $main:end: +88 e8/call syscall_exit/disp32 -- cgit 1.4.1-2-gfad0