You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/part1/memory.md
+6-1Lines changed: 6 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,11 @@ Writing out a label's name is equivalent to writing the address of the byte it's
95
95
For example, consider the `ld de, Tiles` at line {{#line_no_of "ld\s+de\s*,\s*Tiles" ../assets/hello-world.asm}}.
96
96
`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`!
97
97
98
+
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.
99
+
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}}.
100
+
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}}.
101
+
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.
102
+
98
103
## What's with the brackets?
99
104
100
105
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`:
128
133
...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`.
129
134
Here, `a` serves as temporary storage, since the CPU is unable to perform `ld [hl], [de]` directly.
130
135
131
-
While we're at this, let's examine the rest of `.copyTiles` in the following lessons!
136
+
While we're at this, let's examine the rest of `CopyTiles` in the following lessons!
0 commit comments