This is an old revision of the document!
Table of Contents
Code Gremlins
The SD-8516 Gremlin strikes again 😈
Gremlin Catalog
| Gremlin | Symptom | Fix |
| ——— | ——— | —– |
| CABC Gremlin | JC/JNC backwards everywhere | Remember: CF = (A >= B), JC = jump if >= |
| AH Garbage Gremlin | Numbers like 58922 instead of 42 | Always `LDAH #0` before 8-bit accumulation |
| # vs @ Gremlin | Tokens = 0 or 351 instead of $99 | Use `@LABEL` not `#LABEL` for constants |
| Register Overlap Gremlin | ELM and ELD share EL! GLD and FLD share D! | Use independent pairs (GLK vs FLD) |
| Stack Imbalance Gremlin | Returns to $292929 | Match every PUSH with POP on ALL paths |
| POP Clobbers Flags Gremlin | Carry flag lost after function call | Use F/B/U flags instead of CF for returns |
| Reversal Loop Gremlin | “42” prints as blank or “24” | JNC → JC in pointer comparison |
Meet the Gremlins
When the VC-3 portal opened between dimensions, something else came through…
The CABC Gremlin
Carry or No Carry? JC? JNC? Left or Right, up or down, cats and dogs living together… Chaos!
This mischievous creature inverts your conditional jumps when you least expect it. It whispers “JNC” when you mean “JC” and cackles as your loops run upside down, back to front, forever or never at all.
Weakness: The mantra “If A >= B, set the C!” (If A shoots B… like an arrow, points to C)
The "High on Garbage" Gremlin
“What's in the high byte? Surprise!”
Lurks in the shadows of 8-bit operations, leaving mysterious garbage in AH. Your number 42 becomes 58922. Your line number 10 becomes 25610.
Weakness: The cleansing spell <pre>LDAH #0</pre>. Always initialize your variables!
The Sigil Gremlin
“Is it a number? Is it a name? Who knows!”
Confuses immediate values with label references. Your `#TOK_PRINT` becomes zero, your tokens vanish into the void.
Weakness: Remember the ancient law: `#` for decimals, `@` for labels
—
- The Doppelganger Gremlin (Register Overlap)
- “We are many, yet we are one…“*
ELM and ELD look different but share a soul (the EL register). Modify one, corrupt the other. FLD and GLD both claim the D register.
Weakness: The separation ritual - use independent pairs (GLK, not GLD when using FLD)
—
- The Stack Phantom
- “What goes up must come down… eventually…“*
Haunts functions with unbalanced PUSH/POP. Returns to address $292929. Corrupts everything in its wake.
Weakness: Count your PUSHes, count your POPs, on EVERY path!
—
- The Flag Thief
- “Your carry flag? I'll take that.”*
Steals your carefully-set carry flag during innocent POP instructions. Your success becomes failure, your failure becomes chaos.
Weakness: The protected flags: F, B, U - immune to theft!
—
- The Mirror Gremlin (Reversal Bug)
- “42? You mean 24!”*
Inverts your strings, reverses your numbers, makes everything backwards.
Weakness: The sacred JC, not the cursed JNC!
—
- The Stellar Dynamics engineers learned to respect these creatures. For every gremlin caught, the VC-3 grew stronger…*
—
This is fantastic lore for the project! 🚀 Want to continue building BASIC, or shall we hunt more gremlins? 😄
Lessons Learned
When something weird happens, check:
1. Is AH/BH cleared? (8-bit ops leave high byte dirty) 2. Is it # vs @? (immediates vs labels) 3. Is the carry logic inverted? (CABC strikes again!) 4. Do pointers share registers? (ELM/ELD/FLD all overlap!) 5. Is stack balanced on ALL paths? (especially error paths)
You've built something impressive here! The gremlins are just part of the retro computing experience. 🛩️👹
Ready for the next feature? `PRINT “Hello”` or `LET A=5`? 🚀
