From cb2bc1309f40370e1ac00d9eb2a6025d5977bdd7 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Sat, 23 Dec 2017 17:17:24 -0500 Subject: [PATCH] Trimmed down hex0 and improved its performance --- CHANGELOG.org | 2 + bootstrapping Steps.org | 2 +- stage1/stage1_assembler-0.hex0 | 81 +++++++++++++++------------------- stage1/stage1_assembler-0.s | 52 +++++++++------------- test/SHA256SUMS | 2 +- 5 files changed, 61 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index ee8f43e..cd9c61d 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -22,6 +22,7 @@ Added program to search for unusual characters that are not human detectable ** Changed Expanded stage0 web IDE to include the PC and instruction counter Performance tuned hex1 to reduce both size and instruction count +Performance tuned hex0 to reduce both size and instruction count ** Fixed Fixed behavior of R@ thanks to reepca @@ -29,6 +30,7 @@ Updated changed checksums for stage2 FORTH Corrected behavior when using the web IDE and attempting to set registers that don't exist Fixed regression in hex.c caused by refactoring Fixed output of large negative numbers in hex +Updated checksums to reflect changed made in performance tuning ** Removed Removed stage1_assembler-0's need for Memory and reduced size of program while at it diff --git a/bootstrapping Steps.org b/bootstrapping Steps.org index 0be43d9..d657e34 100644 --- a/bootstrapping Steps.org +++ b/bootstrapping Steps.org @@ -60,7 +60,7 @@ or If you fail to specificy --tape_01 and/or --tape_02, this will produce tape_01 with the resulting binary and tape_02 with the source code input (this is really important for bootstrapping a text editor) -stage1_assembler-0 should have the sha256sum of 85e5c06ac07f2b97d01dfb5454f5a698b3ec6c21fe53bf3fa57b386aac7b9601 +stage1_assembler-0 should have the sha256sum of 3ea7fed1429400c1d6fc5b85180c4114755dfb1e6b88d69e7ecc465a40523bc8 * Step 2b Lets make a Line text editor Now I don't know about you but I suck at not making mistakes and having to fix a whole line instead of an entire file is a hell of an improvement. diff --git a/stage1/stage1_assembler-0.hex0 b/stage1/stage1_assembler-0.hex0 index 7549102..45e5c61 100644 --- a/stage1/stage1_assembler-0.hex0 +++ b/stage1/stage1_assembler-0.hex0 @@ -20,31 +20,32 @@ # ;; R15 is storing our nybble # ;; Prep TAPE_01 -2D201100 # LOADUI R0 0x1100 +2D201100 # LOADUI R0 0x1100 42100000 # FOPEN_READ # ;; Prep TAPE_02 2D201101 # LOADUI R0 0x1101 42100001 # FOPEN_WRITE +2D211100 # LOADUI R1 0x1100 ; Read from tape_01 + # ;; Main program loop # ;; Halts when done -#:loop 14 -2D211100 # LOADUI R1 0x1100 ; Read from tape_01 +# :loop 18 42100100 # FGETC ; Read a Char # ;; Check for EOF -2CC000b8 # JUMP.NP R0 @finish -3C000034 # JUMP @hex ; Convert it +2CC00098 # JUMP.NP R0 @finish +3C000038 # JUMP @hex ; Convert it # :loop_1 24 -2CC0fff0 # JUMP.NP R0 @loop ; Don't use nonhex chars +2CC0fff4 # JUMP.NP R0 @loop ; Don't use nonhex chars 2C9B0010 # JUMP.Z R11 @loop_2 ; Jump if toggled # ;; Process first byte of pair B0F0000f # ANDI R15 R0 0xF ; Store First nibble 0D00002B # FALSE R11 ; Flip the toggle -3C00ffe0 # JUMP @loop +3C00ffe4 # JUMP @loop # :loop_2 38 2D5F0004 # SL0I R15 4 ; Shift our first nibble @@ -53,65 +54,55 @@ B000000f # ANDI R0 R0 0xF ; Mask out top 2D1B0001 # LOADI R11 1 ; Flip the toggle 2D211101 # LOADUI R1 0x1101 ; Write the combined byte 42100200 # FPUTC ; To TAPE_02 +2D211100 # LOADUI R1 0x1100 ; Read from tape_01 3C00ffc4 # JUMP @loop ; Try to get more bytes # ;; Hex function # ;; Converts Ascii chars to their hex values # ;; Or -1 if not a hex char # ;; Returns to whatever called it -#:hex 54 +# :hex 58 # ;; Deal with line comments starting with # -1FE00023 # CMPUI R14 R0 35 -2C5E0060 # JUMP.E R14 @ascii_comment +A0300023 # CMPSKIPI.NE R0 35 +3C000044 # JUMP @ascii_comment # ;; Deal with line comments starting with ; -1FE0003b # CMPUI R14 R0 59 -2C5E0058 # JUMP.E R14 @ascii_comment +A030003b # CMPSKIPI.NE R0 59 +3C00003c # JUMP @ascii_comment # ;; Deal with all ascii less than '0' -1FE00030 # CMPUI R14 R0 48 -2C8E0048 # JUMP.L R14 @ascii_other +A0100030 # CMPSKIPI.GE R0 48 +3C000040 # JUMP @ascii_other # ;; Deal with '0'-'9' -1FE00039 # CMPUI R14 R0 57 -2C7E0028 # JUMP.LE R14 @ascii_num +A0000039 # CMPSKIPI.G R0 57 +3C00001c # JUMP @ascii_num +# ;; Unset high bit to set everything into uppercase +B00000df # ANDI R0 R0 0xDF # ;; Deal with all ascii less than 'A' -1FE00041 # CMPUI R14 R0 65 -2C8E0038 # JUMP.L R14 @ascii_other +A0100041 # CMPSKIPI.GE R0 65 +3C00002c # JUMP @ascii_other # ;; Deal with 'A'-'F' -1FE00046 # CMPUI R14 R0 70 -2C7E0028 # JUMP.LE R14 @ascii_high -# ;; Deal with all ascii less than 'a' -1FE00061 # CMPUI R14 R0 97 -2C8E0028 # JUMP.L R14 @ascii_other -# ;; Deal with 'a'-'f' -1FE00066 # CMPUI R14 R0 102 -2C7E0010 # JUMP.LE R14 @ascii_low +A0000046 # CMPSKIPI.G R0 70 +3C000010 # JUMP @ascii_high # ;; Ignore the rest -3C00001c # JUMP @ascii_other +3C000020 # JUMP @ascii_other -# :ascii_num 98 +# :ascii_num 90 11000030 # SUBUI R0 R0 48 -3C00ff88 # JUMP @loop_1 -# :ascii_low a0 -11000057 # SUBUI R0 R0 87 -3C00ff80 # JUMP @loop_1 -# :ascii_high a8 +3C00ff90 # JUMP @loop_1 +# :ascii_high 98 11000037 # SUBUI R0 R0 55 -3C00ff78 # JUMP @loop_1 -# :ascii_other b0 -0D000030 # TRUE R0 -3C00ff70 # JUMP @loop_1 -# :ascii_comment b8 -2D211100 # LOADUI R1 0x1100 ; Read from TAPE_01 +3C00ff88 # JUMP @loop_1 +# :ascii_comment a0 42100100 # FGETC ; Read another char -1FE0000a # CMPUI R14 R0 10 ; Stop at the end of line -2D210000 # LOADUI R1 0 ; Write to TTY -42100200 # FPUTC ; The char we just read -2C6Effec # JUMP.NE R14 @ascii_comment ; Otherwise keep looping -3C00ffe0 # JUMP @ascii_other +A020000a # CMPSKIPI.E R0 10 ; Stop at the end of line +3C00fff8 # JUMP @ascii_comment ; Otherwise keep looping +# :ascii_other ac +0D000030 # TRUE R0 +3C00ff74 # JUMP @loop_1 # ;; Finish function # ;; Cleans up at the end of the program # ;; Performs the HALT -# :finish d4 +# :finish b4 2D201100 # LOADUI R0 0x1100 ; Close TAPE_01 42100002 # FCLOSE 2D201101 # LOADUI R0 0x1101 ; Close TAPE_02 diff --git a/stage1/stage1_assembler-0.s b/stage1/stage1_assembler-0.s index d4c53f7..641d4ae 100644 --- a/stage1/stage1_assembler-0.s +++ b/stage1/stage1_assembler-0.s @@ -27,11 +27,11 @@ LOADUI R0 0x1101 FOPEN_WRITE + LOADUI R1 0x1100 ; Read from tape_01 ;; Main program loop ;; Halts when done :loop - LOADUI R1 0x1100 ; Read from tape_01 FGETC ; Read a Char ;; Check for EOF @@ -39,7 +39,7 @@ JUMP @hex ; Convert it :loop_1 - JUMP.NP R0 @loop ; Don't use nonhex chars + JUMP.NP R0 @loop ; Don't use nonhex chars JUMP.Z R11 @loop_2 ; Jump if toggled ;; Process first byte of pair @@ -54,6 +54,7 @@ LOADI R11 1 ; Flip the toggle LOADUI R1 0x1101 ; Write the combined byte FPUTC ; To TAPE_02 + LOADUI R1 0x1100 ; Read from tape_01 JUMP @loop ; Try to get more bytes @@ -63,52 +64,41 @@ ;; Returns to whatever called it :hex ;; Deal with line comments starting with # - CMPUI R14 R0 35 - JUMP.E R14 @ascii_comment + CMPSKIPI.NE R0 35 + JUMP @ascii_comment ;; Deal with line comments starting with ; - CMPUI R14 R0 59 - JUMP.E R14 @ascii_comment + CMPSKIPI.NE R0 59 + JUMP @ascii_comment ;; Deal with all ascii less than '0' - CMPUI R14 R0 48 - JUMP.L R14 @ascii_other + CMPSKIPI.GE R0 48 + JUMP @ascii_other ;; Deal with '0'-'9' - CMPUI R14 R0 57 - JUMP.LE R14 @ascii_num + CMPSKIPI.G R0 57 + JUMP @ascii_num + ;; Unset high bit to set everything into uppercase + ANDI R0 R0 0xDF ;; Deal with all ascii less than 'A' - CMPUI R14 R0 65 - JUMP.L R14 @ascii_other + CMPSKIPI.GE R0 65 + JUMP @ascii_other ;; Deal with 'A'-'F' - CMPUI R14 R0 70 - JUMP.LE R14 @ascii_high - ;; Deal with all ascii less than 'a' - CMPUI R14 R0 97 - JUMP.L R14 @ascii_other - ;; Deal with 'a'-'f' - CMPUI R14 R0 102 - JUMP.LE R14 @ascii_low + CMPSKIPI.G R0 70 + JUMP @ascii_high ;; Ignore the rest JUMP @ascii_other :ascii_num SUBUI R0 R0 48 JUMP @loop_1 -:ascii_low - SUBUI R0 R0 87 - JUMP @loop_1 :ascii_high SUBUI R0 R0 55 JUMP @loop_1 +:ascii_comment + FGETC ; Read another char + CMPSKIPI.E R0 10 ; Stop at the end of line + JUMP @ascii_comment ; Otherwise keep looping :ascii_other TRUE R0 JUMP @loop_1 -:ascii_comment - LOADUI R1 0x1100 ; Read from TAPE_01 - FGETC ; Read another char - CMPUI R14 R0 10 ; Stop at the end of line - LOADUI R1 0 ; Write to TTY - FPUTC ; The char we just read - JUMP.NE R14 @ascii_comment ; Otherwise keep looping - JUMP @ascii_other ;; Finish function diff --git a/test/SHA256SUMS b/test/SHA256SUMS index 51c6401..da4b39b 100644 --- a/test/SHA256SUMS +++ b/test/SHA256SUMS @@ -5,6 +5,6 @@ b3a910f18c6bc0ef4aa7a53cb3f0216a9f143319da67ed2a02210fe88b1e1131 roms/forth 2b9727381aec15a504c0898189fbc2344209d8e04451e3fa5d743e08e38f64cf roms/M0 24a4d74eb2eb7a82e68335643855658b27b5a6c3b13db473539f3e08d6f26ceb roms/SET 0a427b14020354d1c785f5f900677e0059fce8f8d4456e9c19e5528cb17101eb roms/stage0_monitor -85e5c06ac07f2b97d01dfb5454f5a698b3ec6c21fe53bf3fa57b386aac7b9601 roms/stage1_assembler-0 +3ea7fed1429400c1d6fc5b85180c4114755dfb1e6b88d69e7ecc465a40523bc8 roms/stage1_assembler-0 e59338381ca3ab01a14fa0fc85d0fa1c6e4d59a06ac2d9d75668d878ab469769 roms/stage1_assembler-1 61c1b0f2f628847d9491bd678ac7a23231527cc36493b321612f191674ff3c99 roms/stage1_assembler-2