HPlogo HP Assembler Reference Manual: HP 9000 Computers

Chapter 2 Program Structure

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

An assembly language program is a sequence of statements. There are three classes of statements:

  • Instructions

  • Pseudo-operations

  • Directives

Instructions represent a single machine instruction in symbolic form. Pseudo-operations cause the Assembler to initialize or reserve one or more words of storage for data, rather than machine instructions. Directives communicate information about the program to the Assembler, but do not generally cause the Assembler to output any machine instructions.

An assembly statement contains four fields:

  • Label

  • Opcode

  • Operands

  • Comments

Each of these fields is optional. However the operands field cannot appear without an opcode field.

The label field is used to associate a symbolic address with an instruction or data location, or to define a symbolic constant using the .EQU, .REG, or .MACRO directives. This field is optional for all but a few statement types; if present, the label must begin in column one of a source program line. If a label appears on a line by itself, or with a comment only, the label is associated with the next address within the same subspace and location counter.

When the label field begins with the pound sign (#) character, it is not treated as a label. If # is followed by white space and an integer, the Assembler's line number counter, used when reporting errors, is reset to the value of the integer. Otherwise, the line beginning with # is ignored. This feature is for the use of the C language preprocessor cpp.

The opcode field contains either a mnemonic machine instruction, a pseudo-operation code, or the name of an Assembler directive. It must be separated from the label field by a blank or tab. For certain machine instructions, the opcode field can also contain completers, separated from the instruction mnemonic by commas.

The machine instruction mnemonics and completers are described in the PA-RISC 1.1 Architecture and Instruction Set Reference Manual and PA-RISC 2.0 Architecture.

The operands field follows the opcode field, separated by a blank or tab. Operands are separated by commas. The meaning of the operands depends on the specific statement type, determined by the opcode.

The number of operands permitted or required depends upon the specific instruction.

The comments field is introduced with a semicolon, and causes the Assembler to ignore the remainder of the source line. A comment can appear on a line by itself.

The following listing contains several assembly language statements. The headings identify the four fields.

Label

Opcode

Operands

Comments

JAN

.EQU

1

;declares a symbolic constant

SUM

.WORD

0

;reserve a word and set to zero

LOOP

LDW

4(%r1),%r2

 

ADD

%r2,%r3,%r4

 

STW

%r4,SUM-$global$(%dp)

 

BL

LOOP,%r0

 

Statements are normally written on separate lines. It is sometimes useful, especially when using a macro preprocessor, to be able to write several statements on one line. This can be done by separating the statements with the "!" character. When this feature is used, a label can be placed only on the first statement of the line, and a comment can only follow the last statement on the line. The .LABEL directive can override this condition by providing a means for declaring a label within a multi-statement line.

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