Program Structure

Macro Processing

Macro Processing

A macro is a user-defined word that is replaced by a sequence of instructions. Including a macro in a source program causes the sequence of instructions to be inserted into the program wherever the macro appears.

A user may define a word as a macro by using the .MACRO directive.

Detailed information about macro arguments, placement and redefinition of macros, nested macro definitions, and nested macro calls is in “Assembler Directives and Pseudo-Operations” on page 53.

Defining New Instructions With Macros

If you are testing new CPUs or coprocessors, you may need to use opcodes that are unknown to the Assembler. A variant of a macro definition may be used to create a mnemonic for the instruction. After being defined, the new mnemonic instruction can be invoked as easily as a standard instruction.

Opcodes, subopcodes, completers, and operands are encoded into the instruction word in a bit-intensive manner because all PA-RISC instructions are one word, or 32-bits, in length.

To write a macro, you must specify explicitly which bit fields are to contain constants and which are to contain macro arguments. The macro processor has no built-in knowledge of instruction formats. Defining new instructions through macros is only possible because a convenient way to delimit bit fields has been provided. It is up to the programmer to choose the correct bit field.

Bit positions within the 32-bit word are numbered from zero to 31, from left to right. A bit range is indicated by the starting bit position followed by the ending bit position. The two bit positions are separated by two periods and enclosed in braces. The bit field beginning at bit position 6 and ending at bit position 10 is represented as:

{6..10}

If the bit field being assigned from is bigger than the bit field being assigned to, then a warning is issued and the assigned-from bit field is truncated on the left. When no bit field is specified for the assigned-from

Chapter 2

37