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:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user