diff --git a/src/assets/hello-world.asm b/src/assets/hello-world.asm index 0edf2c8e..c4d00626 100644 --- a/src/assets/hello-world.asm +++ b/src/assets/hello-world.asm @@ -29,7 +29,7 @@ WaitVBlank: ; Copy the tile data ld de, Tiles ld hl, $9000 - ld bc, TilesEnd - Tiles + ld bc, Tiles.End - Tiles CopyTiles: ; ANCHOR: memcpy_first_two ld a, [de] @@ -45,7 +45,7 @@ CopyTiles: ; Copy the tilemap ld de, Tilemap ld hl, $9800 - ld bc, TilemapEnd - Tilemap + ld bc, Tilemap.End - Tilemap CopyTilemap: ld a, [de] ld [hli], a @@ -71,6 +71,7 @@ Done: SECTION "Tile data", ROM0 +; ANCHOR: tiles Tiles: db $00,$ff, $00,$ff, $00,$ff, $00,$ff, $00,$ff, $00,$ff, $00,$ff, $00,$ff db $00,$ff, $00,$80, $00,$80, $00,$80, $00,$80, $00,$80, $00,$80, $00,$80 @@ -142,10 +143,12 @@ Tiles: db $54,$ff, $aa,$ff, $54,$ff, $aa,$ff, $54,$ff, $aa,$ff, $54,$ff, $00,$ff db $15,$ff, $2a,$ff, $15,$ff, $0a,$ff, $15,$ff, $0a,$ff, $01,$ff, $00,$ff db $01,$ff, $80,$ff, $01,$ff, $80,$ff, $01,$ff, $80,$ff, $01,$ff, $00,$ff -TilesEnd: +.End: +; ANCHOR_END: tiles SECTION "Tilemap", ROM0 +; ANCHOR: tilemap Tilemap: db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0 db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0 @@ -165,4 +168,5 @@ Tilemap: db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0 db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0 db $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, 0,0,0,0,0,0,0,0,0,0,0,0 -TilemapEnd: +.End: +; ANCHOR_END: tilemap diff --git a/src/part1/memory.md b/src/part1/memory.md index ccb70fa4..02bbc7da 100644 --- a/src/part1/memory.md +++ b/src/part1/memory.md @@ -95,6 +95,11 @@ Writing out a label's name is equivalent to writing the address of the byte it's For example, consider the `ld de, Tiles` at line {{#line_no_of "ld\s+de\s*,\s*Tiles" ../assets/hello-world.asm}}. `Tiles` (line {{#line_no_of "^\s*Tiles:" ../assets/hello-world.asm}}) is referring to the first byte of the tile data; if we assume that the tile data ends up being stored starting at $0193, then `ld de, Tiles` is equivalent to `ld de, $0193`! +There's a shorthand for writing *local* labels: start their name with a dot `.` and it will implicitly be prefixed with the name of the most recent non-local label. +For example, consider the two `.End:` labels at lines {{#line_no_of "^\.End:" ../assets/hello-world.asm:tiles}} and {{#line_no_of "^\.End:" ../assets/hello-world.asm:tilemap}}. +The first one is implicitly defining "`Tiles.End:`" because of the non-local `Tiles:` label before it on line {{#line_no_of "^\s*Tiles:" ../assets/hello-world.asm}}, and the second one is defining "`Tilemap.End:`" because of the non-local `Tilemap:` label on line {{#line_no_of "^\s*Tilemap:" ../assets/hello-world.asm}}. +Local labels are useful because as your project gets larger, you'll need more and more very similar names, and it would be tedious to have to make up unique prefixes for them everywhere. + ## What's with the brackets? Right, we came into this because we wanted to know what the brackets in `ld a, [de]` mean. @@ -128,7 +133,7 @@ So, if we look at the first two instructions of `CopyTiles`: ...we can see that we're copying the byte in memory *pointed to* by `de` (that is, whose address is contained in `de`) into the byte pointed to by `hl`. Here, `a` serves as temporary storage, since the CPU is unable to perform `ld [hl], [de]` directly. -While we're at this, let's examine the rest of `.copyTiles` in the following lessons! +While we're at this, let's examine the rest of `CopyTiles` in the following lessons! ---