Two mechanical fixes SplitLint found: MVQA, and RSTA for zero

Twenty four places moved Q into A or B by pushing it and popping it back.
That is four bus cycles and two bytes to do what MVQA does in one of each,
and several of them are inside loops - Life, the calculator, int8. Nineteen
more loaded zero with INIA 0d0 where RSTA says the same thing in one byte.

Both are equivalent at the CPU rather than by assertion: RSTA and INIA both
leave Status alone, and PSHQ followed by POPA nets to A = Q with the Stack
Pointer where it started. The one difference is that the pair leaves a copy
of Q in memory just below the Stack Pointer and MVQA does not, which
nothing here reads.

Five recorded outputs moved and every one of them says the change worked:

- 16x16Life fits five more generations into the same cycle budget, the
  first 457 lines identical, because the loop got cheaper.
- Life.sbx is 1409 bytes rather than 1411, in three tests that list it.
- Edit.sbx is 1995 rather than 1996.

That last one broke a check I added this morning, and the hole is worth
recording: the CosmOS README's claim about Edit's size did not have the
word "Edit" on the same line as the number, because the subject was in the
sentence before, so the check that measures quoted sizes skipped it
silently. The sentence now names what it is talking about, which makes it
both checkable and clearer, and the check fails on a wrong number there.

Comments on either half of a replaced pair are carried onto the
instruction that replaces them, so nothing anybody wrote was lost.
This commit is contained in:
Anachronaut
2026-08-26 17:53:10 -04:00
parent c146d98588
commit e1273337c4
19 changed files with 55 additions and 74 deletions
+2 -3
View File
@@ -8,7 +8,7 @@
start:
; Load our initial values into A and B.
INIA 0x00
RSTA
CALL printByteDecimal
CALL blankSpace
; Move the value into B.
@@ -25,8 +25,7 @@ start:
PSHA
POPB
; Copy Q into A
PSHQ
POPA
MVQA
; Print A.
CALL printByteDecimal
CALL blankSpace
+1 -1
View File
@@ -33,7 +33,7 @@ clsToken:
INIB 0x23 ; '#'
XOR
BNQ clsTryInstruction
INIA 0d0
RSTA
SETD.0 ClsType
STA.0
BRI clsYes
+1 -1
View File
@@ -462,7 +462,7 @@ Typed in as bytes, checked by disassembling it back, and run. It ends with `SWI
`Edit` is the first program on this machine that makes a file a person typed - every byte on every disk before it was put there by the host tool. It is line oriented in the manner of `ed`: `l` lists, `a` adds at the end, `i` and `c` and `d` take a line number, `w` writes and `q` stops.
It includes nothing but `services.asm` and `text.asm`: the filesystem and the console are the system's, asked for rather than carried. That is what took it from 4,941 bytes to 1,996 without a line of its own logic changing - and the way that was checked is worth knowing, because the recorded output of the `cosmosEdit` test did not move by a single byte across the rewrite.
It includes nothing but `services.asm` and `text.asm`: the filesystem and the console are the system's, asked for rather than carried. That is what brought `Edit` down from 4,941 bytes to 1,995 bytes without a line of its own logic changing - and the way that was checked is worth knowing, because the recorded output of the `cosmosEdit` test did not move by a single byte across the rewrite.
It keeps the document as a **linked list of lines** rather than one buffer with newlines in it. Each line says where the next one is, how long it is, and then its bytes. Inserting is two pointers changed and nothing moved; with a flat buffer it would mean shifting every byte after the edit, on a machine whose only block move is a device asked politely. The price is that deleted lines are not reused, so a heavy session uses more room than the document needs and writing it out is what tidies up.
+1 -2
View File
@@ -94,8 +94,7 @@ textHexWord:
textHexLoop:
LDA.0
CALL textHexDigit
PSHQ
POPA
MVQA
INIB 0xFF
CCF
SUB
@@ -5,7 +5,7 @@
#Program
start:
; Load our initial values into A and B.
INIA 0x00
RSTA
CALL printByteDecimal
CALL blankSpace
; Move the value into B.
@@ -22,8 +22,7 @@ start:
PSHA
POPB
; Copy Q into A
PSHQ
POPA
MVQA
; Print A.
CALL printByteDecimal
CALL blankSpace
+7 -14
View File
@@ -193,50 +193,43 @@ countNeighbors:
LDB
CCF
ADD
PSHQ
POPA
MVQA
DPUP 0d02
LDB
CCF
ADD
PSHQ
POPA
MVQA
DPUP 0d02
LDB
CCF
ADD
PSHQ
POPA
MVQA
DPUP 0d32
LDB
CCF
ADD
PSHQ
POPA
MVQA
DPUP 0d04
LDB
CCF
ADD
PSHQ
POPA
MVQA
DPUP 0d32
LDB
CCF
ADD
PSHQ
POPA
MVQA
DPUP 0d02
LDB
CCF
ADD
PSHQ
POPA
MVQA
DPUP 0d02
LDB
+1 -1
View File
@@ -20,7 +20,7 @@ start:
INCD ; Increment to the next spot in the buffer.
BRI inputLoop ; Loop again to grab more string.
inputEnd:
INIA 0x00 ; Set A to 0.
RSTA ; Set A to 0.
STA ; Store it in the buffer.
SETD Buffer ; Set the Data Pointer to the start of the buffer again.
CALL printString ; Print it out.
+17 -27
View File
@@ -18,8 +18,7 @@ repl:
CALL printString
CALL readNonSpace
PSHQ
POPA
MVQA
; Q, q, or end-of-file exits.
INIB 0xFF
@@ -39,14 +38,12 @@ repl:
BRQ inputError
CALL readNonSpace
PSHQ
POPA
MVQA
SETD Operator
STA
CALL readNonSpace
PSHQ
POPA
MVQA
CALL readHexByteFirst
SETD RightOperand
STQ
@@ -98,7 +95,7 @@ readNonSpaceLoop:
INIB 0x0D
XOR
BRQ readNonSpaceLoop
INIB 0x00
RSTB
CCF
ADD
RET
@@ -108,12 +105,11 @@ readNonSpaceLoop:
readHexByteFirst:
CALL clearParseStatus
CALL hexNibble
PSHQ
POPA
MVQA
INIB 0xFF
XOR
BRQ invalidByte
INIB 0x00
RSTB
SHL
SHL
SHL
@@ -121,11 +117,9 @@ readHexByteFirst:
PSHA
CALL readNonSpace
PSHQ
POPA
MVQA
CALL hexNibble
PSHQ
POPA
MVQA
INIB 0xFF
XOR
BRQ invalidLowNibble
@@ -142,7 +136,7 @@ invalidByte:
STA
POPD
INIA 0xFF
INIB 0x00
RSTB
CCF
ADD
RET
@@ -157,8 +151,7 @@ hexNibble:
CCF
SUB
BRC tryUpperHex
PSHQ
POPA
MVQA
INIB 0d10
CCF
SUB
@@ -171,8 +164,7 @@ tryUpperHex:
CCF
SUB
BRC tryLowerHex
PSHQ
POPA
MVQA
INIB 0d06
CCF
SUB
@@ -185,8 +177,7 @@ tryLowerHex:
CCF
SUB
BRC badNibble
PSHQ
POPA
MVQA
INIB 0d06
CCF
SUB
@@ -195,14 +186,14 @@ tryLowerHex:
badNibble:
POPA
INIA 0xFF
INIB 0x00
RSTB
CCF
ADD
RET
decimalNibble:
POPB
INIB 0x00
RSTB
CCF
ADD
RET
@@ -223,8 +214,7 @@ lowerNibble:
; Return Q=0 if Q was 0xFF, otherwise return a nonzero value.
resultIsInvalid:
PSHQ
POPA
MVQA
INIB 0xFF
XOR
RET
@@ -288,7 +278,7 @@ evaluate:
INIA 0x01
STA
RSTA
INIB 0x00
RSTB
CCF
ADD
RET
@@ -360,7 +350,7 @@ multiplyLoop:
multiplyDone:
SETD Product
LDA
INIB 0x00
RSTB
CCF
ADD
RET
+4 -8
View File
@@ -25,8 +25,7 @@ int8mult:
DECA ; Subtract one from the multiplier.
BRA int8multDone ; If the multiplier becomes zero, we're done.
PSHA ; Push the multiplier back to the stack.
PSHQ ; Push the running total to the stack.
POPA ; Pop the running total into A.
MVQA ; Push the running total to the stack. Pop the running total into A.
BRI int8multLoop
return0:
RSTA
@@ -58,8 +57,7 @@ int8div:
POPA ; Pop the quotient counter from the stack.
INCA ; Increment it.
PSHA ; Push it back onto the stack.
PSHQ ; Push the running total onto the stack.
POPA ; Pop the runing total into A.
MVQA ; Push the running total onto the stack. Pop the runing total into A.
BRI int8divLoop ; Branch back to the loop.
int8divDone:
CCF ; Clear the Carry Flag.
@@ -76,13 +74,11 @@ int8mod:
int8modLoop:
SUB ; Subtract B from A.
BRC int8modDone
PSHQ
POPA
MVQA
BRI int8modLoop
int8modDone:
; Add the divisor to Q to get the remainder.
CCF
PSHQ
POPA
MVQA
ADD
RET
+2 -2
View File
@@ -97,10 +97,10 @@ printByteDecimal:
; Expects A to contain the byte you want to print as a hexadecimal value.
printByteHex:
INIB 0x00 ; Set B to 0.
RSTB ; Set B to 0.
SHR SHR SHR SHR ; Shift Right four times to move the high nybble into the lower half of A.
CALL printHexDigit ; Print the nybble.
INIA 0x00 ; Set A to 0.
RSTA ; Set A to 0.
SHL SHL SHL SHL ; Shift left four times to move the low nybble back into the lower half of A.
CALL printHexDigit ; Print the nybble.
RET ; Return to the caller.
+1 -1
View File
@@ -20,7 +20,7 @@ start:
INCD ; Increment to the next spot in the buffer.
BRI inputLoop ; Loop again to grab more string.
inputEnd:
INIA 0x00 ; Set A to 0.
RSTA ; Set A to 0.
STA ; Store it in the buffer.
SETD Buffer ; Set the Data Pointer to the start of the buffer again.
CALL printString ; Print it out.
+2 -2
View File
@@ -8,8 +8,8 @@
#Program
clearRegisters:
INIA 0x00;
INIB 0x00;
RSTA
RSTB
ADD
RET
+2 -2
View File
@@ -36,12 +36,12 @@ start:
; ---- Offsetting by a whole sixteen bit value ----
SETD.1 Text
INIA 0x00
RSTA
INIB 0d13
DPUW.1
LDA.1
OUTA 0x00
INIA 0x00
RSTA
INIB 0d13
DPDW.1
LDA.1
+1 -1
View File
@@ -21,7 +21,7 @@
#Program
start:
INIA 0x00
RSTA
CALL reportPort
INIA 0x10
CALL reportPort