Labels are strings of text (without spaces or punctuation) that let you refer to lines of code, or data, by a name instead of a number.

When the code is assembled, it is all converted to numbers. That means that if you want to refer to some graphical data, for example, or a code routine, by the time it comes to the machine code, that location is merely a memory address in the ROM or RAM. However, when you’re writing the code you don’t want to pre-choose these addresses; you’d rather have the assembler figure out where to put everything, and then fill in the addresses accordingly.

That means that instead of this:

; load data
ld hl,$100
call $200

...

.org $100
.incbin "data.bin"

...

.org $200
; Data loading function...

...you can have

; load data
ld hl,SomeData
call LoadData

...

SomeData:
.incbin "data.bin"

...

LoadData:
; Data loading function...

The assembler will include all the code and data, assemble it together into the output (with placeholders for the addresses), then go back and fill in the placeholders with the actual addresses. We don’t need to remember which thing is at which address.


< Directives | Lesson 1 | Opcodes >