4.6.5 Symbolic Labels

A label is a symbolic alias that is assigned a value equal to the current address within the current psect. They can be used to represent a location in program memory, when they act like the name of a routine that can be called or jumped to, and they can be used to represent a location in data memory, hence act like the name of a variable or object. Labels are not assigned a value until link time.

A label definition consists of any valid assembly identifier that must be followed by a colon, :. The definition can appear on a line by itself or it can be positioned to the left of an instruction or assembler directive. Regardless of how they are defined, the assembler list file produced by the assembler will always show labels on a line by themselves.

Here are examples of legitimate labels interspersed with assembly code and used with memory reserved for a variable.

PSECT myCode,class=CODE,delta=2
start:
  movlw   1
  goto    fin
more:  clrf _input
  return
PSECT myDATA,class=BANK1,space=1
myVar:
  DS      2       ;2 bytes of storage, please

Here, the label start will ultimately be assigned the same address as the movlw instruction, and more, the same address as the clrf instruction. The label myVar will be assigned same address as the start address of the block of memory reserved by the DS directive.

Labels can be used (and are preferred) in assembly code, rather than using an absolute address with other instructions. In this way, they can be used as the target location for jump-type instructions or to load an program or data memory address into a register.

Like C variables, assembly labels have scope. By default, they can be used anywhere in the module in which they are defined. They can be used by code located in the source file before their definition. To make a label accessible in other modules, use the GLOBAL directive (see 4.9.29 Global Directive for more information).

The assembler will not output information relating to labels that do not use the GLOBAL directive, thus you will not see any such symbols appear in the map or symbol files, for example.