Problems related to lexical similarities between labels and macros

Beware, the lexical definition of a label is identical to that of a macro. The context of the first occurance of a label or 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 defined as a macro.

Potential problems with labels and macros

Because of the way a label can be indentifieded, it is possible for an undefined macro to be mistaken for a label. If the macro is subsequently defined after its use, a strange inexplicable error message may be observed by the programmer. The error may be further complicated by parameters supplied to the macro.

error scenario 1

	fred

fred	.macro
	movlw	25
	.endm

bert	movlw	26
Here we get a strage error that indicates that bert is redefined, we see no reason why this is the case. In fact what has happened is that during the first pass, fred was interpreted as a label because the macro definition was not processed before the firt use of the macro fred. Then during the second pass fred was expanded as a macro, effectively inserting a 'movlw 25' instruction into pass 2 where there was none in pass 1. Consequently the label bert is defined in a different place in pass 1 and pass 2.
error scenario 2

	fred	jack

fred	.macro	arg
	movlw	arg
	.endm
Here we get a strage error that indicates that jack is not a valid opcode, we see no reason why this is the case. In fact what has happened is that during the first pass, fred was interpreted as a label because the macro definition was not processed before the firt use of the macro fred. Jack was then interpreted as the opcode that followed the label fred.

See also example of obscure problems related to lexical similarities between labels and assembler variables