From 604c8315bd7251daa898dd646cb8595f3700ed21 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 1 Sep 2019 23:57:29 -0700 Subject: 5607 --- apps/assort.subx | 6 +- apps/crenshaw2-1.subx | 6 +- apps/crenshaw2-1b.subx | 6 +- apps/dquotes.subx | 6 +- apps/factorial.subx | 3 +- apps/hex.subx | 6 +- apps/pack.subx | 6 +- apps/sigils.subx | 4 +- apps/survey.subx | 4 +- apps/tests.subx | 4 +- html/apps/assort.subx.html | 6 +- html/apps/crenshaw2-1.subx.html | 6 +- html/apps/crenshaw2-1b.subx.html | 6 +- html/apps/dquotes.subx.html | 6 +- html/apps/factorial.subx.html | 127 ++++++++++++++++++++------------------- html/apps/hex.subx.html | 6 +- html/apps/pack.subx.html | 6 +- html/apps/sigils.subx.html | 4 +- html/apps/survey.subx.html | 4 +- html/apps/tests.subx.html | 4 +- 20 files changed, 114 insertions(+), 112 deletions(-) diff --git a/apps/assort.subx b/apps/assort.subx index f1d76df6..57ed1eb2 100644 --- a/apps/assort.subx +++ b/apps/assort.subx @@ -55,7 +55,7 @@ Entry: # run tests if necessary, convert stdin if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: @@ -66,7 +66,7 @@ $run-main: # configure ed to really exit() # . ed->target = 0 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - # return convert(Stdin, Stdout, Stderr, ed) + # convert(Stdin, Stdout, Stderr, ed) # . . push args 50/push-eax/ed 68/push Stderr/imm32 @@ -76,7 +76,7 @@ $run-main: e8/call convert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - # . syscall(exit, 0) + # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $main:end: b8/copy-to-eax 1/imm32/exit diff --git a/apps/crenshaw2-1.subx b/apps/crenshaw2-1.subx index e4e78e9c..5d1c9c0c 100644 --- a/apps/crenshaw2-1.subx +++ b/apps/crenshaw2-1.subx @@ -62,7 +62,7 @@ Entry: # run tests if necessary, call 'compile' if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: @@ -73,7 +73,7 @@ $run-main: # configure ed to really exit() # . ed->target = 0 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - # return compile(Stdin, 1/stdout, 2/stderr, ed) + # compile(Stdin, 1/stdout, 2/stderr, ed) # . . push args 50/push-eax/ed 68/push 2/imm32/stderr @@ -83,7 +83,7 @@ $run-main: e8/call compile/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - # . syscall(exit, 0) + # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $main:end: b8/copy-to-eax 1/imm32/exit diff --git a/apps/crenshaw2-1b.subx b/apps/crenshaw2-1b.subx index cbd18d46..908ca942 100644 --- a/apps/crenshaw2-1b.subx +++ b/apps/crenshaw2-1b.subx @@ -62,7 +62,7 @@ Entry: # run tests if necessary, call 'compile' if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: @@ -73,7 +73,7 @@ $run-main: # configure ed to really exit() # . ed->target = 0 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - # return compile(Stdin, 1/stdout, 2/stderr, ed) + # compile(Stdin, 1/stdout, 2/stderr, ed) # . . push args 50/push-eax/ed 68/push 2/imm32/stderr @@ -83,7 +83,7 @@ $run-main: e8/call compile/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - # . syscall(exit, 0) + # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $main:end: b8/copy-to-eax 1/imm32/exit diff --git a/apps/dquotes.subx b/apps/dquotes.subx index 95d3bc15..b22758de 100644 --- a/apps/dquotes.subx +++ b/apps/dquotes.subx @@ -51,7 +51,7 @@ Entry: # run tests if necessary, convert stdin if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: @@ -62,7 +62,7 @@ $run-main: # configure ed to really exit() # . ed->target = 0 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - # return convert(Stdin, 1/stdout, 2/stderr, ed) + # convert(Stdin, 1/stdout, 2/stderr, ed) # . . push args 50/push-eax/ed 68/push Stderr/imm32 @@ -72,7 +72,7 @@ $run-main: e8/call convert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - # . syscall(exit, 0) + # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $main:end: b8/copy-to-eax 1/imm32/exit diff --git a/apps/factorial.subx b/apps/factorial.subx index 1fb111d0..23cb8294 100644 --- a/apps/factorial.subx +++ b/apps/factorial.subx @@ -50,11 +50,12 @@ Entry: # run tests if necessary, compute `factorial(5)` if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: # - otherwise return factorial(5) + # eax = factorial(5) # . . push args 68/push 5/imm32 # . . call diff --git a/apps/hex.subx b/apps/hex.subx index a28d9461..57b112ab 100644 --- a/apps/hex.subx +++ b/apps/hex.subx @@ -49,7 +49,7 @@ Entry: # run tests if necessary, convert stdin if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: @@ -60,7 +60,7 @@ $run-main: # configure ed to really exit() # . ed->target = 0 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - # return convert(Stdin, 1/stdout, 2/stderr, ed) + # convert(Stdin, 1/stdout, 2/stderr, ed) # . . push args 50/push-eax/ed 68/push Stderr/imm32 @@ -70,7 +70,7 @@ $run-main: e8/call convert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - # . syscall(exit, 0) + # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $main:end: b8/copy-to-eax 1/imm32/exit diff --git a/apps/pack.subx b/apps/pack.subx index fe695c4f..36896669 100644 --- a/apps/pack.subx +++ b/apps/pack.subx @@ -50,7 +50,7 @@ Entry: # run tests if necessary, convert stdin if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: @@ -61,7 +61,7 @@ $run-main: # configure ed to really exit() # . ed->target = 0 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - # return convert(Stdin, Stdout, Stderr, ed) + # convert(Stdin, Stdout, Stderr, ed) # . . push args 50/push-eax/ed 68/push Stderr/imm32 @@ -71,7 +71,7 @@ $run-main: e8/call convert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - # . syscall(exit, 0) + # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $main:end: b8/copy-to-eax 1/imm32/exit diff --git a/apps/sigils.subx b/apps/sigils.subx index 35ebf6cd..2e1daa4a 100644 --- a/apps/sigils.subx +++ b/apps/sigils.subx @@ -83,7 +83,7 @@ Entry: # run tests if necessary, convert stdin if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: @@ -96,7 +96,7 @@ $run-main: e8/call convert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # . syscall(exit, 0) + # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $main:end: b8/copy-to-eax 1/imm32/exit diff --git a/apps/survey.subx b/apps/survey.subx index e19befc2..2738da38 100644 --- a/apps/survey.subx +++ b/apps/survey.subx @@ -79,7 +79,7 @@ Entry: # run tests if necessary, convert stdin if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: @@ -100,7 +100,7 @@ $run-main: #? e8/call write-stream/disp32 #? # . . discard args #? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # . syscall(exit, 0) + # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $main:end: b8/copy-to-eax 1/imm32/exit diff --git a/apps/tests.subx b/apps/tests.subx index 8f825a3a..92447067 100644 --- a/apps/tests.subx +++ b/apps/tests.subx @@ -48,7 +48,7 @@ Entry: # run tests if necessary, convert stdin if not 74/jump-if-equal $run-main/disp8 # run-tests() e8/call run-tests/disp32 - # return *Num-test-failures + # syscall(exit, *Num-test-failures) 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx eb/jump $main:end/disp8 $run-main: @@ -61,7 +61,7 @@ $run-main: e8/call convert/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - # . syscall(exit, 0) + # syscall(exit, 0) bb/copy-to-ebx 0/imm32 $main:end: b8/copy-to-eax 1/imm32/exit diff --git a/html/apps/assort.subx.html b/html/apps/assort.subx.html index 3e4cc6f7..80e53122 100644 --- a/html/apps/assort.subx.html +++ b/html/apps/assort.subx.html @@ -117,7 +117,7 @@ if ('onhashchange' in window) { 55 74/jump-if-equal $run-main/disp8 56 # run-tests() 57 e8/call run-tests/disp32 - 58 # return *Num-test-failures + 58 # syscall(exit, *Num-test-failures) 59 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 60 eb/jump $main:end/disp8 61 $run-main: @@ -128,7 +128,7 @@ if ('onhashchange' in window) { 66 # configure ed to really exit() 67 # . ed->target = 0 68 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - 69 # return convert(Stdin, Stdout, Stderr, ed) + 69 # convert(Stdin, Stdout, Stderr, ed) 70 # . . push args 71 50/push-eax/ed 72 68/push Stderr/imm32 @@ -138,7 +138,7 @@ if ('onhashchange' in window) { 76 e8/call convert/disp32 77 # . . discard args 78 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - 79 # . syscall(exit, 0) + 79 # syscall(exit, 0) 80 bb/copy-to-ebx 0/imm32 81 $main:end: 82 b8/copy-to-eax 1/imm32/exit diff --git a/html/apps/crenshaw2-1.subx.html b/html/apps/crenshaw2-1.subx.html index dd730bae..088f2973 100644 --- a/html/apps/crenshaw2-1.subx.html +++ b/html/apps/crenshaw2-1.subx.html @@ -123,7 +123,7 @@ if ('onhashchange' in window) { 62 74/jump-if-equal $run-main/disp8 63 # run-tests() 64 e8/call run-tests/disp32 - 65 # return *Num-test-failures + 65 # syscall(exit, *Num-test-failures) 66 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 67 eb/jump $main:end/disp8 68 $run-main: @@ -134,7 +134,7 @@ if ('onhashchange' in window) { 73 # configure ed to really exit() 74 # . ed->target = 0 75 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - 76 # return compile(Stdin, 1/stdout, 2/stderr, ed) + 76 # compile(Stdin, 1/stdout, 2/stderr, ed) 77 # . . push args 78 50/push-eax/ed 79 68/push 2/imm32/stderr @@ -144,7 +144,7 @@ if ('onhashchange' in window) { 83 e8/call compile/disp32 84 # . . discard args 85 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - 86 # . syscall(exit, 0) + 86 # syscall(exit, 0) 87 bb/copy-to-ebx 0/imm32 88 $main:end: 89 b8/copy-to-eax 1/imm32/exit diff --git a/html/apps/crenshaw2-1b.subx.html b/html/apps/crenshaw2-1b.subx.html index 7088439a..4918134a 100644 --- a/html/apps/crenshaw2-1b.subx.html +++ b/html/apps/crenshaw2-1b.subx.html @@ -123,7 +123,7 @@ if ('onhashchange' in window) { 62 74/jump-if-equal $run-main/disp8 63 # run-tests() 64 e8/call run-tests/disp32 - 65 # return *Num-test-failures + 65 # syscall(exit, *Num-test-failures) 66 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 67 eb/jump $main:end/disp8 68 $run-main: @@ -134,7 +134,7 @@ if ('onhashchange' in window) { 73 # configure ed to really exit() 74 # . ed->target = 0 75 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - 76 # return compile(Stdin, 1/stdout, 2/stderr, ed) + 76 # compile(Stdin, 1/stdout, 2/stderr, ed) 77 # . . push args 78 50/push-eax/ed 79 68/push 2/imm32/stderr @@ -144,7 +144,7 @@ if ('onhashchange' in window) { 83 e8/call compile/disp32 84 # . . discard args 85 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - 86 # . syscall(exit, 0) + 86 # syscall(exit, 0) 87 bb/copy-to-ebx 0/imm32 88 $main:end: 89 b8/copy-to-eax 1/imm32/exit diff --git a/html/apps/dquotes.subx.html b/html/apps/dquotes.subx.html index b74502a2..34dbe1ff 100644 --- a/html/apps/dquotes.subx.html +++ b/html/apps/dquotes.subx.html @@ -114,7 +114,7 @@ if ('onhashchange' in window) { 51 74/jump-if-equal $run-main/disp8 52 # run-tests() 53 e8/call run-tests/disp32 - 54 # return *Num-test-failures + 54 # syscall(exit, *Num-test-failures) 55 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 56 eb/jump $main:end/disp8 57 $run-main: @@ -125,7 +125,7 @@ if ('onhashchange' in window) { 62 # configure ed to really exit() 63 # . ed->target = 0 64 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - 65 # return convert(Stdin, 1/stdout, 2/stderr, ed) + 65 # convert(Stdin, 1/stdout, 2/stderr, ed) 66 # . . push args 67 50/push-eax/ed 68 68/push Stderr/imm32 @@ -135,7 +135,7 @@ if ('onhashchange' in window) { 72 e8/call convert/disp32 73 # . . discard args 74 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - 75 # . syscall(exit, 0) + 75 # syscall(exit, 0) 76 bb/copy-to-ebx 0/imm32 77 $main:end: 78 b8/copy-to-eax 1/imm32/exit diff --git a/html/apps/factorial.subx.html b/html/apps/factorial.subx.html index e2154a6a..1c8d35b7 100644 --- a/html/apps/factorial.subx.html +++ b/html/apps/factorial.subx.html @@ -111,73 +111,74 @@ if ('onhashchange' in window) { 50 74/jump-if-equal $run-main/disp8 51 # run-tests() 52 e8/call run-tests/disp32 - 53 # return *Num-test-failures + 53 # syscall(exit, *Num-test-failures) 54 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 55 eb/jump $main:end/disp8 56 $run-main: 57 # - otherwise return factorial(5) - 58 # . . push args - 59 68/push 5/imm32 - 60 # . . call - 61 e8/call factorial/disp32 - 62 # . . discard args - 63 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp - 64 # syscall(exit, eax) - 65 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . . # copy eax to ebx - 66 $main:end: - 67 b8/copy-to-eax 1/imm32/exit - 68 cd/syscall 0x80/imm8 - 69 - 70 factorial: # n : int -> int/eax - 71 # . prolog - 72 55/push-ebp - 73 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp - 74 53/push-ebx - 75 # if (n <= 1) return 1 - 76 b8/copy-to-eax 1/imm32 - 77 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 1/imm32 # compare *(ebp+8) - 78 7e/jump-if-<= $factorial:end/disp8 - 79 # ebx = n-1 - 80 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 3/r32/ebx 8/disp8 . # copy *(ebp+8) to ebx - 81 81 5/subop/subtract 3/mod/direct 3/rm32/ebx . . . . . 1/imm32 # subtract from ebx - 82 # eax = factorial(n-1) - 83 # . . push args - 84 53/push-ebx - 85 # . . call - 86 e8/call factorial/disp32 - 87 # . . discard args - 88 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp - 89 # return n * factorial(n-1) - 90 f7 4/subop/multiply 1/mod/*+disp8 5/rm32/ebp . . 8/disp8 . # multiply *(ebp+8) into eax - 91 # TODO: check for overflow - 92 $factorial:end: - 93 # . epilog - 94 5b/pop-to-ebx - 95 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp - 96 5d/pop-to-ebp - 97 c3/return - 98 - 99 test-factorial: -100 # factorial(5) -101 # . . push args -102 68/push 5/imm32 -103 # . . call -104 e8/call factorial/disp32 -105 # . . discard args -106 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp -107 # check-ints-equal(eax, 120, msg) -108 # . . push args -109 68/push "F - test-factorial"/imm32 -110 68/push 0x78/imm32/expected-120 -111 50/push-eax -112 # . . call -113 e8/call check-ints-equal/disp32 -114 # . . discard args -115 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp -116 # end -117 c3/return -118 -119 # . . vim:nowrap:textwidth=0 + 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 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp + 65 # syscall(exit, eax) + 66 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . . # copy eax to ebx + 67 $main:end: + 68 b8/copy-to-eax 1/imm32/exit + 69 cd/syscall 0x80/imm8 + 70 + 71 factorial: # n : int -> int/eax + 72 # . prolog + 73 55/push-ebp + 74 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp + 75 53/push-ebx + 76 # if (n <= 1) return 1 + 77 b8/copy-to-eax 1/imm32 + 78 81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 1/imm32 # compare *(ebp+8) + 79 7e/jump-if-<= $factorial:end/disp8 + 80 # ebx = n-1 + 81 8b/copy 1/mod/*+disp8 5/rm32/ebp . . 3/r32/ebx 8/disp8 . # copy *(ebp+8) to ebx + 82 81 5/subop/subtract 3/mod/direct 3/rm32/ebx . . . . . 1/imm32 # subtract from 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 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp + 90 # return n * factorial(n-1) + 91 f7 4/subop/multiply 1/mod/*+disp8 5/rm32/ebp . . 8/disp8 . # multiply *(ebp+8) into eax + 92 # TODO: check for overflow + 93 $factorial:end: + 94 # . epilog + 95 5b/pop-to-ebx + 96 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 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 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp +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 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp +117 # end +118 c3/return +119 +120 # . . vim:nowrap:textwidth=0 diff --git a/html/apps/hex.subx.html b/html/apps/hex.subx.html index 6478a270..d8a455e4 100644 --- a/html/apps/hex.subx.html +++ b/html/apps/hex.subx.html @@ -110,7 +110,7 @@ if ('onhashchange' in window) { 49 74/jump-if-equal $run-main/disp8 50 # run-tests() 51 e8/call run-tests/disp32 - 52 # return *Num-test-failures + 52 # syscall(exit, *Num-test-failures) 53 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 54 eb/jump $main:end/disp8 55 $run-main: @@ -121,7 +121,7 @@ if ('onhashchange' in window) { 60 # configure ed to really exit() 61 # . ed->target = 0 62 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - 63 # return convert(Stdin, 1/stdout, 2/stderr, ed) + 63 # convert(Stdin, 1/stdout, 2/stderr, ed) 64 # . . push args 65 50/push-eax/ed 66 68/push Stderr/imm32 @@ -131,7 +131,7 @@ if ('onhashchange' in window) { 70 e8/call convert/disp32 71 # . . discard args 72 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - 73 # . syscall(exit, 0) + 73 # syscall(exit, 0) 74 bb/copy-to-ebx 0/imm32 75 $main:end: 76 b8/copy-to-eax 1/imm32/exit diff --git a/html/apps/pack.subx.html b/html/apps/pack.subx.html index 0c74da8e..f8caafb6 100644 --- a/html/apps/pack.subx.html +++ b/html/apps/pack.subx.html @@ -112,7 +112,7 @@ if ('onhashchange' in window) { 50 74/jump-if-equal $run-main/disp8 51 # run-tests() 52 e8/call run-tests/disp32 - 53 # return *Num-test-failures + 53 # syscall(exit, *Num-test-failures) 54 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 55 eb/jump $main:end/disp8 56 $run-main: @@ -123,7 +123,7 @@ if ('onhashchange' in window) { 61 # configure ed to really exit() 62 # . ed->target = 0 63 c7 0/subop/copy 0/mod/direct 0/rm32/eax . . . . . 0/imm32 # copy to *eax - 64 # return convert(Stdin, Stdout, Stderr, ed) + 64 # convert(Stdin, Stdout, Stderr, ed) 65 # . . push args 66 50/push-eax/ed 67 68/push Stderr/imm32 @@ -133,7 +133,7 @@ if ('onhashchange' in window) { 71 e8/call convert/disp32 72 # . . discard args 73 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp - 74 # . syscall(exit, 0) + 74 # syscall(exit, 0) 75 bb/copy-to-ebx 0/imm32 76 $main:end: 77 b8/copy-to-eax 1/imm32/exit diff --git a/html/apps/sigils.subx.html b/html/apps/sigils.subx.html index 5a61c9fc..901a7707 100644 --- a/html/apps/sigils.subx.html +++ b/html/apps/sigils.subx.html @@ -145,7 +145,7 @@ if ('onhashchange' in window) { 83 74/jump-if-equal $run-main/disp8 84 # run-tests() 85 e8/call run-tests/disp32 - 86 # return *Num-test-failures + 86 # syscall(exit, *Num-test-failures) 87 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 88 eb/jump $main:end/disp8 89 $run-main: @@ -158,7 +158,7 @@ if ('onhashchange' in window) { 96 e8/call convert/disp32 97 # . . discard args 98 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - 99 # . syscall(exit, 0) + 99 # syscall(exit, 0) 100 bb/copy-to-ebx 0/imm32 101 $main:end: 102 b8/copy-to-eax 1/imm32/exit diff --git a/html/apps/survey.subx.html b/html/apps/survey.subx.html index 09b59be7..b83ec98d 100644 --- a/html/apps/survey.subx.html +++ b/html/apps/survey.subx.html @@ -142,7 +142,7 @@ if ('onhashchange' in window) { 79 74/jump-if-equal $run-main/disp8 80 # run-tests() 81 e8/call run-tests/disp32 - 82 # return *Num-test-failures + 82 # syscall(exit, *Num-test-failures) 83 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 84 eb/jump $main:end/disp8 85 $run-main: @@ -163,7 +163,7 @@ if ('onhashchange' in window) { 100 #? e8/call write-stream/disp32 101 #? # . . discard args 102 #? 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - 103 # . syscall(exit, 0) + 103 # syscall(exit, 0) 104 bb/copy-to-ebx 0/imm32 105 $main:end: 106 b8/copy-to-eax 1/imm32/exit diff --git a/html/apps/tests.subx.html b/html/apps/tests.subx.html index c1dc59f0..16270e28 100644 --- a/html/apps/tests.subx.html +++ b/html/apps/tests.subx.html @@ -108,7 +108,7 @@ if ('onhashchange' in window) { 48 74/jump-if-equal $run-main/disp8 49 # run-tests() 50 e8/call run-tests/disp32 - 51 # return *Num-test-failures + 51 # syscall(exit, *Num-test-failures) 52 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32 # copy *Num-test-failures to ebx 53 eb/jump $main:end/disp8 54 $run-main: @@ -121,7 +121,7 @@ if ('onhashchange' in window) { 61 e8/call convert/disp32 62 # . . discard args 63 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - 64 # . syscall(exit, 0) + 64 # syscall(exit, 0) 65 bb/copy-to-ebx 0/imm32 66 $main:end: 67 b8/copy-to-eax 1/imm32/exit -- cgit 1.4.1-2-gfad0