SLAU131Y October 2004 – June 2021
Define Assembly-Time Constant
symbol .set value
symbol .equ value
The .setand .equ directives equate a constant value to a .set/.equ symbol. The symbol can then be used in place of a value in assembly source. This allows you to equate meaningful names with constants and other values. The .set and .equ directives are identical and can be used interchangeably.
Undefined external symbols and symbols that are defined later in the module cannot be used in the expression. If the expression is relocatable, the symbol to which it is assigned is also relocatable.
The value of the expression appears in the object field of the listing. This value is not part of the actual object code and is not written to the output file.
Symbols defined with .set or .equ can be made externally visible with the .def or .global directive (see the .global/.def/.ref topic). In this way, you can define global absolute constants.
This example shows how symbols can be assigned with .set and .equ.
1 *****************************************************
2 ** Equate symbol ACCUM to register R11 and use **
3 ** it instead of the register. **
4 *****************************************************
5 000B ACCUM .set R11
6 0000 401B MOV 0x56, ACCUM
0002 0054
7
8 *****************************************************
9 ** Set symbol INDEX to an integer expression **
10 ** and use it as an immediate operand. **
11 *****************************************************
12 0035 INDEX .equ 100/2 + 3
13 0004 503B ADD #INDEX, ACCUM
0006 0035
14
15 *****************************************************
16 ** Set symbol SYMTAB to a relocatable expression **
17 ** and use it as a relocatable operand. **
18 *****************************************************
19 0008 000A LABEL .word 10
20 0009! SYMTAB .set LABEL + 1
21
22 *****************************************************
23 ** Set symbol NSYMS equal to the symbol INDEX **
24 ** and use it as you would INDEX. **
25 *****************************************************
26 0035 NSYMS .set INDEX
27 000a 0035 .word NSYMS