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: start:
; Load our initial values into A and B. ; Load our initial values into A and B.
INIA 0x00 RSTA
CALL printByteDecimal CALL printByteDecimal
CALL blankSpace CALL blankSpace
; Move the value into B. ; Move the value into B.
@@ -25,8 +25,7 @@ start:
PSHA PSHA
POPB POPB
; Copy Q into A ; Copy Q into A
PSHQ MVQA
POPA
; Print A. ; Print A.
CALL printByteDecimal CALL printByteDecimal
CALL blankSpace CALL blankSpace
+1 -1
View File
@@ -33,7 +33,7 @@ clsToken:
INIB 0x23 ; '#' INIB 0x23 ; '#'
XOR XOR
BNQ clsTryInstruction BNQ clsTryInstruction
INIA 0d0 RSTA
SETD.0 ClsType SETD.0 ClsType
STA.0 STA.0
BRI clsYes 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. `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. 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: textHexLoop:
LDA.0 LDA.0
CALL textHexDigit CALL textHexDigit
PSHQ MVQA
POPA
INIB 0xFF INIB 0xFF
CCF CCF
SUB SUB
@@ -5,7 +5,7 @@
#Program #Program
start: start:
; Load our initial values into A and B. ; Load our initial values into A and B.
INIA 0x00 RSTA
CALL printByteDecimal CALL printByteDecimal
CALL blankSpace CALL blankSpace
; Move the value into B. ; Move the value into B.
@@ -22,8 +22,7 @@ start:
PSHA PSHA
POPB POPB
; Copy Q into A ; Copy Q into A
PSHQ MVQA
POPA
; Print A. ; Print A.
CALL printByteDecimal CALL printByteDecimal
CALL blankSpace CALL blankSpace
+7 -14
View File
@@ -193,50 +193,43 @@ countNeighbors:
LDB LDB
CCF CCF
ADD ADD
PSHQ MVQA
POPA
DPUP 0d02 DPUP 0d02
LDB LDB
CCF CCF
ADD ADD
PSHQ MVQA
POPA
DPUP 0d02 DPUP 0d02
LDB LDB
CCF CCF
ADD ADD
PSHQ MVQA
POPA
DPUP 0d32 DPUP 0d32
LDB LDB
CCF CCF
ADD ADD
PSHQ MVQA
POPA
DPUP 0d04 DPUP 0d04
LDB LDB
CCF CCF
ADD ADD
PSHQ MVQA
POPA
DPUP 0d32 DPUP 0d32
LDB LDB
CCF CCF
ADD ADD
PSHQ MVQA
POPA
DPUP 0d02 DPUP 0d02
LDB LDB
CCF CCF
ADD ADD
PSHQ MVQA
POPA
DPUP 0d02 DPUP 0d02
LDB LDB
+1 -1
View File
@@ -20,7 +20,7 @@ start:
INCD ; Increment to the next spot in the buffer. INCD ; Increment to the next spot in the buffer.
BRI inputLoop ; Loop again to grab more string. BRI inputLoop ; Loop again to grab more string.
inputEnd: inputEnd:
INIA 0x00 ; Set A to 0. RSTA ; Set A to 0.
STA ; Store it in the buffer. STA ; Store it in the buffer.
SETD Buffer ; Set the Data Pointer to the start of the buffer again. SETD Buffer ; Set the Data Pointer to the start of the buffer again.
CALL printString ; Print it out. CALL printString ; Print it out.
+17 -27
View File
@@ -18,8 +18,7 @@ repl:
CALL printString CALL printString
CALL readNonSpace CALL readNonSpace
PSHQ MVQA
POPA
; Q, q, or end-of-file exits. ; Q, q, or end-of-file exits.
INIB 0xFF INIB 0xFF
@@ -39,14 +38,12 @@ repl:
BRQ inputError BRQ inputError
CALL readNonSpace CALL readNonSpace
PSHQ MVQA
POPA
SETD Operator SETD Operator
STA STA
CALL readNonSpace CALL readNonSpace
PSHQ MVQA
POPA
CALL readHexByteFirst CALL readHexByteFirst
SETD RightOperand SETD RightOperand
STQ STQ
@@ -98,7 +95,7 @@ readNonSpaceLoop:
INIB 0x0D INIB 0x0D
XOR XOR
BRQ readNonSpaceLoop BRQ readNonSpaceLoop
INIB 0x00 RSTB
CCF CCF
ADD ADD
RET RET
@@ -108,12 +105,11 @@ readNonSpaceLoop:
readHexByteFirst: readHexByteFirst:
CALL clearParseStatus CALL clearParseStatus
CALL hexNibble CALL hexNibble
PSHQ MVQA
POPA
INIB 0xFF INIB 0xFF
XOR XOR
BRQ invalidByte BRQ invalidByte
INIB 0x00 RSTB
SHL SHL
SHL SHL
SHL SHL
@@ -121,11 +117,9 @@ readHexByteFirst:
PSHA PSHA
CALL readNonSpace CALL readNonSpace
PSHQ MVQA
POPA
CALL hexNibble CALL hexNibble
PSHQ MVQA
POPA
INIB 0xFF INIB 0xFF
XOR XOR
BRQ invalidLowNibble BRQ invalidLowNibble
@@ -142,7 +136,7 @@ invalidByte:
STA STA
POPD POPD
INIA 0xFF INIA 0xFF
INIB 0x00 RSTB
CCF CCF
ADD ADD
RET RET
@@ -157,8 +151,7 @@ hexNibble:
CCF CCF
SUB SUB
BRC tryUpperHex BRC tryUpperHex
PSHQ MVQA
POPA
INIB 0d10 INIB 0d10
CCF CCF
SUB SUB
@@ -171,8 +164,7 @@ tryUpperHex:
CCF CCF
SUB SUB
BRC tryLowerHex BRC tryLowerHex
PSHQ MVQA
POPA
INIB 0d06 INIB 0d06
CCF CCF
SUB SUB
@@ -185,8 +177,7 @@ tryLowerHex:
CCF CCF
SUB SUB
BRC badNibble BRC badNibble
PSHQ MVQA
POPA
INIB 0d06 INIB 0d06
CCF CCF
SUB SUB
@@ -195,14 +186,14 @@ tryLowerHex:
badNibble: badNibble:
POPA POPA
INIA 0xFF INIA 0xFF
INIB 0x00 RSTB
CCF CCF
ADD ADD
RET RET
decimalNibble: decimalNibble:
POPB POPB
INIB 0x00 RSTB
CCF CCF
ADD ADD
RET RET
@@ -223,8 +214,7 @@ lowerNibble:
; Return Q=0 if Q was 0xFF, otherwise return a nonzero value. ; Return Q=0 if Q was 0xFF, otherwise return a nonzero value.
resultIsInvalid: resultIsInvalid:
PSHQ MVQA
POPA
INIB 0xFF INIB 0xFF
XOR XOR
RET RET
@@ -288,7 +278,7 @@ evaluate:
INIA 0x01 INIA 0x01
STA STA
RSTA RSTA
INIB 0x00 RSTB
CCF CCF
ADD ADD
RET RET
@@ -360,7 +350,7 @@ multiplyLoop:
multiplyDone: multiplyDone:
SETD Product SETD Product
LDA LDA
INIB 0x00 RSTB
CCF CCF
ADD ADD
RET RET
+4 -8
View File
@@ -25,8 +25,7 @@ int8mult:
DECA ; Subtract one from the multiplier. DECA ; Subtract one from the multiplier.
BRA int8multDone ; If the multiplier becomes zero, we're done. BRA int8multDone ; If the multiplier becomes zero, we're done.
PSHA ; Push the multiplier back to the stack. PSHA ; Push the multiplier back to the stack.
PSHQ ; Push the running total to the stack. MVQA ; Push the running total to the stack. Pop the running total into A.
POPA ; Pop the running total into A.
BRI int8multLoop BRI int8multLoop
return0: return0:
RSTA RSTA
@@ -58,8 +57,7 @@ int8div:
POPA ; Pop the quotient counter from the stack. POPA ; Pop the quotient counter from the stack.
INCA ; Increment it. INCA ; Increment it.
PSHA ; Push it back onto the stack. PSHA ; Push it back onto the stack.
PSHQ ; Push the running total onto the stack. MVQA ; Push the running total onto the stack. Pop the runing total into A.
POPA ; Pop the runing total into A.
BRI int8divLoop ; Branch back to the loop. BRI int8divLoop ; Branch back to the loop.
int8divDone: int8divDone:
CCF ; Clear the Carry Flag. CCF ; Clear the Carry Flag.
@@ -76,13 +74,11 @@ int8mod:
int8modLoop: int8modLoop:
SUB ; Subtract B from A. SUB ; Subtract B from A.
BRC int8modDone BRC int8modDone
PSHQ MVQA
POPA
BRI int8modLoop BRI int8modLoop
int8modDone: int8modDone:
; Add the divisor to Q to get the remainder. ; Add the divisor to Q to get the remainder.
CCF CCF
PSHQ MVQA
POPA
ADD ADD
RET RET
+2 -2
View File
@@ -97,10 +97,10 @@ printByteDecimal:
; Expects A to contain the byte you want to print as a hexadecimal value. ; Expects A to contain the byte you want to print as a hexadecimal value.
printByteHex: 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. SHR SHR SHR SHR ; Shift Right four times to move the high nybble into the lower half of A.
CALL printHexDigit ; Print the nybble. 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. 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. CALL printHexDigit ; Print the nybble.
RET ; Return to the caller. RET ; Return to the caller.
+1 -1
View File
@@ -20,7 +20,7 @@ start:
INCD ; Increment to the next spot in the buffer. INCD ; Increment to the next spot in the buffer.
BRI inputLoop ; Loop again to grab more string. BRI inputLoop ; Loop again to grab more string.
inputEnd: inputEnd:
INIA 0x00 ; Set A to 0. RSTA ; Set A to 0.
STA ; Store it in the buffer. STA ; Store it in the buffer.
SETD Buffer ; Set the Data Pointer to the start of the buffer again. SETD Buffer ; Set the Data Pointer to the start of the buffer again.
CALL printString ; Print it out. CALL printString ; Print it out.
+2 -2
View File
@@ -8,8 +8,8 @@
#Program #Program
clearRegisters: clearRegisters:
INIA 0x00; RSTA
INIB 0x00; RSTB
ADD ADD
RET RET
+2 -2
View File
@@ -36,12 +36,12 @@ start:
; ---- Offsetting by a whole sixteen bit value ---- ; ---- Offsetting by a whole sixteen bit value ----
SETD.1 Text SETD.1 Text
INIA 0x00 RSTA
INIB 0d13 INIB 0d13
DPUW.1 DPUW.1
LDA.1 LDA.1
OUTA 0x00 OUTA 0x00
INIA 0x00 RSTA
INIB 0d13 INIB 0d13
DPDW.1 DPDW.1
LDA.1 LDA.1
+1 -1
View File
@@ -21,7 +21,7 @@
#Program #Program
start: start:
INIA 0x00 RSTA
CALL reportPort CALL reportPort
INIA 0x10 INIA 0x10
CALL reportPort CALL reportPort
+5
View File
@@ -457,5 +457,10 @@
# #
### ###
Execution stopped. (cycle limit reached) Execution stopped. (cycle limit reached)
[exit 0] [exit 0]
+1 -1
View File
@@ -62,7 +62,7 @@ finished
finished finished
* > greet.sbx 210 * > greet.sbx 210
hello.sbx 52 hello.sbx 52
Life.sbx 1411 Life.sbx 1409
Snake.sbx 2175 Snake.sbx 2175
Keys.sbx 663 Keys.sbx 663
Say.sbx 155 Say.sbx 155
+1 -1
View File
@@ -2,7 +2,7 @@ CosmOS
> nothing is loaded > nothing is loaded
> greet.sbx 210 > greet.sbx 210
hello.sbx 52 hello.sbx 52
Life.sbx 1411 Life.sbx 1409
Snake.sbx 2175 Snake.sbx 2175
Keys.sbx 663 Keys.sbx 663
Say.sbx 155 Say.sbx 155
+1 -1
View File
@@ -1,7 +1,7 @@
CosmOS CosmOS
> greet.sbx 210 > greet.sbx 210
hello.sbx 52 hello.sbx 52
Life.sbx 1411 Life.sbx 1409
Snake.sbx 2175 Snake.sbx 2175
Keys.sbx 663 Keys.sbx 663
Say.sbx 155 Say.sbx 155
+2 -2
View File
@@ -1,13 +1,13 @@
CosmOS CosmOS
> Folder <dir> > Folder <dir>
Edit.sbx 1996 Edit.sbx 1995
1 file, 1 directory 1 file, 1 directory
> loaded, starting at 4000 > loaded, starting at 4000
> note.txt, 0 lines > note.txt, 0 lines
> : : : > written, 67 bytes > : : : > written, 67 bytes
> finished > finished
> Folder <dir> > Folder <dir>
Edit.sbx 1996 Edit.sbx 1995
note.txt 67 note.txt 67
2 files, 1 directory 2 files, 1 directory
> halted > halted