HPlogo HP Assembler Reference Manual: HP 9000 Computers > Chapter 2 Program Structure

Macro Processing

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

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 Chapter 4 “Assembler Directives and Pseudo-Operations”.

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 value, low-order bits are used until the value of the assigned-from bit field becomes the same as the width of the assigned-to bit field. The assigned-to bit field must always be specified.

No sign extension is provided by the macro assembler when bit fields are generated.

The following macro definition defines the macro PACK with four formal parameters.

PACK    .MACRO            BASE,GREG,SREG,OFFSET
{0..5}=0x3E{26..31}
{6..10}=BASE{27..31}
{11..15}=GREG{27..31}
{16..17}=SREG{30..31}
{18..31}=OFFSET{18..31}
.ENDM

The following explanation assumes that PACK is invoked with the statement:

        PACK    %sp,%r19,%sr0,-52

Title not available (Defining New Instructions With Macros)

Bit Field

Description

{0..5}

Contains the six low-order bits of the new opcode 0x3E, or binary 111110, entered as a constant in the macro definition.

{6..10}

Contains general register 30, or binary 11110. These are the five low-order bits of the argument BASE in the macro definition.

{11..15}

Contains general register 19, or binary 10011. These are the five low-order bits of the argument GREG in the macro definition.

{16..17}

Contains space register 0 and represents the five low-order bits of the argument SREG in the macro definition.

{18..31}

Contains binary 11111111001100, the OFFSET value -52, which was entered as an argument to the macro definition.

© 1998 Hewlett-Packard Development Company, L.P.