LABELS

Labels are symbolic identifiers that refer to locations or constants in the assembly program source code. Usually labels are assigned a number by the assembler as the assembler processes the source code (sometimes the numbers are assigned by the user before the assembler starts processing the source code). References to program code or data locations using symbolic labels instead of explicit numbers allows the programmer great flexibility while writing or modifying assembler source code. Primarilly because the programmer does not have to contend with a constantly growing and shrinking program which would require that the programmer constantly change many explicit location references by hand.

Symbolic label references verses direct address references

XCASM goes one step further by allowing the programmer to dynamically generate labels depending on the executable code emitted by the assembler. Assembler variables are a very important component of this facility. With them, the programmer can indicate to the assembler that a reference exists and that the exact label will be specified in pass 2.

LABELS - Lexical Definition
Labels are symbols consisting of sequences of alphanumeric characters and the underscore character. Labels must begin with an alpha character. Alpha characters are any of the characters a to z (upper or lower case). Alphanumeric characters are any of the alpha characters and any of the numeric characters 0 to 9. The underscore character is the '_' character.

Labels can be any length and all characters are significant (not just the first 8, 16 or 32 as with some other assemblers).

Valid labels are:

	Brown_Fox
	fred
	bert
	bert2

Invalid labels are:

	2bert			does not start with alpha character, '2' is
				a numeric character which is an illegal start
				of label character

	_fred			does not start with alpha character, '_' is
				illegal start of label character

	Brown Fox		contains illegal character ' '

	J.3			contains illegal character '.'
Case in labels is significant e.g. fred and Fred are considered different labels. Care must be taken when using mixed case labels since it is possible to use similar labels that cause confusion and introduce bugs into an assembly program.

Consider the following:

A program is originally written that uses the runtime variable Delay. Sometime later the program is modified and a new runtime variable delay is used. Sometime later still the program is again modified and the variable delay or Delay is used without care for the case used. Tracking down a bug related to this kind of mistake is difficult, time consuming and totally unnecessary.

As a rule make labels easily distinquishable and do not rely on case differences. Use long label names if appropriote such as:

led_on_delay
led_off_delay
instead of
delay1
delay2
Amoungst other things this will reduce the amount of commentry needed in the program.
Label Definition Syntax
Labels can be defined almost anywhere in the assembler source by simply placing them on a line before a machine code mnemonic, a macro invocation or one of several special assembler statements. Such a label takes the value of the current location counter (BEWARE this may be a count of bytes or words depending on the type of addressing used by the processer - see notes on location counter)

Label definitions do not have to occure at the start of a line, they can be indented. This allows nested conditional label definitions to be indented and helps make the source code easier to read.

e.g.
	fred	movlw	25		; here fred is defined, it refers to the
					; address of the 'movlw 25' instruction

	a_long_label_name		; here a_long_label_name is defined on
		movlw	26		; a line on its own, it refers to the
					; address of the 'movlw 26' instruction

	fred1
	fred2
	fred3	movlw	27		; here fred1, fred2 and fred3 are defined,
					; they all refer to the address of the
					; 'movlw 27' instruction

Using dynamic labels is accomplished via assembler variables
e.g.
	fred	.set	bert		; here fred is defined as an assembler
					; variable and bert is a label

	fred	movlw	26		; here fred refers to the label bert
					; which is defined and refers to the
					; address of the 'movlw 26' instruction

it is equivalent to the statement

	bert	movlw	26

a more complex use of a dynamic label would be

Resolving strange label related assembler errors

Beware, the lexical definition of a label is identical to that of an assembler variable and a macro. The context of the first occurance of a label, assmebler variable and macro determins the assemblers subsequent interpretation of that symbol. Problems occure where the symbol is first seen in the context of a label and subsequently used as an assembler variable or defined as a macro.

Example of obscure problems related to lexical similarities between labels and assembler variables, and labels and macros