Reference Guide
Chapter 2 35
Program Structure
Operands and Completers
Operands and Completers
Machine instructions usually require one or more operands.
These operands tell the processor what data to use and where to store
the result. Operands can identify a register, a location in memory, or an
immediate constant (that is, data that is coded into the instruction
itself). The operation code determines how many and what kinds of
operands are required.
Registers used in operands should be either predefined register symbols
(with the % prefix) or user-defined register symbols defined with the .REG
directive. They can also be absolute expressions. See “Registers and
Register Mnemonics” on page 23 in this chapter.
The following example shows a few machine instructions with register
operands:
SCRATCH .REG %r18 ;define register SCRATCH
ADD %r3,%r7,%r4 ;r3 + r7 -> r4
OR %r7,%r3,%r8 ;inclusive or of r7,r3 -> r8
COPY SCRATCH,%r7 ;copy r18 to r7
MTCTL %r2,%sar ;set shift amount register (cr11)
MFSP %sr4,%r10 ;fetch contents of sr4
Operands designating memory locations usually consist of an expression
and a general register used as a base register. Some instructions also
require a space register designation. In general, such operands are
written in the form expr(sr,gr) or expr(gr), as in the following
examples:
local_off .EQU -64
LDW 4(%dp),%r2
STW %r0,local_off-4(%sp)
LDW 0(%sr3,%r2),%r9
Notice that the space register can be omitted on instructions that allow
short addressing, as in the STW instruction shown above.
If only one register is given, it is assumed to be the general register, and
the space register field in the machine instruction is set to zero, which
indicates short addressing.
The expression in a memory operand is either absolute or relocatable.
Absolute expressions are meaningful when the base register contains the
address of an array, record, or the stack pointer to which a constant offset