Step a Data Pointer with INCD and DECD, not DPUP and DPDN by one
DPUP takes an immediate, so an offset of one is legal and does exactly the right thing. It is also three bytes where INCD is two, and reads as "offset the pointer up by one" where INCD reads as "step the pointer". 56 of them across 15 files: the system, the assembler, the editor, and eight test programs. CosmOS is 9,564 bytes to 9,537, the native assembler 11,648 to 11,635, and every program in the repository together 49 bytes lighter. The worst offender was numbers.asm, written this week, where every sixteen bit helper reaches the low byte and comes back the long way round. It is the file every other part of the assembler includes, so it is the first thing anybody reads when they go looking - and it was teaching them the long way. Pattern matched off sbfs.asm rather than off the instruction table I had just embedded in two programs. THIS IS NOT TWO WAYS TO DO ONE THING. DPUP takes an arbitrary number, so one is inevitably among them; INCD earns its place by making the common case a byte cheaper. The overlap is structural and the choice is a usage question, which is a linter's job rather than an ISA's - "DPUP.n 0d01: INCD.n does this in a byte less" is a mechanical rule with no judgement in it. Nothing needed re-recording, which was not a foregone conclusion: cosmosBreak prints the system addresses the registers happened to hold, and they did not move. Both assemblers still produce identical bytes and CosmOS still builds itself to a fixed point. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
co-authored by
Claude Opus 5
parent
12cb489268
commit
4fd8bf7b3f
@@ -179,7 +179,7 @@ refusedHandler:
|
||||
BRC refusedCarried
|
||||
RETI
|
||||
refusedCarried:
|
||||
DPDN.0 0d01
|
||||
DECD.0
|
||||
LDA.0
|
||||
INCA
|
||||
STA.0
|
||||
|
||||
@@ -102,7 +102,7 @@ stepPastRefusal:
|
||||
BRC carried
|
||||
RETI
|
||||
carried:
|
||||
DPDN.0 0d01
|
||||
DECD.0
|
||||
LDA.0
|
||||
INCA
|
||||
STA.0
|
||||
|
||||
@@ -41,7 +41,7 @@ faultHandler:
|
||||
RETI
|
||||
|
||||
carried:
|
||||
DPDN.0 0d01
|
||||
DECD.0
|
||||
LDA.0
|
||||
INCA
|
||||
STA.0
|
||||
|
||||
@@ -143,7 +143,7 @@ guardHandler:
|
||||
BRC stepCarried
|
||||
RETI
|
||||
stepCarried:
|
||||
DPDN.0 0d01
|
||||
DECD.0
|
||||
LDA.0
|
||||
INCA
|
||||
STA.0
|
||||
|
||||
@@ -50,7 +50,7 @@ refusalHandler:
|
||||
RETI
|
||||
|
||||
carried:
|
||||
DPDN.0 0d01
|
||||
DECD.0
|
||||
LDA.0
|
||||
INCA
|
||||
STA.0
|
||||
|
||||
@@ -114,7 +114,7 @@ bankHandler:
|
||||
BRC bankCarried
|
||||
RETI
|
||||
bankCarried:
|
||||
DPDN.0 0d01
|
||||
DECD.0
|
||||
LDA.0
|
||||
INCA
|
||||
STA.0
|
||||
|
||||
@@ -89,7 +89,7 @@ showFound:
|
||||
showContents:
|
||||
SETD.0 Landing
|
||||
SETD.1 SbfsFileBlocks
|
||||
DPUP.1 0d01
|
||||
INCD.1
|
||||
LDA.1
|
||||
SETD.1 LeftHigh
|
||||
STA.1
|
||||
|
||||
@@ -60,7 +60,7 @@ walkCheck:
|
||||
; A file is its blocks times 256 plus its tail, which is the block count in the high
|
||||
; byte and the tail in the low one. Nothing has to multiply anything.
|
||||
SETD.0 SbfsFileBlocks
|
||||
DPUP.0 0d01
|
||||
INCD.0
|
||||
LDA.0
|
||||
SETD.1 Size
|
||||
STA.1
|
||||
|
||||
@@ -24,7 +24,7 @@ start:
|
||||
; The Stack Pointer points at the next free slot, so the byte pushed last sits one
|
||||
; above it, and the one before that sits two above.
|
||||
MVSD.0
|
||||
DPUP.0 0d01
|
||||
INCD.0
|
||||
LDA.0 ; 'K', the last one pushed.
|
||||
INCD.0
|
||||
LDB.0 ; 'O', the one before it.
|
||||
|
||||
Reference in New Issue
Block a user