Using Equates

The width and position parameters of the "field" statement can be rather difficult to keep track of if the number and position of your fields changes often. (This is sometimes the case during ROM development.) The "equ" statement can be used to simplify the process of adding new fields, and changing the size of existing ones. Suppose you have the following three fields, declared as in the previous section.
flda: field width=3,position=0

fldb: field width=4,position=3

fldc: field width=7,position=7


If you want to add a field between flda and fldb, you must change the position of fldb and fldc. The same is true if you change the size of flda. The following is the same three fields coded with equates.
flda: field width=awid,position=apos

fldb: field width=bwid,position=bpos

fldc: field width=cwid,position=cpos

awid: equ 3

bwid: equ 4

cwid: equ 7

apos: equ 0

bpos: equ awid+apos

cpos: equ bwid+bpos

Using this technique, one need only concern oneself with the width and the order of each field. Positions are calculated automatically by the preprocessor.

The right hand side of an equate may be an arbitrary expression involving constants; the names of other equates; the operators +, -, *, and /; and parenthesis. The order of the equate statements does not matter, as long as they do not reference one another cyclically. Expressions may also be used to specify field widths and positions, as illustrated below.
flda: field width=awid,position=0

fldb: field width=bwid,position=bpos

fldc: field width=awid+bwid,position=bwid+bpos

awid: equ 3

bwid: equ 4

apos: equ 0

bpos: equ awid+apos

This example illustrates the rule that any place a number is acceptable, an expression is also acceptable.