diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-04-26 22:59:59 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-04-26 22:59:59 -0700 |
commit | c0bde5f8269b8f322742d57ec0c02cec75c8a2c7 (patch) | |
tree | f3b270575c58481ac79e050f6deed52c0407fdd4 /apps | |
parent | 144abce2309c3422238be60a2fbedb1e4454af53 (diff) | |
download | mu-c0bde5f8269b8f322742d57ec0c02cec75c8a2c7.tar.gz |
6213
Some minor tweaks while preparing presentation to Mek's Junto group.
Diffstat (limited to 'apps')
-rwxr-xr-x | apps/factorial | bin | 39303 -> 39377 bytes | |||
-rw-r--r-- | apps/factorial.subx | 34 |
2 files changed, 32 insertions, 2 deletions
diff --git a/apps/factorial b/apps/factorial index 97c62ac8..be287f31 100755 --- a/apps/factorial +++ b/apps/factorial Binary files differdiff --git a/apps/factorial.subx b/apps/factorial.subx index 651552e0..bded3a36 100644 --- a/apps/factorial.subx +++ b/apps/factorial.subx @@ -1,4 +1,4 @@ -## compute the factorial of 5, and return the result in the exit code +## compute the factorial of 5, and print the result # # To run: # $ ./bootstrap translate init.linux 0*.subx apps/factorial.subx -o apps/factorial @@ -54,7 +54,7 @@ Entry: # run tests if necessary, compute `factorial(5)` if not 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) + # - otherwise print factorial(5) # eax = factorial(5) # . . push args 68/push 5/imm32 @@ -62,6 +62,36 @@ $run-main: e8/call factorial/disp32 # . . discard args 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp + # var buffer/ecx: (stream byte 10) # number of decimal digits a 32-bit number can have + 81 5/subop/subtract 3/mod/direct 4/rm32/esp . . . . . 0xa/imm32 # subtract from esp + 68/push 0xa/imm32/decimal-digits-in-32bit-number + 68/push 0/imm32/read + 68/push 0/imm32/write + 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx + # print-int32-decimal(buffer, eax) + # . . push args + 50/push-eax + 51/push-ecx + # . . call + e8/call print-int32-decimal/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # write-stream(stderr, buffer) + # . . push args + 51/push-ecx + 68/push 2/imm32/stderr + # . . call + e8/call write-stream/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + # write(stderr, Newline) + # . . push args + 68/push Newline/imm32 + 68/push 2/imm32/stderr + # . . call + e8/call write/disp32 + # . . discard args + 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp # syscall(exit, eax) 89/copy 3/mod/direct 3/rm32/ebx . . . 0/r32/eax . . # copy eax to ebx $main:end: |