As your programs grow, manually calculating jump addresses (like JP 272) becomes tedious and error prone. Assembly language provides a powerful solution: labels.
Labels make your code:
In this lesson, you’ll learn what labels are, how to use them, and why they matter so much
A label is a symbolic name for a specific line in your program.
Instead of writing:
JP 262
You can write:
JP NXT
The assembler automatically replaces NXT with the correct address. This means you never have to manually track memory addresses, which makes your code more maintainable
Labels must follow strict rules:
LOOP:
TEST:
NXTXCH:
LOOP : ; space before colon — invalid
BACKONE: ; too long — invalid
NEXT L: ; contains a space — invalid
If you break these rules, the assembler will generate an error
ORG 256
LD A, 83 ; Load ASCII code for 'S'
JP NXT ; Jump to the label NXT
END: RET ; Return to BASIC
NXT: ADD A, 1 ; Increment A
RST 8 ; Print the character
DEFB 158
JP END ; Jump to the end
The program is readable and flexible. You never need to know the actual memory location of NXT — the assembler works it out
Always put the label on its own line, aligned with the left margin
Example:
LOOP: DEC C
JR NZ, LOOP