I am trying to figure out the syntax to assign a computed constant to a constant. I want to assign the fixed value 13 to JACK. I tried as follows:
FRED EQU 6
JOE EQU 7
JILL EQU FRED+JOE
JACK DC F(JILL)
END
But I got an invalid delimiter. I can see that JILL is indeed 13, and if I make this
FRED EQU 6
JOE EQU 7
JILL EQU FRED+JOE
JACK DC A(JILL)
END
it 'works', but I want JACK to be a full word, not an address (I guess it's 4 bytes in either case, but it seems like 'false advertising')
Your second method is valid, and there is nothing wrong with it.
EQUs are 'kind-of' addresses when you take into consideration that we use the LA Rx,EquLabel
instruction - which is a Load Address (syntactically, at least) - to load its value, and we use EQU *
for the current (relative) address in assembly code. Nevertheless, they are plain integer values in the end. We also use EQU to define aliases for register numbers as in R15 EQU 15
.
A plain JACK DC A(Jill)
does the same as defining a full-word.
N.b. You can also define other lengths using AL1
, AL2
, and AL3
. The invalid delimiter in JACK DC F(JILL)
is issued because DC F
requires quotation marks as value delimiters, not parentheses, but the quotation marks keep the assembler from replacing the EQU label with its value, so we can't use an equ to define a fullword, or any other type except an address constant for that matter.
A(Label)
- with parentheses instead of quotation marks - is kind of an "emergency exit" for cases like yours; I personally would still code FRED DC F'6'
and JOE DC F'7'
, which is more straightforward.