BitMagic The Complete Development Environment for the Commander X16.

Labels

A label is a name for a point in your code or data. Use it as the target of a branch or jump, or in an expression like any other constant.

A label goes on its own line: a single word starting with . and ending with :, with nothing but whitespace before the .. A comment may follow the :; anything else on the line, an instruction included, is dropped without warning.

.start:
    inx
    bne start

A label belongs to the scope it is defined in, so a label inside a .proc is private to that procedure. Forward references are fine; the compiler resolves them in a later pass.

Labels in expressions

As long as a label is defined only once, it can be used in an expression like any other constant:

.byte $00
.loop:
    inc loop-1
    bne loop        ; loops 256 times

loop-1 is the address of the .byte just before the label. inc loop-1 bumps that byte each pass, and bne loop keeps going until it wraps back to zero.

Repeated labels

The same label name can be defined more than once. This is meant for flow control. A repeated label cannot be used in an expression, and using its bare name is an error because it is not unique.

To reference one, prefix it with + or - for the direction to search, relative to the current line:

  • -name is the nearest name at or before this line.
  • +name is the nearest name at or after this line.

Repeat the prefix to step further: --name is the second match backwards, ++name the second forwards.

.loop:          ; A
    ; ...
.loop:          ; B

    bne -loop    ; B
    bne --loop   ; A
    bne +loop    ; C
    bne ++loop   ; D
    bne loop     ; error, not unique

.loop:          ; C
    ; ...
.loop:          ; D

Anonymous labels

A label with no name, just .:, is an anonymous label. Reference the nearest one with a bare - or + (no name), following the same direction and repeat rules.

Unlike a named label, .: may share its line with an instruction:

.: dex
   bne -            ; back to the anonymous label