Assembly Language Fundamentals

Beginner
Version:
1.1

Labels

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

What Is a Label?

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

How to Write a Label

Labels must follow strict rules:

  1. The name must be six or fewer characters
  2. It must be followed immediately by a colon (:)
  3. You must write exactly one space after the colon
  4. Do not use spaces inside the label name

Valid Labels

LOOP:
TEST:
NXTXCH:

Invalid Labels

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

Example Program Using Labels

        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

What This Program Does

  1. Loads 83 (ASCII 'S') into A
  2. Jumps to the NXT label
  3. Adds 1 to A, then prints it using RST 8 and DEFB 158
  4. Jumps to END, where the program finishes

The program is readable and flexible. You never need to know the actual memory location of NXT — the assembler works it out

Where to Place Labels

Always put the label on its own line, aligned with the left margin

Example:

LOOP:   DEC C
        JR NZ, LOOP

Summary

Previous Module
Next Module