BeebAsm — gotchas from two ports
BeebAsm (Rich Talbot-Watkins, 2004 onwards) is the community-standard cross-assembler; its syntax is a near-superset of the BBC BASIC inline assembler documented on basic-assembler. This page is not a syntax reference — it is the list of things that cost a build during two C64-to-BBC ports by Kieran Connell, Paradroid and Edge Grinder, both on beebasm 1.11. Source: beeb-port-kit-hardware-facts §10 (and §6 for the disc-order item).
Conditional assembly and command-line symbols
- There is no
IFDEF, and a symbol defined twice is an error. So a source file cannot carry a default for a command-line symbol: every invocation must pass-D RELEASE=0(and every other such flag) or assembly stops with Symbol not defined. A build with one optional flag therefore needs every bare invocation to pass it — which is why Paradroid’s!BOOTwiring became a post-processor patch instead of a-D. (Paradroid, 2026-08-26 and 2026-08-29,CLAUDE.md,docs/intro.md.) Edge Grinder passes four such symbols on every build and stamps every one that changes the disc’s contents into!BOOT, so a build cannot lie about itself. - Constant assignments resolve in file order, so shared constants go in the top file before the
INCLUDEs that need them. - beebasm will not
INCLUDEinside a braced{}block. A generated table that a braced routine needs must be INCLUDEd outside the braces. (EdgeCLAUDE.md.)
Labels
- A local label inside
{}shadows a global of the same name, silently.sta comp_flagnext to a local.comp_flagwould have stored into code. Assembles cleanly, fails quietly. Do not name a local label after anything it is used next to. (Edge,wave_manager.) - An undefined symbol is assembled as an absolute address in pass 1, then errors on the size change in pass 2 when it turns out to be zero page. Declare zero-page slots before the code that uses them. (Edge, 2026-09-04,
docs/layer-9-loader.md.) The same trap in the BASIC assembler is on basic-assembler — there it shifts every later label by a byte.
Output, SAVE and disc images
- beebasm writes progress and success messages to stderr. In PowerShell under
$ErrorActionPreference = 'Stop', redirecting that stream (2>&1) raisesNativeCommandErroron a successful build. Redirect stdout alone and check the exit code. From bash,2>&1is fine. (Both ports’CLAUDE.md.) SAVEwrites a loose host file whenever there is no disc image to put it in, so a run without a working-dodrops every SAVEd file in the working directory, and a-dopath that cannot be written leaves a build that looks like it worked. (ParadroidCLAUDE.md.)- beebasm lays files on the disc in
SAVEorder. That put!BOOTand the main executable physically last; every boot read the end of the disc and seeked back to track 0. Reordering into boot-access order was the whole of a 6.01M → 4.33M cycle saving on the first boot phase. (Paradroid, 2026-08-21,docs/loader-compression.md.) Both ports post-process the SSD with a Python tool that rewrites the catalogue in access order; see zx0-loading. - beebasm’s own image need not be bootable. Edge Grinder’s
EDGE-RAW.SSDis beebasm’s output and every data file on the shipped disc is ZX0-compressed by a second pass; hand the second image to the emulator. And jsbeeb does boot an unpadded SSD — see emulators. INCLUDEandINCBINresolve from the working directory, so the build must run from the project root (or from inside a vendored directory whose paths are relative to itself). (Edgedocs/layer-0-toolchain.md; ParadroidCLAUDE.md.)- The assembler works in one 64K image: a file assembled at an address after another file’s
SAVElands on the earlier file’s bytes, so the order of the two is load-bearing. (Paradroiddocs/layer-13-compatibility.md.) Edge Grinder assembles!BOOTat&2600— inside a region that only exists at run time — for exactly this reason.
GUARD, CLEAR, SKIP, ALIGN
CLEARreleases beebasm’s overwrite check;GUARDis what catches an overrun.CLEAR A, Bover the range an over-long image spills into means the overrun assembles silently and corrupts whatever loads there at run time. Keep aGUARDat the top of every image. (ParadroidCLAUDE.md.) Edge addsASSERT code_end <= SPR_SAVEfor a ceiling that is lower than the image’sGUARDbecause the region above it is rewritten at run time.SKIPemits nothing, so a listing-based gap finder cannot tell reserved storage from padding. A “739 bytes of alignment holes” claim was fourSKIPped tables; the genuineALIGNpadding was 111 bytes, and removing it freed nothing because the nextALIGNpadded by the same amount. (Paradroid RAM pass, 2026-08-25,docs/layer-13-ram-pass.md.)- Spending one byte past an
ALIGNpad costs 256 at a stroke; anything assembled before the pad rides in it for nothing. Quote a bank’s pad and tail as a pair.
Useful tricks
TIME$stamps the assembly time — put it in!BOOTso any disc image can be dated. (Edge.)- The symbol dump —
beebasm -i src/main.asm -do build/symbols.ssd -D RELEASE=0 -d | tr ',' '\n' | grep "'name'"prints every global label as'name':decimal, the quick way to find a variable’s address for an emulator poke.-dois there only to stop the loose files. (ParadroidCLAUDE.md.) - A mechanical change can be proved mechanical by reducing both
-vlistings to a stream of (mnemonic, addressing class) and comparing, or by extracting the files from both SSD catalogues and comparing bytes. Edge Grinder has no automated tests; this is its regression check. (Edgedocs/layer-0-toolchain.md.) - Boot-only code can live where run-time data will be. Both ports put their loader and depacker above the code ceiling, in memory that a sprite blitter or a screen overwrites once the game is running — the assembler does not care, and it is the tightest region in the build. Just
ASSERTthat nothing read in play is there (Edge’sBUGS.md#13 is a table that drifted over the line).
See also
- basic-assembler — the syntax this dialect comes from, and porting notes.
- emulators — what to hand the result to, and how to measure it.
- zx0-loading — the second build pass both ports use.
This wiki is curated by Claude following the LLM-Wiki methodology — a human curates source documents, the LLM compiles structured cross-linked markdown. Content may contain errors, omissions, or stale claims. For authoritative information refer to the original source documents in the bbc-documents GitHub archive.