5. Running the MCDS COSM AC Resident Assembler (CRA)
31
Text constants:
A text constant is specified using the
form:
T’cc...cc’
(For example, TTHIS IS TEXT )
where each c is any printable character, including
space. Each character is converted to its ASCII code
equivalent (see Appendix F) and is represented in one
byte. Characters that have no graphic associated with
them (i.e., ETX, DC-3, CR, LF, etc) should not be
used within a text constant. Entering an apostrophe
within a text constant is treated specially, however. See
“Additional Notes” below.
Address Constants
The programmer finds it useful to specify not only
explicit or absolute constants, but also derived
constants whose values are assigned o r “computed” by
the assembler. Because the fundamental function of
the assembler is to assign address values, such
constants are normally called address constants. For
CRA, an address constant has one of the following
forms:
Examples:
1) A(expression)
A(GEORGE + 2)
2) A.1 (expression)
A.l(LOOP)
3) A.O(expression)
A.0(*-X’10’)
where the permissible forms for an expression have
already been defined. For all cases, the resulting
constant is derived by first evaluating the expression.
In the first case, the two-byte result is the constant. In
the second case, only the upper byte is used; for the
third case, only the lower byte. For all cases, the
resulting one- or two-byte value is assembled directly
into the code output.
Operation Mnemonics
CRA uses special two-, three-, and four-character
mnemonics to represent the various instructions inthe
COSMAC instruction set. These mnemonics are listed
in Appendix E. When CRA determines that an
operation is being specified, it looks it up in a table to
determine the code equivalent of the mnemonic. (Note
that this table is not the symbol table, which contains
only programmer-defined symbols.) Thus, use of an
operation mnemonic effectively defines an explicit hex
code value to be inserted into the object stream.
Instructions and Operands
There are two types of output code-producing
statements:
instructions
and
data lists.
An instruction
begins with an instruction operation mnemonic. In
some cases (such as IDL, RET, LDX, etc.) this
mnemonic is all that needs to be specified. In most
cases, however, the operation mnemonic must be
followed by an operand. The form of the operand (i.e.,
the additional information which the programmer
needs to supply to fully define the instruction) depends
on the type of instruction. The four operand forms
follow.
Register operands:
Many instructions (e.g., INC,
LDA, etc.) include a hex digit identifying one of the
scratchpad registers. The operand field in such a
statement may include either a single hex digit, or a
symbol. For the last case, CRA uses the least
significant hex digit of the symbol’s value in the symbol
table as the register identifying field.
Examples:
DEC 9
LDA RF
PLO SAVE
(“SAVE=OF” could have previously defined SAVE.)
I/O device operands.
The instructions OUT and
INP
require a device-identifying field. The operand in such
a statement may be a single digit in the range 1 to 7, or a
symbol. Again, for the latter case, a symbol table
lookup occurs, using the least significant hex digit of
the symbol’s value (checking also that it is within the
appropriate range).
Examples:
OUT 4
INP READER
Branch addresses:
Every branch instruction reqiiires
an operand specifying the branch address. If the
mnemonic is a short branch, a one-byte operand is
generated. A two-byte operand is generated if the
mnemonic is a long branch. Whenever CRA sees a
branch operation mnemonic, it expects to next find an
operand in the form of an expression. The acceptable
forms for expressions have already been defined. In
case of a short branch, CRA evaluates the expression
by getting a two-byte address, checks that this address
is within the current 256-byte page by examining the
upper byte, and uses the lower byte as the second byte
in the instruction. For a long branch, the upper byte
represents the page number, and the lower byte is the
address within that page.
Examples:
If A(LABEL) is #6789
BZ LABEL
generates
#3289
and LBZ LABEL
generates
#C26789
Immediate operands:
Several instructions include a
second byte as an immediate argument. The operand
field in such a statement may be any one-byte constant
(i.e., an absolute or explicit constant or an address
constant) or a symbol. For the latter case, CRA uses
the least significant byte of the symbol’s assigned
value.
Examples:
XRI X’FF’
ADI INCREM
LDI A.0(*)
Note:
When an immediate argument is specified, it is
the programmer’s responsibility to make sure that it is