HP Assembler Reference Manual
HP Assembler Reference Manual
HP Assembler Reference Manual
HP 9000 Computers
9th Edition
92432-90012
June 1998
2
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Printing History. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Audience. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
Related Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
Typographical Conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
In This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
Summary of Technical Changes for HP-UX 11.0 . . . . . . . . . . . . . . . . . . .14
2. Program Structure
Symbols and Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21
Registers and Register Mnemonics . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Parenthesized Subexpressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
Operands and Completers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35
Macro Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
Defining New Instructions With Macros. . . . . . . . . . . . . . . . . . . . . . . .37
3
Contents
Directives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Sections in 64-bit Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Location Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Compiler Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Shared Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Assembly Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4
Contents
5
Contents
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
.ENDM Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
.ENTER and .LEAVE Pseudo-Operations . . . . . . . . . . . . . . . . . . . . . . . 81
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
.ENTRY and .EXIT Directives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
.EQU Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
.EXPORT Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
.FLOAT Pseudo-Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
.HALF Pseudo-Operation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
6
Contents
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .89
.IMPORT Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .90
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .91
.LABEL Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .92
.LEVEL Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .93
.LISTOFF and .LISTON Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .95
.LOCCT Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .97
.MACRO Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
Examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99
.ORIGIN Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .101
7
Contents
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
.PROC and .PROCEND Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
.REG Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
.SHLIB_VERSION Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
.SPACE Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
.SPNUM Pseudo-Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
.STRING and .STRINGZ Pseudo-Operations . . . . . . . . . . . . . . . . . . . . 109
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
8
Contents
Examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110
.SUBSPA Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .113
.VERSION Directive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114
.WORD Pseudo-Operation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115
Programming Aids. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116
5. Pseudo-Instruction Set
9
Contents
7. Programming Examples
1. Binary Search for Highest Bit Position. . . . . . . . . . . . . . . . . . . . . . . 130
2. Copying a String. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
3. Dividing a Double-Word Dividend. . . . . . . . . . . . . . . . . . . . . . . . . . . 134
4. Demonstrating the Procedure Calling Convention . . . . . . . . . . . . . 136
C Program Listing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Assembly Program Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
5. Output of the cc -S Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
C Program Listing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Assembly Program Listing From the C Compiler . . . . . . . . . . . . . . . 138
8. Diagnostic Messages
Warning Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Error Messages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Panic Messages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
User Warning Messages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Limit Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Branching Error Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
10
Preface
This manual describes the use of the Precision Architecture RISC
(PA-RISC) Assembler on HP 9000 computers.
You need to be familiar with the machine instructions to use the
Assembler. For a complete description of the machine instruction set,
refer to PA-RISC 1.1 Architecture and Instruction Set Reference Manual
and PA-RISC 2.0 Architecture.
Note that, throughout this manual, there are references to PA-RISC 1.0,
1.1, and 2.0. Each version of the architecture is a superset of the
preceding version.
Any program written for PA-RISC 1.0 machines will execute on PA-RISC
1.1 and 2.0 machines, but programs using instructions unique to
PA-RISC 1.1 will not execute on PA-RISC 1.0 machines. Any program
written for PA-RISC 1.1 machines will execute on PA-RISC 2.0
machines, but programs using features unique to PA-RISC 2.0 will not
execute on PA-RISC 1.1 or 1.0 machines.
Printing History
New editions are complete revisions of the manual. Technical
addendums or release notes may be released as supplements.
The software version is the version level of the software product at the
time the manual was issued. Many product updates and fixes do not
require manual changes and, conversely, manual corrections may be
done without accompanying product changes. Therefore, do not expect a
one-to-one correspondence between product updates and manual
updates.
Software
Edition Date
Version
11
Software
Edition Date
Version
You may send any suggestions for improvements in this manual to:
Languages Information Engineering Manager
Hewlett-Packard Company
Mailstop 42UD
11000 Wolfe Road
Cupertino CA 95014-9804
Electronic Mail: [email protected]
Audience
This manual assumes that you are an experienced assembly language
programmer. In addition, you should have detailed understanding of the
PA-RISC and hardware features, and a working knowledge of the HP-UX
operating system, program structures, procedure calling conventions,
and stack unwind procedures.
Related Documentation
For more information on HP-UX programming, refer to the following
documents:
12
• HP-UX Linker and Libraries Online User Guide, (ld +help)
• 64-bit Runtime Architecture for PA-RISC 2.0. URL:
http://www.software.hp.com/STK/
• ELF 64 Object File Format. URL: http://www.software.hp.com/STK/
Typographical Conventions
Unless otherwise noted in the text, this manual uses the following
symbolic conventions.
In This Manual
The manual is organized as follows:
Chapter 1 Introduces the Assembler for HP 9000 computers.
Chapter 2 Explains assembly language program structure.
13
Chapter 3 Explains programming in Assembler for HP-UX.
Chapter 4 Describes the PA-RISC Assembler directives and
pseudo-operations.
Chapter 5 Summarizes the pseudo-instructions for the PA-RISC
machine instructions.
Chapter 6 Describes the assembly (as) command and the ways to
invoke the PA-RISC Assembler under the HP-UX
operating system.
Chapter 7 Contains several sample assembly language programs.
Chapter 8 Lists the diagnostic messages that the PA-RISC
Assembler can generate.
• In 64-bit mode, the linkage pointer register is %r27. See Table 2-11,
“Available Field Selectors,” on page 31.
• In 64-bit mode, the Executable and Linking Format (ELF) uses
segments and sections rather than spaces and subspaces. See
“Sections in 64-bit Mode” on page 44.
• The Assembler ignores the .CALL directive. This means that your
program must ensure that the caller and called procedure agree on
argument locations. See “.CALL Directive” on page 63.
• The .CALLINFO directive parameters include updates to support
64-bit mode.
• You can specify 2.0W with the .LEVEL directive to tell the the
Assembler to generate 64-bit object code. For details, see “.LEVEL
Directive” on page 93.
• New and changed Assembler error messages. For details, see Chapter
8, “Diagnostic Messages,” on page 141.
14
1 Introduction to PA-RISC
Assembly Language
The HP 9000 Assembly Language represents machine language
instructions symbolically, and permits declaration of addresses
symbolically as well. The Assembler's function is to translate an
assembly language program, stored in a source file, into machine
language. The result of this translation resides in a relocatable object file.
The object file is relocatable because it can still be combined with other
relocatable object files and libraries. Therefore, it is necessary to relocate
any addresses that the Assembler chooses for the symbols in the source
program.
This process of combining object files and libraries is performed by the
linker, ld. The linker's task is to transform one or more relocatable
object files into an executable program file. Every program must be
linked before it can be executed, even if the source file is complete within
itself and does not need to be combined with other files.
Assembler Features
The Assembler provides a number of features to make assembly
language programming convenient. These features include:
15
Introduction to PA-RISC Assembly Language
Assembler Features
16 Chapter 1
Introduction to PA-RISC Assembly Language
Summary of Changes for PA-RISC 2.0
Chapter 1 17
Introduction to PA-RISC Assembly Language
Summary of Changes for PA-RISC 2.0W (Wide Mode, 64-bit)
You can explicitly use space registers, however, the Assembler issues
a warning if it is other than sr0.
• Some of the completers on ADDB and ADDIB instructions are not valid
for PA2.0W. In addition, new completers are available.
For example: ZNV, SV, and OD are not valid whereas *=, *<, and *<=
are additional completers.
Please refer to the PA-RISC 2.0 Architecture guide for details.
• The displacement on both general load/store and floating load/store
instructions can be up to 16 bits. For example,
ex: FLDD disp(b),tgt ; displacement can be up to 16 bits.
Please refer to PA-RISC 2.0 Architecture for details.
• You must change any .WORD directives that are initialized with a code
symbol or data symbol to .DWORD.
• You can not use space identification operations such as MTSP and
LDSID used for dealing with space registers in user level code.
Currently, the Assembler does not give any warning.
• The procedure calling conventions are different in the HP-UX
PA-RISC 2.0 64-bit architecture. In PA 2.0W, you can pass the first
eight parameters in registers (arg0-arg7). In earlier versions (PA1.0
and PA1.1) and on PA-RISC 2.0, you can only pass the first four
parameters in registers(arg0-arg3). For more information, please
refer to the 64-bit Runtime Architecture for PA-RISC 2.0, at URL:
http://www.software.hp.com/STK/.
18 Chapter 1
2 Program Structure
• 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.
19
Program Structure
20 Chapter 2
Program Structure
Symbols and Constants
Chapter 2 21
Program Structure
Symbols and Constants
Signed Unsigned
Decimal -2147483648 0
through through
2147483647 4294967295
Octal 020000000000 0
through through
017777777777 037777777777
Hexadecimal 0x80000000 0
through through
0x7FFFFFFF 0xFFFFFFFF
The period (.) is a special symbol reserved to denote the current offset of
the location counter. It is useful in address expressions to refer to a
location relative to the current instruction or data word. This symbol is
considered relocatable, and can be used anywhere a relocatable symbol
can be used, with the exception of the label field.
The period cannot be used in an expression involving another label, such
as sym+., sym-., .+sym, or .-sym. It can be used in an expression that
has only a constant, such as .+8 or .-8.
22 Chapter 2
Program Structure
Registers and Register Mnemonics
• General
• Floating-point
• Space
• Control
Data is loaded from memory into general or floating-point registers and
stored into memory from general or floating-point registers. Arithmetic
and logical operations are performed on the contents of the general
registers. On PA-RISC 1.0 or 1.1 each general register is 32 bits wide. On
PA-RISC 2.0 each general register is 64 bits wide. On PA-RISC 2.0W
(true 64-bit environment) each general register is 64 bits wide.
There are 32 general registers, denoted as %r0 through %r31. General
register %r0 is special because “writes” into it are ignored, and it always
reads as zero. The remaining general registers can be used normally,
with the caution that %r1 is the implicit target register for the ADDIL
instruction, %r31 is the implicit link register for the BLE instruction, and
for PA-RISC 2.0 only, %r2 is the implicit link register for the BLVE
instruction. Certain general registers also have predefined conventional
uses. Refer to “Register Procedure Calling Conventions” on page 28. You
can find detailed information on both 32-bit and 64-bit runtime
architecture under the topic PA-RISC Architecture at
http://www.software.hp.com/STK/.
PA-RISC 1.0 machines have 16 floating-point registers; PA-RISC 1.1, 2.0,
and 2.0W (true 64-bit environment) machines have 32 floating-point
registers. Each register is capable of holding either a single- or
double-precision floating-point number in IEEE format. These registers
are denoted %fr0 through %fr15 for PA-RISC 1.0 and %fr0 through
%fr31 for PA-RISC 1.1, 2.0, and 2.0W.
Registers %fr1, %fr2, and %fr3 are exception registers and are not
available to the programmer. Floating-point register %fr0 contains a
permanent floating-point zero when used in an arithmetic operation;
when written or read with floating-point loads or stores, the
floating-point status register is actually accessed.
Chapter 2 23
Program Structure
Registers and Register Mnemonics
In addition, on PA-RISC 1.1, 2.0. and 2.0W the left and right halves of
the floating-point registers can be accessed as separate single-precision
registers by using an L or R suffix.
For example, %fr8R accesses the right-most 32 bits of %fr8 as a
single-precision number.
The L or R suffixes can only be used on the predefined floating-point
registers in the form %frnn, where nn is the register number. It is not
legal to use L or R with an integer value. For example, %fr8R is legal; 8R
is not legal.
The space registers form the basis of the virtual memory system. Each of
the eight space registers can hold a 16- or 32-bit space identifier,
depending on the hardware model. The space registers are denoted as
%sr0 through %sr7. Space register %sr0 is set implicitly by the BLE
instruction, and space registers %sr5 through %sr7 cannot be modified
except by code running at the most privileged level.
The control registers contain system-state information. There are 25
control registers, denoted as %cr0 and %cr8 through %cr31. Of these
registers, only %cr11 (%sar), the shift amount register, and %cr16
(%itmt), the interval timer, are normally accessible to the user-level
programmer. The other registers are accessed only by code running at
the most privileged level.
Register operands are denoted by register-typed constants because the
Assembler needs to be able to differentiate between general registers,
space registers, floating point registers, and ordinary integer constants.
To make assembly code more readable, you can use the .REG directive to
declare a symbolic name as an alias for a predefined register. The
predefined registers have a register type associated with them. The
Assembler enforces register type checking and issues a warning message
if the wrong kind of register is used within an operand. A warning is also
issued when an integer constant or absolute expression is found where a
register is expected. You must use the .REG directive to define symbolic
register names. If a symbolic name defined in an .EQU directive is used
where a register symbol is expected, the Assembler issues a warning
message, because it considers an .EQU defined symbol to be a simple
integer constant.
24 Chapter 2
Program Structure
Registers and Register Mnemonics
Chapter 2 25
Program Structure
Registers and Register Mnemonics
26 Chapter 2
Program Structure
Registers and Register Mnemonics
Chapter 2 27
Program Structure
Registers and Register Mnemonics
28 Chapter 2
Program Structure
Expressions
Expressions
Arithmetic expressions are often valuable in writing assembly code. The
Assembler allows expressions involving integer constants, symbolic
constants, and symbolic addresses. These terms can be combined with
the standard arithmetic operators shown in “Standard Arithmetic
Operators” on page 29 or with bit-wise operators shown in “Bit-Wise
Operators” on page 29.
Table 2-8 Standard Arithmetic Operators
Operator Operation
+ Integer addition
- Integer subtraction
* Integer multiplication
Operator Operation
| Logical OR
Chapter 2 29
Program Structure
Expressions
Operation Result
For example, assume the symbols MONTH and YEAR are relocatable, and
JANUARY and FEBRUARY are absolute. The expressions MONTH+JANUARY
and MONTH+FEBRUARY-4 are relocatable, while the expressions
YEAR-MONTH and FEBRUARY-4 are absolute. The expression
MONTH+JANUARY*4 is also legal and produces a relocatable result,
because JANUARY*4 is evaluated first, producing an absolute
intermediate result that is added to MONTH. The expression MONTH+YEAR
is illegal, because the sum of two relocatable terms is not permitted.
Because all instructions are a single word in length, it is not possible to
form a complete 32-bit address in a single instruction. Therefore, it is
likely that the Assembler (or linker) may not be able to insert the final
address of a symbol into the instruction as desired. For example, to load
the contents of a word into a register, the following instruction could be
used:
LDW START,%r2
Because LDW provides only 14 bits for the address of START, the
Assembler or linker prints an error message if the address of START
requires more than 14 bits. There are two instructions, LDIL and ADDIL,
whose function is to form the left-most 21 bits of a 32-bit address. The
succeeding instruction, by using the target of the LDIL or ADDIL as a
30 Chapter 2
Program Structure
Expressions
base register, needs only 11 bits for the remainder of the address. The
Assembler provides special operators, called field selectors, that extract
the appropriate bits from the result of an expression. With the field
selectors L' and R', the previous example can be recoded as follows:
LDIL L'START,%r1 ;put left part into r1
LDW R'START(%r1),%r2 ;add r1 and right part
The field selectors are always applied to the final result of the
expression. They cannot be used in the interior of an expression.
“Available Field Selectors” on page 31 shows all the available field
selectors and their meanings.
Table 2-11 Available Field Selectors
Field
Meaning
Selector
Chapter 2 31
Program Structure
Expressions
Field
Meaning
Selector
LT' or LR% value offset of data linkage table slots from linkage
LT% table pointer. In 32-bit mode, the linkage table pointer is
%r19. In 64-bit mode, the linkage table pointer is %r27.
RT' or RR% value offset of data linkage table slots from linkage
RT% table pointer. In 32-bit mode, the linkage table pointer is
%r19. In 64-bit mode, the linkage table pointer is %r27.
32 Chapter 2
Program Structure
Expressions
Field
Meaning
Selector
On PA-RISC 1.0, the page size is 2048 bytes long; on PA-RISC 1.1, 2.0,
and 2.0W the page size is 4096. The selectors L', LS', and LD' modulate
by 2048, and the corresponding selectors R', RS', and RD' extract the
offset relative to that address.
The distinction is whether the offset is always positive and between 0
and 0x7ff (L'-R'), always negative and between -0x800 and -1
(LD'-RD'), or between -0x400 and 0x3ff (LS'-RS'). This
distinction is only important when using short addressing near a
quadrant boundary, because only the left part is used to select a space
register. Each pair is designed to work together just as L' and R' do in
the previous example. See “Spaces” on page 39. The LR' and RR'
prefixes are used for accessing different fields of a structure, allowing the
sharing of the LR' computation.
For shared libraries, the field selectors T', LT', RT', Q', LRQ', and RRQ'
are used in conjunction with the position-independent code options +z or
+Z.
The field selectors P', LP', and RP' are used to form plabels
(procedure labels) for use in dynamic calls. With position-independent
code, the use of plabel values, rather than simple code addresses, is
required. Refer to the HP-UX Linker and Libraries Online User Guide
and ELF 64 Object File Format, http://www.software.hp.com/STK/ for
more information.
For example, to get a procedure label for foo, use the following code:
ADDIL LTP'foo,%r27,%r1 ;get left portion of plabel pointer.
LDO RTP'foo(%r1),%r4 ;add right portion to form a complete
; plabel pointer.
The field selectors in the above example can also be written LP% and RP%.
Chapter 2 33
Program Structure
Expressions
Parenthesized Subexpressions
The constant term of an expression may contain parenthesized
subexpressions that alter the order of evaluation from the precedence
normally associated with arithmetic operators. For example:
LABEL1-LABEL2+((6765+(2048-1))/2048)*2048
contains a parenthesized subexpression that rounds a value up to a
multiple of 2048.
Absolute symbols may be equated to constant terms containing
parenthesized subexpressions as in the following sequence:
BASE .EQU 0x200
N_EL .EQU 24
SIZE .EQU (BASE+4)*N_EL
34 Chapter 2
Program Structure
Operands and Completers
Chapter 2 35
Program Structure
Operands and Completers
36 Chapter 2
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.
Chapter 2 37
Program Structure
Macro Processing
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
38 Chapter 2
3 HP-UX Architecture
Conventions
The Assembler is a flexible tool for writing programs, but every operating
system imposes certain conventions and restrictions on the programs
that are intended to run on that system. This chapter discusses the
conventions that must be understood in order to write assembly
language programs and procedures for the PA-RISC instruction set on
the HP 9000 Series 700 and 800 HP-UX operating system. Several
Assembler directives are mentioned in this chapter to place them in a
meaningful context. A full discussion of these directives is in Chapter 4,
“Assembler Directives and Pseudo-Operations,” on page 53.
Spaces
Virtual addressing on PA-RISC is based on spaces. A virtual address is
composed of a space identifier, which is either 16 or 32 bits long
(depending on the hardware model), and a 32-bit offset within the space.
Therefore, each space can contain up to 4 gigabytes, and there is a large
supply of spaces.
NOTE In the 64-bit mode architecture each application is provided a flat virtual
address space of 2** 64 bytes, which is divided into four quadrants. Each
quadrant is mapped into this global virtual address space by means of
four space registers, which are under the control of the operating
system.
39
HP-UX Architecture Conventions
Spaces
for the duration of program execution. The identifier of the code space is
placed in space register 4 (%sr4) and the identifier of the data space is
placed in space register 5 (%sr5).
When writing an assembly language program, declare a space named
$TEXT$ for executable code, and a space named $PRIVATE$ for
modifiable data. Constant data or literals that you do not plan to modify
during program execution, can be placed in either space. Placing
constant data in the $TEXT$ space decreases the size of the nonsharable
part of your program and improves the overall efficiency of the operating
system.
The particular space registers mentioned above play an important role in
virtual addressing. While many of the branching instructions, such as
BL, BLR, and BV, are capable of branching only within the currently
executing code space (called PC-space), two of the branching instructions,
BE and BLE, require that you specify a space register as well as an offset.
These instructions allow you to branch to code executing in a different
space. On HP-UX systems, normally all code for a program is contained
in one space, so all BE and BLE instructions should be coded to use %sr4.
In contrast, the memory reference instructions, such as LDW and STW,
allow a choice between two forms of addressing: long and short. With
long addressing, you can choose any of the space registers 1 through 3 for
the space identifier part of the virtual address. The space offset is formed
as the sum of an immediate displacement and the contents of a general
register. With short addressing, one of the space registers between 4
through 7 is chosen automatically, based on the high-order two bits of the
base register. Each space addressed by these four space registers is
effectively divided into four quadrants, with a different quadrant of each
space accessible via short addressing.
On HP-UX systems, all of a program's code is placed in quadrant zero of
the $TEXT$ space, or %sr4, (space offsets from 0 through 0x3FFFFFFF).
The data is placed in quadrant one of the $PRIVATE$ space, or %sr5
(space offsets from 0x40000000 through 0x7FFFFFFF). Therefore,
literal data in the code space and modifiable data in the data space can
be addressed using the short addressing technique, without any concern
for the space registers.
The identifier for shared memory segments, including shared library
text, is placed into space register 6 (%sr6). Shared memory and shared
library text are placed into quadrant two of the shared memory space
(offsets 0x80000000 through 0xBFFFFFFF). The identifier for system
40 Chapter 3
HP-UX Architecture Conventions
Spaces
code is placed into space register 7 (%sr7). System code is placed into
quadrant three of the system space (offsets 0xC0000000 through
0xFFFFFFFF). Table 3-1 on page 41 shows the memory layout on HP-UX.
Table 3-1 Memory Layout on HP-UX
0x00000000 Program
code
0x40000000 Program
data stack
Shared
library data
0x80000000 Shared
memory
Shared
library text
You can define spaces other than $TEXT$ and $PRIVATE$ in a program
file by declaring a special kind of space called an unloadable space.
Unloadable spaces are treated as normal spaces by the linker, but as the
name implies, are not actually loaded when a program is executed.
Unloadable spaces are typically used by compilers to store extra
information within a program file. The most common example of an
unloadable space is $DEBUG$, which is used to hold symbolic debugging
information.
The sort key attribute allows the programmer to control the placement of
a space relative to the other spaces. The linker places spaces with lower
sort keys in front of spaces with higher sort keys.
The .SPACE directive is used to declare spaces. The assembly language
programmer is not required to fill one space before beginning another.
When a space is first declared, the Assembler begins filling that space.
The .SPACE directive can also be used to return to a previously declared
space, and the Assembler continues to fill it as if there had been no
intervening spaces.
Chapter 3 41
HP-UX Architecture Conventions
Subspaces
Subspaces
While a space is a fundamental concept of the architecture, a subspace is
just a logical subdivision of a space. The Assembler places the program's
code and data into subspaces within spaces. Each subspace belongs to
the space that was current when the subspace was first declared. The
linker groups subspaces into spaces as it builds an executable program
file. For more details see the ld(1) entry in the HP-UX Reference. When
the linker combines several relocatable files, it groups the subspaces
from each file by name, so that all subspaces with the same name are
placed contiguously in the program.
Attributes
Subspaces have several attributes. The alignment attribute specifies
what memory alignment (in bytes) is required in the virtual address
space. The alignment can be any power of two, from 1 through 4096,
inclusive. Typically, the alignment is 4 or 8 to specify that the beginning
of the subspace must be word or double-word aligned. Normally, the
alignment attribute is computed automatically by the Assembler from
the largest .ALIGN directive used within the subspace.
The quadrant attribute assigns the subspace to one of the four quadrants
of its space. On HP-UX systems, all subspaces in the code space must be
in quadrant 0, and all subspaces in the data space must be in quadrant
1.
The access rights attribute specifies the access rights that should be
given to each physical page in the subspace. On HP-UX systems, all
subspaces in the code space must have access rights of 0x2C (code page
executable at any privilege level). All subspaces in the data space must
have access rights of 0x1F (data page readable and writable at all
privilege levels).
The sort key attribute allows the programmer to control the placement of
a subspace relative to the other subspaces in its space. The linker places
subspaces with lower sort keys in front of subspaces with higher sort
keys.
42 Chapter 3
HP-UX Architecture Conventions
Subspaces
Directives
The .SUBSPA directive is used to declare a subspace and its attributes.
As with spaces, the assembly language programmer can switch from one
subspace to another, and the Assembler will fill each subspace
independently as if the source code had been presented one complete
subspace at a time. When the .SPACE directive is used to switch spaces,
the Assembler remembers the current subspace in each space.
Several additional Assembler directives are provided as shorthand to
declare and switch to some standard spaces and subspaces. For example,
the .CODE directive switches to the $TEXT$ space and the $CODE$
subspace, and the .DATA directive switches to the $PRIVATE$ space and
the $DATA$ subspace.
You can declare as many subspaces as you can use, but the sort key
attribute should be used carefully, because the stack unwind mechanism
reserves a range of sort keys 56 through 255 for the $TEXT$ space. Refer
to “Compiler Conventions” on page 47 in this chapter. Some of the
standard subspaces and sort keys used by the compilers are shown in
Table 3-2 on page 43. Directives that generate commonly used spaces
and subspaces are found in Table 4-3 on page 116.
Table 3-2 Standard Subspaces and Sort Keys
$TEXT$ 8
$LIT$ 16 Literals.
$PRIVATE$ 16
Chapter 3 43
HP-UX Architecture Conventions
Sections in 64-bit Mode
$THREAD_SPECIFIC$ 16
$BSS$ .bss
$CODE$ .text
$DATA$ .data
$FINI$ .fini
44 Chapter 3
HP-UX Architecture Conventions
Sections in 64-bit Mode
$INIT$ .init
$LIT$ .rodata
$MILLICODE$ .text
$PREINIT$ .preinit
$SHORTBSS$ .sbss
$SHORTDATA$ .sdata
$TBSS$ .tbss
Chapter 3 45
HP-UX Architecture Conventions
Location Counters
Location Counters
Just as spaces can be divided into subspaces, subspaces can be further
divided by using location counters. You can use up to four location
counters in each subspace, and the Assembler fills a separate area for
each location counter. When the assembly is complete, the subspace is
formed by concatenating each of these areas. All references relative to a
location counter are relocated so that they are relative to the complete
subspace.
Unlike subspaces, however, the use of location counters is completely
local to the Assembler. Once the subspace is formed at the end of the
assembly, the distinction among the individual areas built by location
counters disappears. No further reordering or grouping related to
location counters is performed by the linker.
This facility allows you to assemble related data into disjoint pieces of a
subspace, while keeping the source code in a convenient order.
The .LOCCT directive is used to switch from one location counter to
another. The Assembler automatically remembers the previous value of
each location counter within each subspace. When the .SUBSPA directive
is used to switch subspaces, the Assembler automatically begins using
the location counter that was last in effect in the new subspace.
46 Chapter 3
HP-UX Architecture Conventions
Compiler Conventions
Compiler Conventions
In order to write assembly language procedures that can both call to and
be called from high-level language procedures, it is necessary to
understand the standard procedure-calling convention and other
compiler conventions.
On many computer systems, each high-level language has its own calling
convention. Consequently, calls from one language to another are
sometimes difficult to arrange, except through assembly code. The
architecture generally prescribes very few operations that must be done
to effect a procedure call, and there is often a pair of machine-language
instructions to call a procedure and return from one. PA-RISC
architecture provides no special procedure call or return instructions.
There is, however, a standard procedure-calling convention for all
high-level languages as well as the Assembler. It is tuned for the
architecture, and is designed to make a procedure call with as few
instructions as possible.
Besides defining a uniform call and return sequence for all languages,
the calling convention is important for other reasons. In order to
streamline the calling sequence, the return link is not saved on the stack
unless necessary and the previous stack pointer is rarely saved on the
stack. Therefore, it is not usually possible to obtain a stack trace at an
arbitrary point in the program without some additional static
information about each procedure's stack frame size and usage.
For example, you could not obtain a stack trace while debugging or
analyzing a core dump, or using the TRY/RECOVER feature in HP
Pascal/HP-UX. Obtaining a stack trace is made possible by the stack
unwind mechanism. It uses special unwind descriptors that contain the
exact static information needed for each procedure. These descriptors are
generated automatically by the linker based on information provided by
all high-level compilers as well as the Assembler.
Each descriptor contains the starting and ending address of a
procedure's object code, plus that procedure's stack frame size, and a few
flags indicating, among other things, whether the return link is saved on
the stack. Given the current program counter and stack pointer, the
stack unwind mechanism can determine the calling procedure by finding
Chapter 3 47
HP-UX Architecture Conventions
Compiler Conventions
the return link either in a register or on the stack. Also, it can determine
the previous stack pointer by subtracting the current procedure's stack
frame size.
The Assembler requires that you follow programming conventions to
generate unwind descriptors. The beginning and end of each procedure
must be noted with the .PROC and .PROCEND directives. The .CALLINFO
directive supplies additional information about the procedure, including
the stack frame size. The Assembler passes this information to the
linker, which creates the unwind descriptor. It can also generate the
standard entry and exit code to create and destroy the stack frame, save
and restore the return link (if necessary), and save and restore any
necessary registers. These code sequences are generated at the points
indicated by the .ENTER and .LEAVE pseudo-operations. For a more
thorough discussion of programming conventions, refer to the 64-bit
Runtime Architecture for PA-RISC 2.0, at URL:
http://www.software.hp.com/STK/.
Arguments to procedures are loaded into general registers 26, 25, 24,
and 23; these registers are named, respectively, %arg0, %arg1, %arg2,
and %arg3. If more than four words of arguments are required, the
remaining arguments are stored in the caller's stack frame in the
variable argument list. The return value should be returned in general
register 28, called %ret0. General register 29, called %ret1, is used for
the low-order bits of a double-word return value, while %ret0 contains
the high order bits. In addition to the argument and return registers, the
procedure can use registers 19 through 22 and registers 1 and 31 as
scratch registers. Any other general registers must be saved before use
at entry and restored before exit.
Chapter 4, “Assembler Directives and Pseudo-Operations,” on page 53
contains detailed descriptions of the Assembler directives described
above. For a more thorough discussion of the procedure calling
conventions, refer to the topic PA-RISC Architecture at URL:
http://www.software.hp.com/STK/.
In order for an assembly language procedure to be callable from another
language or another assembly language module, the name of the
procedure must be exported. The .EXPORT directive does this. It also
allows you to declare the symbol type. For procedure entry points, the
symbol type should be ENTRY.
The Assembler and linker treat all symbols as case-sensitive, while some
compilers do not. By convention, compilers that are case-insensitive
uniformly convert all exported names to lower case. For example, it is
48 Chapter 3
HP-UX Architecture Conventions
Compiler Conventions
Chapter 3 49
HP-UX Architecture Conventions
Compiler Conventions
This example assumes that the operating system always allocates data
at the same virtual space offset 0x40000000.
Thread local storage (TLS) data is accessed relative to control register 27
(%cr27). The contents of %cr27 must first be moved to a general register
by using the MFCTL instruction. A symbol, __tp, is defined, similar to
$global$. The following code shows the loading of the TLS variable.
Note the similarities between this example and the example “Global
Symbol Usage” on page 49.
MFCTL %cr27, &rx
ADDIL L'var-__tp,%rx ;result in r1
LDW R'var-__tp(%r1),%r3
Uninitialized areas in the data space can be requested with the .COMM
(common) request. These requests are always made in the $BSS$
subspace in the $PRIVATE$ space. The $BSS$ subspace should not be
used for any initialized data. Common requests are passed on to the
linker, which matches up all requests with the same name and allocates
a block of storage equal in size to the largest request. If, however, an
exported data symbol is found with the same name, the linker treats the
common requests as if they were imports.
HP FORTRAN 77/HP-UX common blocks are naturally allocated in this
way: if a BLOCK DATA subprogram initializes the common block, all
common requests are linked to that initialized block. Otherwise, the
linker allocates enough storage in $BSS$ for the common block. The HP
C/HP-UX compiler also allocates uninitialized global variables this way.
In C, however, each uninitialized global is a separate common request.
50 Chapter 3
HP-UX Architecture Conventions
Shared Libraries
Shared Libraries
The field selectors T', LT', and RT' are used to write
position-independent code in assembly language. When you use these
selectors and invoke the Assembler with the as command, you must use
the +z or +Z compiler option on the command line.
Any assembly code that is to be used with shared libraries must follow
the standard procedure call mechanism as defined in the runtime
architecture documents under the topic PA-RISC Architecture at URL:
http://www.software.hp.com/STK/. Any external procedures must be
exported as type ENTRY for the shared library interface to work correctly.
For more information on position-independent code and shared libraries,
refer to the HP-UX Linker and Libraries Online User Guide and the ELF
64 Object File Format, URL: http://www.software.hp.com/STK/.
Assembly Listing
The Assembler command-line option, -l, causes an assembly listing to
standard output. For each line of source code, the listing provides:
• line number
• the subspace offset
• the hexadecimal representation of the assembled code (possibly
flagged with an asterisk (*) to indicate address relocation)
• the source text
• any comments.
The following is a line of assembly language as it appears in the source
file:
SAVE LDO VAL(%r0),%r20 ;retain value
The above line would appear in the assembly listing as follows:
line no. offset hex representation label opcode operands comment
16 0000004c (341400A) SAVE LDO VAL(%r0),%r20 ;retain value
Chapter 3 51
HP-UX Architecture Conventions
Assembly Listing
52 Chapter 3
4 Assembler Directives and
Pseudo-Operations
Assembler directives and pseudo-operations allow you to take special
programming actions during the assembly process. The directive and
pseudo-operation names begin with a period (.) to distinguish them from
machine instruction opcodes or extended opcodes.
Introduction
Table 4-1 lists the Assembler directives. Table 4-2 on page 55 lists the
pseudo-operations. The directives include those that establish the
procedure-calling convention, declare common, and define spaces and
subspaces. The pseudo-operations reserve and initialize data areas.
The remainder of this chapter lists the Assembler directives and
pseudo-operations in alphabetic order. Several of the descriptions include
sample assembly code sequences. You can enter these short code
sequences, assemble them using the -l option of the as command, then
inspect the offsets and field values to see how that particular directive
controls the assembly environment.
This chapter also includes Table 4-3 on page 116 under “Programming
Aids” on page 116, which lists the predefined directives that establish
standard spaces and subspaces.
Table 4-1 Assembler Directives
Directive Function
53
Assembler Directives and Pseudo-Operations
Directive Function
54 Chapter 4
Assembler Directives and Pseudo-Operations
Directive Function
Directive Function
Chapter 4 55
Assembler Directives and Pseudo-Operations
Directive Function
56 Chapter 4
Assembler Directives and Pseudo-Operations
.ALIGN Directive
.ALIGN Directive
The .ALIGN directive advances the current location counter to the next
specified “boundary.”
Syntax
.ALIGN [ boundary]
Parameters
boundary An integer value for the byte boundary to which you
want to advance the location counter. The Assembler
advances the location counter to that boundary.
Permissible values must be a power of 2 and can range
from one to 4096. The default value is 8 (double word
aligned).
Example
This sample program adds a 21 bit field to the data pointer. Then a
branch is taken to the label “page” that has been page-aligned.
.CODE
ADDIL L’$WORDMARK$-$global$,%dp
B page
NOP
.ALIGN 4096
page
ADDI 1,%r1,%r1
.DATA
$WORDMARK$
.WORD 0x0FFF
.IMPORT $global$,DATA
Chapter 4 57
Assembler Directives and Pseudo-Operations
.ALLOW Directive
.ALLOW Directive
The .ALLOW directive tells the Assembler to temporarily allow PA-RISC
features from a higher version level of the PA-RISC architecture. The
.ALLOW directive also tells the Assembler to temporarily allow
implementation-specific features in the assembly source file.
Syntax
.ALLOW 1.1
Lines of source code
.ALLOW
Parameters
Discussion
Use the .ALLOW directive with the .LEVEL directive. The Assembler uses
the .LEVEL directive to mark the relocatable object file with the proper
PA-RISC architecture version level. In the source file, the Assembler
emits warning messages whenever a feature is used that is not
appropriate for the specified .LEVEL directive.
Use the .ALLOW directive when it is necessary to include features or
instructions from a later version of PA-RISC while leaving the
relocatable object file marked as an earlier PA-RISC architecture
version. For example, use the .ALLOW directive when you need to
include PA-RISC 2.0 features or instructions while leaving the
relocatable object file marked as a PA-RISC 1.1 architecture version.
NOTE A 2.0W parameter is not permitted with .ALLOW, because the code
generated for 2.0W(64-bit mode) is incompatible with other levels.
58 Chapter 4
Assembler Directives and Pseudo-Operations
.ALLOW Directive
NOTE The .ALLOW and .LEVEL directives replace the +DA and +DS
command-line compiler options.
Example
The following example shows how to set a range of memory to 0. In
PA-RISC 1.1 architecture, use the stw instruction. In PA-RISC 2.0
architecture, use the more efficient std instruction.
.LEVEL 1.1
; This object file will be marked as a PA 1.1 object file
Chapter 4 59
Assembler Directives and Pseudo-Operations
.BLOCK and .BLOCKZ Pseudo-Operations
Syntax
.BLOCK [ num_bytes]
.BLOCKZ [ num_bytes]
Parameters
Discussion
The .BLOCK pseudo-operation reserves a data storage area but does not
perform any initialization. The .BLOCKZ pseudo-operation reserves a
block of storage and initializes it to zero.
When you label a.BLOCK pseudo-operation, the label refers to the first
byte of the storage area.
For large blocks, it is usually better to use the .COMM directive to allocate
uninitialized space. Since .COMM storage is allocated at run time, it
doesn't increase the size of the object file.
60 Chapter 4
Assembler Directives and Pseudo-Operations
.BLOCK and .BLOCKZ Pseudo-Operations
Example
The first example requests the Assembler to reserve 64 bytes of memory
in the $CODE$ subspace. This area is then followed by a “Load Word” and
“Store Word” instruction.
.SPACE $TEXT$
.SUBSPA $CODE$
.BLOCK 64
swap LDW 0(%r2)%r1
STW %r1,4(%r2)
.END
The second example reserves 32 bytes of memory in the $DATA$
subspace followed by one word intended as an end marker.
.DATA
word0 .BLOCK 0X20
word8 .WORD 0XFFFF
Chapter 4 61
Assembler Directives and Pseudo-Operations
.BYTE Pseudo-Operation
.BYTE Pseudo-Operation
The .BYTE pseudo-operation reserves storage and initializes it to the
given value.
Syntax
.BYTE [ init_value[ , init_value] ...]
Parameters
Discussion
The .BYTE pseudo-operation requests 8 bits of storage. If the location
counter is not properly aligned on a boundary for a data item of that size,
the Assembler advances the location counter to the next multiple of that
item's size before reserving the area.
When you label the pseudo-operation, the label refers to the first byte of
the storage area. Operands separated by commas initialize successive
units of storage.
Example
The first pseudo-operation allocates a byte labeled E and initializes it to
the character [ .
E .BYTE "["
62 Chapter 4
Assembler Directives and Pseudo-Operations
.CALL Directive
.CALL Directive
The .CALL directive marks the next branch statement as a procedure
call, and permits you to describe the location of arguments and the
function return result.
Syntax
.CALL [ argument_description[ argument_description] ...]
Parameters
argument_
description Allows you to communicate to the linker the types of
registers used to pass floating point arguments and
receive floating point return results in the succeeding
procedure call. Similarly, this information can be
communicated in the .EXPORT directive.
The linker requires this information because the
runtime architecture allows floating point arguments
and return values to reside in either general registers
or floating point registers, depending on source
language convention. At link time, the linker ensures
that both the caller and called procedure agree on
argument location. If not, the linker may insert code to
relocate the arguments (or return result) before control
is transferred to the called procedure or a procedure
return is completed.
You can use up to 5 argument-descriptions in the
.CALL directive; one for each of the four arguments
that may be passed in registers (arg0–arg3), and one
for a return value (ret0).
NOTE In PA-RISC 2.0W, (64-bit mode) the Assembler ignores the .CALL
directive. This means that the linker does not ensure that the caller and
called procedure agree on argument locations. If you do not know the
prototype of the called procedure, you must pass floating point
Chapter 4 63
Assembler Directives and Pseudo-Operations
.CALL Directive
Example
This example shows the use of the .CALL directive in 32-bit mode.
64 Chapter 4
Assembler Directives and Pseudo-Operations
.CALL Directive
.LIT
.ALIGN 8
.WORD 1197387154 ; floating-point literal
.BLOCKZ 12
fp2 .WORD 0
.CODE
main
.PROC
.CALLINFO CALLER,FRAME=24,SAVE_RP
.ENTER
LDIL L’fp2,%r1
LDO R’fp2(1),%r31 ; r31 < - floating-point literal address
FLDWS -16(%r31),%fr4
LDO -64(%sp),%r19
FSTWS %fr4,0(%r19)
ADDIL L’61453,0
LDO R’61453(%r1),%r20
STW %r20,-68(%sp) ; end of stacking floating-point address
ADDIL L’string_area-$global$,%dp
LDO R’string_area-$global$(%r1),%r21 ; point to “message”
STW %r21,-60(%sp) ; stack “message” address
LDO -64(%sp),%r22
FLDWS 0(%r22),%fr5
FCNVFF,SGL,DBL %fr5,%fr6 ; convert floating-point value
ADDIL L’string_area-$global$+8,%dp
LDO R’string_area-$global$+8(%r1),%arg0
;point to format string
LDW -60(%sp),%arg1 ; load “message” argument
FSTDS 38,-16(%sp)
FLDWS -12(%sp),%fr6 ; load floating-point argument
LDWS -16(%sp),%arg3 ; load hexadecimal argument
LDW -68(%sp),%r1
STW %r1,-52(%sp)
.CALL argw0=no,argw1=gr,argw2=fr,argw3=gr,rtnval=no
BL printf,2
NOP
.LEAVE
Chapter 4 65
Assembler Directives and Pseudo-Operations
.CALL Directive
.PROCEND
.EXPORT main,ENTRY
.IMPORT printf,CODE
.DATA
string_area
.ALIGN 8
.STRINGZ “message”
.STRINGZ “ARGS = %s,%f,%x\n”
.IMPORT $global$,DATA
66 Chapter 4
Assembler Directives and Pseudo-Operations
.CALLINFO Directive
.CALLINFO Directive
.CALLINFO is a required directive that describes the environment of the
current procedure. The information it provides is available to the
.ENTER and .LEAVE pseudo-operations to control the entry and exit code
sequences that they generate. Additional information is used by the
Assembler to direct the creation of stack unwind descriptors.
Syntax
.CALLINFO [ parameter[ , parameter] ...]
where parameter is one of:
ALLOCA_FRAME
ARGS_SAVED
CALLER
CALLS
NO_CALLS
CLEANUP
ENTRY_FR=number
ENTRY_GR=number
ENTRY_SR=number
FRAME=number
HPUX_INT
MILLICODE
NO_UNWIND
SAVE_MRP
SAVE_RP
SAVE_SP
SAVE_SR0
Parameters
ALLOCA_FRAME Indicates that this procedure allocates temporary
storage by modifying the stack pointer (%r30). A copy
of the frame pointer is normally placed in %r3.
However, if this procedure also has a large frame
(FRAME > 8191), then the copy of the frame pointer is
placed in %r4 instead.
ARGS_SAVED Indicates that this procedure stores the arguments into
the stack frame.
Chapter 4 67
Assembler Directives and Pseudo-Operations
.CALLINFO Directive
CALLER or
CALLS Indicates that this procedure calls other routines, so it
requires space in the stack for a frame marker and a
fixed argument list. (When a program is assembled
using the -f option, this becomes the default case.)
The Assembler allocates stack space when it
encounters an .ENTER pseudo-operation and
deallocates this space when it encounters a .LEAVE
pseudo-operation. The Assembler allocates 48 bytes for
the PA-RISC 32-bit mode and 80 bytes for the PA-RISC
64-bit (2.0W) mode.
The frame marker and fixed argument list area occur
at the top of the stack so you must take this space into
account when locating local variables on the stack. You
must allocate an area (using FRAME=) for a variable
argument list when this area is needed.
CALLER does not imply the existence of the parameter
SAVE_RP.
The CALLER and CALLS parameters are equivalent.
NO_CALLS Indicates that the procedure does not call other
procedures and, therefore, does not require a frame
marker on the stack. This is the default case unless the
program is assembled using the -f option.
CLEANUP Indicates that this procedure requires cleanup during
unwind.
ENTRY_FR=
register Specifies the high end boundary of the Entry/Save
floating-point register partition. The partition includes
%fr12 through %fr15 for PA-RISC 1.0 and %fr12
through %fr21 for PA-RISC 1.1. The Assembler
automatically saves these registers when it encounters
an .ENTER pseudo-operation and restores them when it
encounters a .LEAVE pseudo-operation.
ENTRY_GR=
register Specifies the high end boundary of the Entry/Save
register partition. The partition may extend over
registers %r3 through %r18. If you omit this
parameter, no registers are saved.
68 Chapter 4
Assembler Directives and Pseudo-Operations
.CALLINFO Directive
Chapter 4 69
Assembler Directives and Pseudo-Operations
.CALLINFO Directive
70 Chapter 4
Assembler Directives and Pseudo-Operations
.CALLINFO Directive
Discussion
When a program uses the .CALLINFO directive, all entry and exit code
must follow the procedure calling convention described in the documents
under the topic PA-RISC Architecture at URL:
http://www.software.hp.com/STK/. If you use the .ENTER and .LEAVE
directives, the Assembler will automatically generate the necessary code.
The parameters in the .CALLINFO directive govern the generation of the
Entry/Exit code sequence (except for SAVE_SP). However, if you use the
.ENTRY and .EXIT directives, your code must provide the necessary
Entry/Exit code sequences.
A stack frame consists of a pointer to the top of the frame, a frame
marker, a fixed argument list, and a variable argument list. The
following example, Stack Frames, illustrates these areas as an inverted
stack for PA-RISC 1.x and 2.0.
NOTE For PA-RISC 2.0W, 64-bit mode, the stack frame is different. Refer to the
documents under the topic PA-RISC Architecture at URL:
http://www.software.hp.com/STK/.
Chapter 4 71
Assembler Directives and Pseudo-Operations
.CALLINFO Directive
Stack Frames
Variable Arguments
. . .
SP-64: arg word 7
SP-60: arg word 6
SP-56: arg word 5
SP-52: arg word 4
Fixed Arguments
Frame Marker
Top of Frame
Example
This example uses the C printf() routine (see printf(3S) in HP-UX
Reference). It illustrates most of the directives to be used when assembly
language programmers follow the standard procedure calling
conventions described in the documents under the topic PA-RISC
Architecture at URL: http://www.software.hp.com/STK/.
.CODE ; declare space and subspace
main
.PROC ; delimit procedure entry
.CALLINFO CALLER,FRAME=0,SAVE_RP ; no local variables, need return
.ENTER ; insert entry code sequence
ADDIL L’stringinit-$global$,%r27 ; point to data to be printed
LDO R’stringinit-$global$(%r1),%r26 ; place argument to printf
.CALL ; set up for procedure call
BL printf,%r2 ; call printf, remembering from where
NOP
.LEAVE ; insert exit code sequence
.PROCEND ; delimit procedure end
72 Chapter 4
Assembler Directives and Pseudo-Operations
.CALLINFO Directive
Chapter 4 73
Assembler Directives and Pseudo-Operations
.COMM Directive
.COMM Directive
The .COMM directive makes a storage request for a specified number of
bytes.
Syntax
label .COMM [ num_bytes]
Parameters
label Labels the location of the reserved storage.
num_bytes An integer value for the number of bytes you want to
reserve. The Assembler uses a default value of 4 if the
.COMM directive lacks a num_bytes parameter.
Permissible values range from one to 0x3FFFFFFF.
Discussion
The .COMM directive declares a block of storage that can be thought of as
a common block. You must label every .COMM directive. The linker
associates the label with the subspace in which the .COMM directive is
declared and allocates the necessary storage within that subspace.
.COMM always allocates its space in the $BSS$ subspace of the
$PRIVATE$ space. If the label of a .COMM directive appears in several
object modules, the linker uses the maximum size specified in any
module when it allocates the necessary storage in the current subspace.
Example
This example reserves 16 bytes of storage for mydata.
.BSS
mydata .COMM 16
74 Chapter 4
Assembler Directives and Pseudo-Operations
.COPYRIGHT Directive
.COPYRIGHT Directive
The .COPYRIGHT directive inserts a company name and date into the
object module as a copyright notice.
Syntax
.COPYRIGHT "company-name [ , date] "
Parameters
company-name,
date A sequence of ASCII characters, surrounded by
quotation marks. The string can contain up to 256
characters. When a comma follows the company name,
the next text is expected to be the date.
Discussion
The following is the standard copyright message placed in the copyright
header of the object file:
Copyright company-name,date. All rights reserved. No
part of this program may be photocopied, reproduced, or
transmitted without prior written consent of
company-name.
NOTE This directive can appear anywhere in the source file, but may appear
only once.
Chapter 4 75
Assembler Directives and Pseudo-Operations
.COPYRIGHT Directive
Example
This program places a copyright notice in the object file. Once the
copyright notice is in the object file, the HP-UX utility strings can be
used to access it. See strings(1) in HP-UX Reference.
.COPYRIGHT "My Company Name, 8 Nov 1994"
.CODE
.EXPORT main,ENTRY
main
.PROC
.CALLINFO
.ENTER
LDI 2,%r5
ADDI 2,%r5,%r6
.LEAVE
.PROCEND
76 Chapter 4
Assembler Directives and Pseudo-Operations
.DOUBLE Pseudo-Operation
.DOUBLE Pseudo-Operation
The .DOUBLE pseudo-operation initializes a double-word to a
floating-point value, calculated from the parameters provided. If the
location counter, is not aligned on a double-word boundary, it is forced to
the next multiple of eight. If the statement is labeled, the label refers to
the first byte of the storage area.
Syntax
.DOUBLE integer [ .fraction] [ E [ -] power]
.DOUBLE .fraction [ E[ -] power]
Parameters
integer Specifies the whole number part of a decimal number.
fraction Specifies the fractional part of a decimal number.
power Specifies the power of ten to raise a decimal number. To
raise the decimal number to a negative power of ten,
place a minus sign (-) directly in front of the power
specified.
Example
Each of the following examples initializes two words of memory to
floating-point quantities: 0.00106 and 400000.0 respectively.
dec_val1 .DOUBLE 10.6E-4
Chapter 4 77
Assembler Directives and Pseudo-Operations
.DWORD Pseudo-Operation
.DWORD Pseudo-Operation
The .DWORD pseudo-operation reserves storage and initializes it to the
given value.
Syntax
.DWORD [ init_value[ , init_value] ...]
Parameters
init_value An absolute expression, a decimal, octal, or
hexadecimal number, or a sequence of ASCII
characters surrounded by quotation marks. If you omit
the initializing value, the Assembler initializes the
area to zero.
Discussion
The .DWORD pseudo-operation requests 64 bits of storage. If the location
counter is not properly aligned on a boundary for a data item of that size,
the Assembler advances the location counter to the next multiple of that
item's size before reserving the area.
When you label the pseudo-operation, the label refers to the first byte of
the storage area. Operands separated by commas initialize successive
units of storage.
Example
The first pseudo-operation advances the current subspace's location
counter to a double word boundary, allocates a double word of storage
labeled F and initializes that double word to minus 64 (2s complement).
The second pseudo-operation initializes a double word of storage to the
hexadecimal number 6effffff12345678.
F .DWORD 64
.DWORD 0X6effffff12345678
78 Chapter 4
Assembler Directives and Pseudo-Operations
.END Directive
.END Directive
The .END directive terminates an assembly language program.
Syntax
.END
Discussion
This directive is the last statement in an assembly language program. If
a source file lacks an .END directive, the Assembler terminates the
program when it encounters the end of the file.
Example
A file that omitted the last line of this sample program would produce
identical results.
.CODE
.EXPORT double,ENTRY
.PROC
double
.CALLINFO
.ENTER
ADD %arg0,%arg0,%ret0
.LEAVE
.PROCEND
.END
Chapter 4 79
Assembler Directives and Pseudo-Operations
.ENDM Directive
.ENDM Directive
The .ENDM directive marks the end of a macro definition. The macro
definition is entered into the macro table and the remaining source lines
are read in and assembled. An .ENDM directive must always accompany
a .MACRO directive.
Syntax
.ENDM
Example
This example defines the macro QUADL; it aligns the data specified in the
macro parameters on quad word boundaries. The .ENDM directive
delimits the end of the definition of QUADL.
QUADL .MACRO WD1,WD2,WD3,WD4
.ALIGN 16
.WORD WD1
.ALIGN 16
.WORD WD2
.ALIGN 16
.WORD WD3
.ALIGN 16
.WORD WD4
.ENDM
80 Chapter 4
Assembler Directives and Pseudo-Operations
.ENTER and .LEAVE Pseudo-Operations
Syntax
.ENTER
Lines of code
.LEAVE
Discussion
The .ENTER pseudo-operation marks an entry point for the current
procedure. Every procedure that follows the standard procedure-calling
convention must contain one .ENTER pseudo-operation. The calling
conventions are described in the documents under the topic PA-RISC
Architecture at URL: http://www.software.hp.com/STK/. The .LEAVE
pseudo-operation marks a procedure's exit point. Every procedure that
follows the procedure-calling convention must contain one .LEAVE
pseudo-operation. See “.ENTRY and .EXIT Directives” on page 83 for
exceptions.
When the Assembler encounters an .ENTER pseudo-operation, it
generates an entry code sequence according to the parameters in the
.CALLINFO directive for that procedure. Similarly, when the Assembler
encounters a .LEAVE pseudo-operation, it generates an exit code
sequence according to the parameters in the .CALLINFO directive for
that procedure.
Chapter 4 81
Assembler Directives and Pseudo-Operations
.ENTER and .LEAVE Pseudo-Operations
Example
This example shows the placement of the .ENTER and .LEAVE
pseudo-operations.
.SPACE $TEXT$
.SUBSPA $CODE$
entrypt
.PROC
.CALLINFO
.ENTER
SH1ADD %arg0,%arg1,%ret0
.LEAVE
.PROCEND
.EXPORT entrypt,ENTRY
.END
82 Chapter 4
Assembler Directives and Pseudo-Operations
.ENTRY and .EXIT Directives
Syntax
.ENTRY
Lines of Code
.EXIT
Discussion
The .ENTRY directive signifies that the next instruction is the beginning
of an entry point for the current procedure. The .EXIT directive signifies
that the next instruction initiates a return from the current procedure.
These directives must be used when .ENTER and .LEAVE are not
present. .ENTRY and .EXIT are optional if the unwind region does not
have a corresponding entry or exit. See the documents under the topic
PA-RISC Architecture at URL: http://www.software.hp.com/STK/.
Example
This example shows a sequence of compiler-generated assembly code.
.PROC
.CALLINFO CALLER
.ENTRY ; proc entry code follows
STW %r2,-20(%sp) ; stack the return pointer
LDO 48(%sp),%sp ; set up user stack pointer
ADDIL L’$THISMODULE$-$global$,%r27 ; point to printf data
.CALL ; set up for printf call
BL printf,2 ; call printf thru RP
LDO R’$THISMODULE$-$global$(%r1),%r26 ; insert argument to
printf L$exit1 ; hide from linker
LDW -68(%sp),%r2 ; get callee RP
BV 0(%r2) ; exit thru RP
.EXIT ; end of exit sequence
LDO -48(%sp),%sp ; delete stack frame
.PROCEND
Chapter 4 83
Assembler Directives and Pseudo-Operations
.EQU Directive
.EQU Directive
The .EQU directive assigns an expression value to an identifier.
Syntax
symbolic_name .EQU value
Parameters
symbolic_name The name of the identifier to which the Assembler
assigns the expression.
value An integer expression. The Assembler evaluates the
expression, which must be absolute, and assigns this
value to symbolic_name. If the expression references
other identifiers, each identifier must be defined before
the .EQU directive attempts to evaluate the expression.
Example
This is a valid assembly program because the definition of val1 comes
before the definition of val2. Reversing the first two statements,
however, produces an error condition.
val1 .EQU 0
val2 .EQU val1+4
.SPACE $TEXT$
.SUBSPA $CODE$
LDW val1,%r1
STW %r1,val2
.END
84 Chapter 4
Assembler Directives and Pseudo-Operations
.EXPORT Directive
.EXPORT Directive
The .EXPORT directive allows symbols to be defined in one program and
used in other programs.
Syntax
.EXPORT symbol [ , type] [ , argument-description] ...
Parameters
symbol The name of an identifier whose definition is being
exported or imported.
type A linker symbol type that can take one of the following
values:
Chapter 4 85
Assembler Directives and Pseudo-Operations
.EXPORT Directive
86 Chapter 4
Assembler Directives and Pseudo-Operations
.EXPORT Directive
Discussion
The .EXPORT directive uses a series of keywords to define a symbol to
the linker. These keywords declare the symbol's type, and its argument
relocation information if the symbol is the name of a procedure.
Example
This example makes the symbol proc available to the linker as an entry
point. It also specifies that the first argument is expected in a general
register.
.EXPORT proc,ENTRY,ARGW0=GR
Chapter 4 87
Assembler Directives and Pseudo-Operations
.FLOAT Pseudo-Operation
.FLOAT Pseudo-Operation
The .FLOAT pseudo-operation initializes a single-word of storage to a
floating-point value calculated from the parameters provided. If the
location counter is not aligned on a word boundary, it is forced to the next
multiple of four. If the statement is labeled, the label refers to the first
byte of the storage area.
Syntax
.FLOAT integer [ .fraction] [ E [ -] power]
.FLOAT .fraction [ E [ -] power]
Parameters
integer Specifies the whole number part of a decimal number.
fraction Specifies the fractional part of a decimal number.
power Specifies the power of ten to raise a decimal number. To
raise the decimal number to a negative power of ten,
place a minus sign (-) directly in front of the power
specified.
Example
Each of the following examples initializes one word of memory to
floating-point quantities: 0.00096 and 3400000.0, respectively.
factor1 .FLOAT 9.6E-4
88 Chapter 4
Assembler Directives and Pseudo-Operations
.HALF Pseudo-Operation
.HALF Pseudo-Operation
The .HALF pseudo-operation reserves storage and initializes it to the
given value.
Syntax
.HALF [ init_value [ , init_value] ...]
Parameters
init_value Either a decimal, octal, or hexadecimal number or a
sequence of ASCII characters, surrounded by quotation
marks. If you omit the initializing value, the Assembler
initializes the area to zero.
Discussion
The .HALF pseudo-operation requests 16 bits of storage. If the location
counter is not properly aligned on a boundary for a data item of that size,
the Assembler advances the location counter to the next multiple of that
item's size before reserving the area.
When you label the pseudo-operation, the label refers to the first byte of
the storage area. Operands separated by commas initialize successive
units of storage.
Example
This example allocates two half-words, initializing them to 50 and 100.
The label B refers to the first half-word allocated.
B .HALF 50,100
Chapter 4 89
Assembler Directives and Pseudo-Operations
.IMPORT Directive
.IMPORT Directive
The .IMPORT directive allows symbols to be defined in one program but
used in other programs.
Syntax
.IMPORT symbol [ , type] [ , TSPECIFIC]
Parameters
symbol The name of an identifier whose definition is being
imported.
type A linker symbol type that can take one of the following
values:
90 Chapter 4
Assembler Directives and Pseudo-Operations
.IMPORT Directive
Discussion
The .IMPORT directive uses a series of keywords to define a symbol to
the linker. These keywords declare the symbol's type. Because the
.IMPORT directive specifies that another object module contains this
symbol's formal definition, the Assembler does not associate an imported
symbol with any particular subspace. When an .IMPORT directive lacks
a type parameter, the Assembler assigns the type of the current subspace
(either $CODE$ or $DATA$) to the symbol.
Example
The .IMPORT directive lets the Assembler access symname as a
recognized symbol, even though it is actually defined elsewhere. The
linker resolves the difference.
.IMPORT symname,CODE ;import symname as a CODE symbol.
.CODE ;begin CODE subspace
LDIL L’symname,%r1
BLE,n R’symname(%sr4,%r1) ;call the procedure symname in %sr4
space.
NOP
.END
Chapter 4 91
Assembler Directives and Pseudo-Operations
.LABEL Directive
.LABEL Directive
The .LABEL directive permits a label definition to appear within a
sequence of instructions that occur on a single line.
Syntax
.LABEL label_id
Parameters
label_id Names the label identifier.
NOTE The .LABEL directive is especially useful when using the M4 macro
processor or the C preprocessor (cpp). You would normally use this
directive in a DEFINE macro that includes multiple instructions.
Example
This example defines a cpp macro named Loop.
#define Loop(xx) LDO xx(%r0),%r1 ! .LABEL Loop ! ADDI,=-1,%r1,%r1 \
! BL Loop,%r0 ! NOP ! LDI 1,%ret0 ; macro
.CODE
step_ten
.PROC
.CALLINFO
.ENTER
Loop(10)
.LEAVE
.PROCEND
.EXPORT step_ten,ENTRY
92 Chapter 4
Assembler Directives and Pseudo-Operations
.LEVEL Directive
.LEVEL Directive
The .LEVEL directive tells the Assembler which version level of the
PA-RISC architecture to accept while assembling the source file. The
.LEVEL directive also tells the Assembler which implementations-
specific features are used in the assembly source file.
Syntax
1.0
1.1
.LEVEL
2.0
2.0W
Parameters
1.0 Enables PA-RISC 1.0 features. This is the default.
1.1 Enables PA-RISC 1.1 features.
2.0 Enables PA-RISC 2.0 features.
2.0W Enables PA-RISC 2.0W features and assembles the
source for a 64-bit machine.
Discussion
The Assembler marks the relocatable object file to indicate the minimum
PA-RISC architecture version level required when executing the object
code corresponding to the source file. The linker marks the program file
with the highest version level required by any of the object files linked
into the program.
The Assembler uses the .LEVEL directive to mark the relocatable object
file with the proper PA-RISC architecture version level. For example, if
the code is expected to run only on PA-RISC 1.1 architectures, a .LEVEL
1.1 should be inserted at the beginning of the source file.
To assemble a source file for a PA-RISC 64-bit system, use a .LEVEL
2.0W directive as the first directive in the source file.
Chapter 4 93
Assembler Directives and Pseudo-Operations
.LEVEL Directive
94 Chapter 4
Assembler Directives and Pseudo-Operations
.LISTOFF and .LISTON Directives
Syntax
.LISTOFF
.LISTON
Example
The following is the definition of the macro DECR. It is referred to in the
assembly listing generated when .LISTON was used with a procedure
containing the macro invocation.
DECR .MACRO LAB,VAL
SKF ADDIL L’VAL-$global$,%dp
LDW R’VAL-$global$(%r1),%r20
LAB ADDIBF,=,N -1,%r20,LAB
.ENDM
.CODE
.IMPORT $global$
.IMPORT mark
.IMPORT count
.PROC
call_DECR
.CALLINFO FRAME=0, SAVE_RP
.ENTER
DECR mark,count
.LEAVE
.PROCEND
Chapter 4 95
Assembler Directives and Pseudo-Operations
.LISTOFF and .LISTON Directives
If .LISTOFF had been used in the above example, the macro invocation
DECR, and the directives .CODE, .DATA, .ENTER, and .LEAVE, would not
have been expanded in the assembly listing.
line offset hexcode label opcode operands (comment)
1 .LISTON
2 .CODE
.SPACE $TEXT$, SPNUM=0,SORT=0
.SUBSPA $CODE$, QUAD=0,ALIGN=8,ACCESS=0x2c
3 .PROC
4 call_DECR ;proc label
5 .CALLINFO FRAME=0,SAVE_RP
6 .ENTER
00000000 (6BC23FD9) STW 2,-0x14(0,0x1E)
00000004 (37DE0060) LDO 0x30(0x1E),0x1E
7 00000008 (2B600000) ADDIL L’count-$global$,%dp
8 0000000C (683A0000) STW %arg0,R’count-$global$(%r1)
9 DECR mark,count;
macro invocation
00000010 (2B600000) ADDIL L’VAL-$global$,%dp
00000014 (48340000) LDW R’VAL-$global$(%r1),%r20
LAB
00000018 (AE9F3FF5) ADDIBF,= -1,%r20,LAB
0000001C (08000240) NOP
10 .LEAVE
00000020 (4BC23F79) LDW -0x44(0,0x1E),2
00000024 (E840C000) BV 0(2)
00000028 (37C03FA1) LDO -0x30(0x1E),0
11 .PROCEND
12 .EXPORT call_DECR,ENTRY
13 DATA
.SPACE $PRIVATE$, SPNUM=1,SORT=16
.SUBSPA $DATA$, QUAD=1,ALIGN=8
ACCESS=0x1f
14 .IMPORT $global$
15 40000000 (00000000) count .WORD 0
16 .LISTOFF
96 Chapter 4
Assembler Directives and Pseudo-Operations
.LOCCT Directive
.LOCCT Directive
The .LOCCT directive specifies where subsequent code should occur in
one of the four location counters of the current subspace.
Syntax
.LOCCT [ loc_number]
Parameters
loc_number A location-counter number of the current subspace.
The permissible values are 0, 1, 2, and 3. The default is
zero.
NOTE The .LOCCT directive is not permitted within a procedure and cannot be
used to produce unwindable code.
Example
This example uses two location counters to separate code from data. In
the assembled code, everything under location counter 0 comes first,
followed by everything under location counter 1, and so on.
.CODE
.LOCCT 0
ldval1
LDIL L'val1,%r19
LDO R'val1(%r19),%r19
.LOCCT 1
val1 .WORD 57005
.LOCCT 0
ldval2
LDIL L'val2,%r20
LDO R'val2(%r20),%r20
.LOCCT 1
val2 .WORD 61453
Chapter 4 97
Assembler Directives and Pseudo-Operations
.MACRO Directive
.MACRO Directive
The .MACRO directive marks the beginning of a macro definition. An
.ENDM directive must be used to end the macro definition.
Syntax
label .MACRO [ formal_parameter[,formal_parameter]...]
Parameters
label The name of the macro.
formal_parameter Specifies a string of characters
treated as a positional parameter.
The ith actual parameter in a macro
invocation is substituted for the ith
formal parameter in the macro
declaration wherever the formal
parameter appears in the body of the
macro definition.
Discussion
Normal Assembler syntax is observed within macro definitions, except
that text substitution is assumed for formal parameters. The following
line is an example of a macro declaration:
DECR .MACRO LAB,VAL
LAB and VAL are formal parameters. Their actual values are determined
by the first and second parameters on any invocation of the macro DECR.
On the macro invocation, the parameters are delimited by commas.
Successive commas indicate a null parameter, causing the expanded
macro to substitute null for one of its formal parameters. When the
number of formal parameters exceeds the number of actual parameters,
null parameters are inserted for the excess parameter positions. When
the number of actual parameters exceeds the number of formal
parameters, a warning is issued and the excess parameters are ignored.
98 Chapter 4
Assembler Directives and Pseudo-Operations
.MACRO Directive
NOTE A macro cannot be defined within the body of another macro definition.
Although nested macro definitions are not allowed, nested macro calls
are. A nested macro call occurs when one macro is invoked within the
definition of another macro. A macro may not be invoked within its own
definition. Macros can only be invoked after being defined.
Examples
The macro definition defines a simple counter or timer called DECR.
DECR .MACRO LAB,VAL
SETP ADDIL L'VAL-$global$,%dp
LDW R'VAL-$global$(%r1),%r20
LAB
ADDIBF,= -1,%r20,LAB
NOP
.ENDM
The following is an invocation of DECR:
DECR LOOP,COUNT
LOOP and COUNT are the actual parameters that are specific to this
particular invocation of the macro DECR.
During macro expansion, textual substitution for positional parameters
is performed in the body of the macro definition. Substitution is
performed on strings of characters that are delimited by blanks, tabs,
commas, or semicolons. If the string matches one of the formal
parameters, it is replaced with the corresponding actual parameter.
When a macro definition contains a label, the expanded form of the
macro adds a unique suffix to the label for each instance the macro is
invoked. This unique suffix prevents duplicate symbols from occurring
Chapter 4 99
Assembler Directives and Pseudo-Operations
.MACRO Directive
and prevents the label from being referenced from outside the body of the
macro definition. This suffix also contains a number that is used as a
counter by the Assembler.
The following example defines the macro PRINT, which calls the
printf() function (see printf(3S) in HP-UX Reference). The macro
parameter DATA_ADDR is used to set up the argument to be passed to
printf().
PRINT .MACRO DATA_ADDR
ADDIL L'DATA_ADDR,%dp
.CALL
BL printf,%rp
LDO R'DATA_ADDR(%r1),%arg0
.ENDM
The next example defines the macro STORE. STORE places the contents of
the register REG, the first macro parameter, into the memory address
LOC, the second parameter.
STORE .MACRO REG,LOC
LDIL L'LOC-$global$,%r1
STW REG,R'LOC-$global$(%r1)
.ENDM
100 Chapter 4
Assembler Directives and Pseudo-Operations
.ORIGIN Directive
.ORIGIN Directive
The .ORIGIN directive advances the location counter to the specified
location.
Syntax
.ORIGIN [ location]
Parameters
location The integer value used to advance the location counter
to that absolute location. The location counter value
may not decrease during this process; that is, the value
specified cannot be less than the value of the current
location counter.
The default value is zero.
Discussion
When the Assembler encounters an .ORIGIN directive, it issues a
.BLOCK pseudo-operation of a size calculated to advance the location
counter to the requested origin. See “.BLOCK and .BLOCKZ
Pseudo-Operations” on page 60 in this chapter.
Example
This sample program performs an exclusive OR, advances the location
counter to 64 bytes, and branches to the label idx.
.CODE
XOR %r21,%r22,%r23
B idx
NOP
.ORIGIN 64
idx LDWX %r23(%sr0,%sr0),%r3
.END
Chapter 4 101
Assembler Directives and Pseudo-Operations
.PROC and .PROCEND Directives
Syntax
.PROC
Lines of Code
.PROCEND
Discussion
The .PROC directive signifies that the next instruction is the first
instruction of a procedure. The .PROCEND directive signifies that the
previous instruction was the last instruction of the procedure. Switching
spaces or subspaces within a procedure is not permitted.
Every procedure must contain a .CALLINFO directive and normally
contains an .ENTER and .LEAVE pseudo-operation. The only exception to
the latter rule occurs in procedures that are either compiler-generated or
created by programmers who are writing their own entry and exit code
sequences. In this case, you must use the .ENTRY and .EXIT compiler
directives.
NOTE Because the .ENTER and .LEAVE pseudo-operations guarantee that the
stack unwind process works correctly, you should consistently use these
directives rather than writing your own entry and exit code sequences.
102 Chapter 4
Assembler Directives and Pseudo-Operations
.PROC and .PROCEND Directives
Example
This template shows a procedure that follows the procedure-calling
convention.
.CODE
test
.PROC
.CALLINFO
.ENTER
COMCLR,= %arg0,%arg1,%ret0
LDI 1,%ret0
.LEAVE
.PROCEND
.EXPORT test
Chapter 4 103
Assembler Directives and Pseudo-Operations
.REG Directive
.REG Directive
The .REG directive assigns a predefined or user-defined typed-register to
a symbol, which becomes a synonym for the typed-register.
Syntax
label .REG [ typed_register]
Parameters
label A user-defined register name.
typed_register Must be one of the predefined Assembler registers or a
previously defined user-defined register name All
predefined Assembler registers begin with %.
Example
This example defines the register shift as a synonym for control
register eleven. %sar is a predefined synonym for control register eleven,
the shift-amount register.
shift .REG %sar
104 Chapter 4
Assembler Directives and Pseudo-Operations
.SHLIB_VERSION Directive
.SHLIB_VERSION Directive
The .SHLIB_VERSION directive marks the object file with a version
string that the shared library understands.
Syntax
.SHLIB_VERSION " mm/yyyy"
Parameters
mm The one- or two-digit number of the month.
yyyy The four-digit number of the year.
Example
The following pseudo-operation places the date September 1994 in the
object file.
.SHLIB_VERSION "9/1994"
Chapter 4 105
Assembler Directives and Pseudo-Operations
.SPACE Directive
.SPACE Directive
The .SPACE directive starts a new space or switches back to an old
space. The Assembler ignores the .SPACE directive for 64-bit assembly
programs. For more information, see “Sections in 64-bit Mode” on page
44.
Syntax
,NOTDEFINED
,PRIVATE
,SORT=value
.SPACE name ...
,SPNUM=value
,TSPECIFIC
,UNLOADABLE
Parameters
name An identifier that names the new space.
NOTDEFINED Specifies that the definition for this space occurs in
another object module.
PRIVATE Specifies that other programs cannot share the data in
this space. The enforcement of this directive depends
on the operating system.
SORT=value Provides an integer value for the sort key. The linker
orders the spaces in the output object module according
to this key. It is suggested that the number “8” be used
for space $TEXT$ and the number “16” be used for
$PRIVATE$.
SPNUM=value A space number constant that provides a specific
number for the current space. Its use is currently
optional and is ignored by the linker. If the first
parameter of the .SPACE directive is an integer, it will
be interpreted as the space number and any remaining
parameters will be ignored.
106 Chapter 4
Assembler Directives and Pseudo-Operations
.SPACE Directive
Discussion
The first time the Assembler encounters a .SPACE directive with a new
name, it uses that name to declare a new space. As this is the defining
occurrence of that space, additional keywords can describe attributes for
that space.
If the Assembler encounters subsequent .SPACE directives with that
name, it continues that space. In this case, where the program is
re-entering a previously defined space, the .SPACE directive can only
contain the space name; other keywords to describe the space are illegal.
A space can contain from one to four discrete quadrants (See the QUAD
parameter of the .SUBSPA directive.) When you divide a space into
multiple quadrants, you must define all the subspaces within each
quadrant as a group. If subspaces for a quadrant are defined
individually, program operation is unpredictable. The Assembler,
however, does not check for this condition.
Example
This example shows some of the standard “space” definitions in a typical
assembly language program.
.SPACE $TEXT$, SPNUM=0,SORT=8
Chapter 4 107
Assembler Directives and Pseudo-Operations
.SPNUM Pseudo-Operation
.SPNUM Pseudo-Operation
The .SPNUM pseudo-operation reserves a word of storage and initializes
it with the space number of the space named by the operand. Only one
operand is allowed and any label present is offset at the first byte of the
storage just initialized.
Syntax
.SPNUM name
Parameters
name Specifies the name of a space whose space number is
used to initialize a word of storage.
Example
In this example, the space number of $PRIVATE$, 1, is stored as the
address of the symbol LOG by the .SPNUM pseudo-operation.
.SPACE $PRIVATE$,SPNUM=1 SORT=16
.SUBSPA $DATA$,QUAD=1, ALIGN=8,ACCESS=0x1f SORT=24
data_ref
.WORD 0xFFFF
LOG .SPNUM $PRIVATE$
108 Chapter 4
Assembler Directives and Pseudo-Operations
.STRING and .STRINGZ Pseudo-Operations
Syntax
.STRING "init_value"
.STRINGZ "init_value"
Parameters
init_value A sequence of ASCII characters, surrounded by
quotation marks. A string can contain up to 256
characters. The enclosing quotation marks are not
stored.
The following escape sequences can be used to
represent characters:
Chapter 4 109
Assembler Directives and Pseudo-Operations
.STRING and .STRINGZ Pseudo-Operations
Discussion
The .STRING pseudo-operation requests the required number of bytes to
store the string (where each character is stored in a byte). The .STRINGZ
pseudo-operation also requests the required storage for the quoted string
but then appends a zero byte for compatibility with C language strings.
When you label one of these pseudo-operations, the label refers to the
first byte of the storage area.
Examples
This pseudo-operation allocates eight bytes, the first of which is labeled
G. Then it initializes this area with the characters: A, space, S, T, R, I, N,
and G.
G .STRING "A STRING"
This pseudo-operation allocates eight bytes to hold A STRING, allocates
an additional byte for the appended zero, and associates the label G with
the first byte of the storage area.
G .STRINGZ "A STRING"
110 Chapter 4
Assembler Directives and Pseudo-Operations
.SUBSPA Directive
.SUBSPA Directive
The .SUBSPA directive declares a new subspace or switches back to an
old subspace. In 64-bit assembly programs subspaces map directly to the
ELF concept of sections, so the .SUBSPA directive switches to or creates
a new section. For more information, see “Sections in 64-bit Mode” on
page 44.
Syntax
,ACCESS=value
,ALIGN=value
,CODE_ONLY
, COMMON
,DUP_COMM
,FIRST
.SUBSPA name , FROZEN ...
,LOCK
,QUAD=value
,SORT=value
,TSPECIFIC
,UNLOADABLE
,ZERO
Parameters
name An identifier that names the current subspace.
ACCESS=value Specifies the 7-bit value for the access rights field in
the PDIR (Physical Page Directory for virtual address
mapping). Must be 0X2C for code, and 0X1F for data
subspaces.
ALIGN=value Specifies a value (which must be a power of 2) on which
the Assembler should align the beginning of the
subspace. The default value is the largest alignment
requested within that subspace, or one if no alignment
requests exist.
Chapter 4 111
Assembler Directives and Pseudo-Operations
.SUBSPA Directive
112 Chapter 4
Assembler Directives and Pseudo-Operations
.SUBSPA Directive
Discussion
The first time the Assembler encounters a .SUBSPA directive with a new
name, it uses that name to declare a new subspace. As this is the
defining occurrence of that subspace, optional keywords describe
attributes of that subspace.
When the Assembler encounters additional .SUBSPA directives with that
name, it continues that subspace. In this case, the .SUBSPA directive can
only contain the subspace name; other keywords to describe the subspace
are illegal.
Example
This example shows some of the standard “subspace” definitions in a
typical assembly language program.
.SUBSPA $CODE$, QUAD=0,ALIGN=8,ACCESS=0x2c,SORT=24,CODE_ONLY
Chapter 4 113
Assembler Directives and Pseudo-Operations
.VERSION Directive
.VERSION Directive
The .VERSION directive places the designated string in the current
object module for version identification.
Syntax
.VERSION "info_string"
Parameters
info_string A sequence of ASCII characters, surrounded by
quotation marks. The string can contain up to 256
characters.
Discussion
The Assembler places this string in the current object module. A
program can contain multiple .VERSION directives.
Once the version information is in the object file, the HP-UX utility
strings can be used to access it. See strings(1) in HP-UX Reference.
NOTE This directive can appear anywhere in the source file, and multiple
occurrences are permitted.
Example
This program inserts version information into the object module, and
performs subtract and deposit operations.
.CODE
.VERSION "Version 1 of This Simple Sample Program"
SUB %r19,%r20,%r19
DEP %r19,14,5,%r22
.END
114 Chapter 4
Assembler Directives and Pseudo-Operations
.WORD Pseudo-Operation
.WORD Pseudo-Operation
The .WORD pseudo-operation reserves storage and initializes it to the
given value.
Syntax
.WORD [ init_value[ , init_value] ...]
Parameters
init_value A relocatable or absolute expression, a decimal, octal,
or hexadecimal number, or a sequence of ASCII
characters surrounded by quotation marks. If you omit
the initializing value, the Assembler initializes the
area to zero.
Discussion
The .WORD pseudo-operation requests 32 bits of storage. If the location
counter is not properly aligned on a boundary for a data item of that size,
the Assembler advances the location counter to the next multiple of that
item's size before reserving the area.
When you label the pseudo-operation, the label refers to the first byte of
the storage area. Operands separated by commas initialize successive
units of storage.
Example
The first pseudo-operation advances the current subspace's location
counter to a word boundary, allocates a word of storage labeled F and
initializes that word to minus 32 (2's complement). The second
pseudo-operation initializes a word of storage to the hexadecimal
number 6EFF1234.
F .WORD -32
.WORD 0X6eff1234
Chapter 4 115
Assembler Directives and Pseudo-Operations
Programming Aids
Programming Aids
The Assembler provides a series of standard space and subspace
definitions that you can use to simplify the writing of an assembly
program. These definitions are duplicated in the system file
/usr/lib/pcc_prefix.s. Because this file is relatively large and may
change with new releases of the Assembler, you can view the most recent
version of the file on your terminal screen by typing the command:
more /usr/lib/pcc_prefix.s
Table 4-3 on page 116 lists the predefined directives for establishing
standard spaces and subspaces.
Table 4-3 Predefined Subspace Directives
116 Chapter 4
Assembler Directives and Pseudo-Operations
Programming Aids
Chapter 4 117
Assembler Directives and Pseudo-Operations
Programming Aids
118 Chapter 4
5 Pseudo-Instruction Set
119
Pseudo-Instruction Set
B w BL w, %r0
NOP OR %r0,%r0,%r0
1. The cond completer determines the actual instruction that the Assembler uses
in the conditional branch. The T form is used with nonnegated completers. The
F form is used with negated completers. See Table 5-2 on page 121 and
Table 5-3 on page 122 for details.
2. n indicates an optional nullification completer.
120 Chapter 5
Pseudo-Instruction Set
cond Description
never
TR always
Chapter 5 121
Pseudo-Instruction Set
cond Description
never
TR always
122 Chapter 5
6 Assembling Your Program
This chapter describes two different ways you can invoke the Assembler
and the various command line options controlling its behavior. It also
contains a brief description of the interface between the Assembler and
linker, and things you should remember to facilitate the running of an
assembly program.
123
Assembling Your Program
Using the as Command
Syntax
as [ [ option] ...[ file] ...] ...
Parameters
file The name of an input file. The name must include the
suffix .s. If you specify multiple input files, they are
concatenated in order.
option A flag telling the Assembler to take some special
action. All options affect all input files. The as
command supports the following options.
124 Chapter 6
Assembling Your Program
Using the as Command
Chapter 6 125
Assembling Your Program
Using the as Command
126 Chapter 6
Assembling Your Program
Using the cc Command
NOTE If you are using the HP C/HP-UX ANSI C compiler, you can suppress the
pcc_prefix.s file with the cc option +a.
Chapter 6 127
Assembling Your Program
Using the cc Command
cpp Preprocessor
You can use the C preprocessor (cpp) with assembly language programs
to include C-type macros, including directives. You can use an
exclamation point (!) as a statement terminator to include multiple
statements in the body of one macro definition. Furthermore, you can use
the .LABEL directive to declare labels within a macro definition.
NOTE If you use cpp, C-style comments should only be used on separate lines.
128 Chapter 6
7 Programming Examples
129
Programming Examples
1. Binary Search for Highest Bit Position
130 Chapter 7
Programming Examples
1. Binary Search for Highest Bit Position
;
; if extracted bit is zero, fall thru and keep assumption
; else make conclusion
;
EXTRU,= %arg0,0,1,%r0 ; check next bit
ADDI -1,%ret0,%ret0 ; next higher power of 2
B,N tally
all_zeros
LDI -1,%ret0
tally
.LEAVE
.PROCEND
Chapter 7 131
Programming Examples
2. Copying a String
2. Copying a String
This example contains a section of assembly code that moves a byte
string of arbitrary length to an arbitrary byte address.
; The routine reflect copies bytes from the source location
; to the destination location.
;
; The first parameter is the source address and the second
; parameter is the destination address.
;
; The third parameter is the number of bytes to copy.
;
; For performance, larger chunks of bytes are handled differently.
;
.CODE
.EXPORT reflect,ENTRY
reflect
.PROC
.CALLINFO ENTRY_GR=6,SAVE_RP
.ENTER
COMB,=,N %arg2,%r0,fallout ; done, count is zero
COMB,<,N %arg2,%r0,choke ; caller error, neg count
OR %arg0,%arg1,%r6 ; source and dest
OR %r6,%arg2,%r6 ; count
EXTRU,= %r6,31,2,%r0 ; 2 low order bits = 0?
B,N onebyte ; yes, skip this branch
ADDIBT,<,N -16,%arg2,chekchunk ; no, skip chunkify if count<0
chunkify
LDWM 16(%arg0),%r6 ; word 1- > temp1
; point ahead 4 words in source
LDW -12(%arg0),%r5 ; place mark 3 wds back- >temp2
LDW -8(%arg0),%r4 ; place mark 2 wds back- >temp3
LDW -4(%arg0),%r3 ; place mark 1 wds back- >temp4
STW %r5,4(%arg1) ; dest wd 2 <-temp2
STWM %r6,16(%arg1) ; dest wd 1 <-temp1
; point ahead 4 words in dest
STW %r4,-8(%arg1) ; dest wd 3 <-temp3
ADDIBF,< -16,%arg2,chunkify ; loop if count > 0
STW %r3,-4(%arg1) ; dest wd 2 <-temp1
chekchunk
ADDIBT,< 12,%arg2,exeunt ; go if count < -12
COPY %r0,%ret0 ; clear rtnval
subchunk
LDWS,MA 4(%arg0),%r6 ; word- >temp1
; point ahead 4 bytes in source
ADDIBF,< -4,%arg2,subchunk ; go if count<4
STWS,MA %r6,4(%arg1) ; dest< -temp1
; point ahead 4 bytes in dest
132 Chapter 7
Programming Examples
2. Copying a String
onebyte
LDBS,MA 1(%arg0),%r6 ; temp1 < -byte,bump src pointer
onemore
STBS,MA %r6,1(%arg1) ; dest<-temp1,bump dest pointer
ADDIBF,=,N -1,%arg2,onemore ; decrement count
; compare for 0.
LDBS,MA 1(%arg0),%r6 ; delay slot
; temp1 <-byte,bump src pointer
fallout
B exeunt
COPY %r0,%ret0
choke
LDI 14,%ret0
exeunt
.LEAVE
.PROCEND
Chapter 7 133
Programming Examples
3. Dividing a Double-Word Dividend
134 Chapter 7
Programming Examples
3. Dividing a Double-Word Dividend
Register
Purpose
Designations
tp Temporary register.
Chapter 7 135
Programming Examples
4. Demonstrating the Procedure Calling Convention
C Program Listing
#include <stdio.h>
int errorcount = 0;
main ()
{
int toterr = 0;
printf("TESTING FEATURE 000");
fflush(stdout);
if( feat000(000) != -9 ) ++errorcount;
printf(" %d errors\\n",errorcount);
toterr += errorcount;
errorcount = 0;
}
136 Chapter 7
Programming Examples
4. Demonstrating the Procedure Calling Convention
.CODE
.IMPORT errorcount,DATA
.SUBSPA $CODE$
.EXPORT feat000,ENTRY
.PROC
.CALLINFO
feat000 .ENTER
LDI 0,ret0
COMIB,<> myfeat,arg0,exit
NOP
LDI success,ret0
exit .LEAVE
.PROCEND
.END
Chapter 7 137
Programming Examples
5. Output of the cc -S Command
C Program Listing
main ()
{
printf ("Hello World\n");
}
.SPACE $TEXT$
.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44,SORT=16
.SUBSPA $CODE$
.SPACE $PRIVATE$,SORT=16
.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=16
$THIS_DATA$
.ALIGN 4
.STRINGZ “Hello World\n”
.SUBSPA $SHORTDATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=24
138 Chapter 7
Programming Examples
5. Output of the cc -S Command
$THIS_SHORTDATA$
.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82
$THIS_BSS$
.SUBSPA $SHORTBSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=80
$THIS_SHORTBSS$
.SUBSPA $STATICDATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=16
$STATIC_DATA$
.SUBSPA $SHORTSTATICDATA$,QUAD=1,ALIGN=8,ACCESS=31,SORT=24
$SHORT_STATIC_DATA$
.IMPORT $global$,DATA
.SPACE $TEXT$
.SUBSPA $CODE$
.EXPORT main,ENTRY,PRIV_LEV=3,RTNVAL=GR
.IMPORT printf,CODE
.END
Chapter 7 139
Programming Examples
5. Output of the cc -S Command
140 Chapter 7
8 Diagnostic Messages
This appendix lists all error messages that originate from the PA-RISC
Assembler.
The Assembler error messages are divided into the following categories:
Warning Messages Conditions that cause errors in
program execution.
Error Messages Conditions that cause the Assembler
to terminate abnormally.
Panic Messages Conditions that cause the Assembler
to abort immediately.
User Warnings Conditions that cause the Assembler
to produce an object file and possibly
to take a specified corrective action.
Limit Errors Conditions caused by running into
Assembler limits or running out of
memory.
Branching Errors Conditions that prevent the
Assembler from creating an object
file.
Message descriptions use symbols in the form &<operand> to designate
Assembler source elements that are the subject of the error. When a
message is printed during the assembly operation, the &<operand>
symbol is replaced by the appropriate source element.
The text for the Assembler messages is stored in a file with the path
name:
/usr/lib/nls/msg/$LANG/as.cat
The default value for the localization environment variable LANG is C.
141
Diagnostic Messages
Warning Messages
Warning Messages
The following messages describe compiler warnings that prevent the
Assembler from creating an object file. You must correct these errors to
assemble your program.
1 MESSAGE Use of old style opcode, “%s”
CAUSE Attempt to use an opcode that has
been renamed for PA2.0.
ACTION Consult the PA-RISC Architecture
manual for the new form of the
opcode.
2 MESSAGE Unknown option “%s” ignored.
CAUSE An unknown or invalid command-line
option was passed to the assembler.
ACTION Remove the invalid option from the
command-line.
3 MESSAGE Argument is missing for "%s"
CAUSE Missing argument for command-line
option <operand>.
ACTION Add an argument to the
command-line option.
4 MESSAGE Illegal argument for option
“%s”
CAUSE Invalid value for command-line
option <operand>
ACTION Supply a valid value for the
command-line option.
5 MESSAGE Usage of field selector "%s"
with instruction "%s" may be
incorrect
CAUSE Using an improper field selector for
the instruction.
ACTION Change the field selector.
142 Chapter 8
Diagnostic Messages
Warning Messages
Chapter 8 143
Diagnostic Messages
Warning Messages
144 Chapter 8
Diagnostic Messages
Warning Messages
Chapter 8 145
Diagnostic Messages
Warning Messages
146 Chapter 8
Diagnostic Messages
Warning Messages
Chapter 8 147
Diagnostic Messages
Warning Messages
148 Chapter 8
Diagnostic Messages
Warning Messages
Chapter 8 149
Diagnostic Messages
Warning Messages
150 Chapter 8
Diagnostic Messages
Warning Messages
Chapter 8 151
Diagnostic Messages
Warning Messages
152 Chapter 8
Diagnostic Messages
Warning Messages
Chapter 8 153
Diagnostic Messages
Error Messages
Error Messages
The following messages describe compilation errors that prevent the
Assembler from creating an object file. You must correct these errors to
assemble your program.
1000 MESSAGE Unterminated quoted string
CAUSE String specified was missing the
trailing double quote. Strings literals
can not span multiple lines.
ACTION Add trailing double quote to string.
1001 MESSAGE Undefined register symbol
CAUSE Name specified is not a predefined or
.REG defined register symbol
ACTION Correct spelling of name or add .REG
directive to define name.
1002 MESSAGE Undefined completer
CAUSE Invalid value used in completer field.
ACTION Use a proper completer as specified in
PA-RISC Architecture and
Instruction Set Reference Manual.
1003 MESSAGE Improper completer ,%s
specified for opcode %s
CAUSE The completer used is not a valid
completer for the instruction.
ACTION Consult the PA-RISC Architecture
and Instruction Set Reference Manual
for the list of valid completers for this
instruction.
1004 MESSAGE Illegal completer combination
specified for opcode %s
CAUSE The combination of completers used
is not valid for the instruction.
154 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 155
Diagnostic Messages
Error Messages
156 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 157
Diagnostic Messages
Error Messages
158 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 159
Diagnostic Messages
Error Messages
160 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 161
Diagnostic Messages
Error Messages
162 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 163
Diagnostic Messages
Error Messages
164 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 165
Diagnostic Messages
Error Messages
166 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 167
Diagnostic Messages
Error Messages
168 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 169
Diagnostic Messages
Error Messages
170 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 171
Diagnostic Messages
Error Messages
172 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 173
Diagnostic Messages
Error Messages
174 Chapter 8
Diagnostic Messages
Error Messages
Chapter 8 175
Diagnostic Messages
Panic Messages
Panic Messages
The following messages describe panic errors that cause the Assembler
to terminate immediately and prevent it from creating an object file. You
must correct these errors to assemble your program.
2000 MESSAGE Exceeded maximum error count
CAUSE More than 100 errors were detected
and the -e option was not used.
ACTION Use the -e option to permit up to a
million errors.
2002 MESSAGE Unable to open input file: %s
CAUSE The input file is either nonexistent or
unreadable.
ACTION Check for presence of requested input
file and examine the read permission
for the file.
2003 MESSAGE Unable to open output file:
%s
CAUSE One of the following: 1. Output file
exists and is not writable. 2.
Directory is not writable 3. File
system is not writable. 4. File system
full 5. File system error.
ACTION Perform the corresponding action: 1.
Delete output file or make output file
writable. 2. Make directory writable.
3. Use a read/write file system for the
output file. 4. Contact your HP-UX
system administrator 5. Contact your
HP-UX system administrator
2004 MESSAGE Free storage exhausted
CAUSE Assembler cannot allocate memory
for it's internal structures.
176 Chapter 8
Diagnostic Messages
Panic Messages
Chapter 8 177
Diagnostic Messages
User Warning Messages
178 Chapter 8
Diagnostic Messages
User Warning Messages
Chapter 8 179
Diagnostic Messages
User Warning Messages
180 Chapter 8
Diagnostic Messages
User Warning Messages
Chapter 8 181
Diagnostic Messages
User Warning Messages
182 Chapter 8
Diagnostic Messages
Limit Error Messages
Chapter 8 183
Diagnostic Messages
Limit Error Messages
184 Chapter 8
Diagnostic Messages
Limit Error Messages
Chapter 8 185
Diagnostic Messages
Limit Error Messages
186 Chapter 8
Diagnostic Messages
Branching Error Messages
Chapter 8 187
Diagnostic Messages
Branching Error Messages
188 Chapter 8
Diagnostic Messages
Branching Error Messages
Chapter 8 189
Diagnostic Messages
Branching Error Messages
190 Chapter 8
Diagnostic Messages
Branching Error Messages
Chapter 8 191
Diagnostic Messages
Branching Error Messages
192 Chapter 8
Diagnostic Messages
Branching Error Messages
Chapter 8 193
Diagnostic Messages
Branching Error Messages
194 Chapter 8
Index
Index 195
Index
196 Index
Index
Index 197
Index
198 Index
Index
Index 199
Index
C program generating R S
assembly code, 138 register SEC_PROG
copying a string, 132 control, 24 symbols, 86
dividing a double-word floating-point, 23 sections
dividend, 134 general, 23, 35, 48 64-bit mode, 44
programs mnemonics, 23 segments
file, 15 name user-defined, 104 64-bit environment, 44
structure, 19 procedure calling convention, shared libraries
pseudo-instruction, 120 28 creating, 51
ADDB, 120 space, 24, 27 field selectors, 33
ADDIB, 120 typing, 25, 35 spaces, 40
B, 120 register mnemonic specifying object file version,
COMB, 120 previous_sp, 28 105
COMIB, 120 registers shared memory
COPY, 120 arg0, 136 spaces, 40
LDI, 120 r%26, 136 SHN_ABS
MTSAR, 120 r%28, 136 ., 85
NOP, 120 ret0, 136 short addressing, 40
pseudo-instruction set, 119 relocatable single-word to floating-point
pseudo-operation, 53 expressions, 16 value, 88
.BLOCK, 60, 101 legal combinations, 30 soft_reg.h header file, 127
.BLOCKZ, 60 result, 29 sort keys
.BYTE, 62 symbols, 15 and standard subspaces, 43
.DOUBLE, 77 relocatable object file, 15 attribute and subspaces, 42, 43
.DWORD, 78 requesting storage, 74 spaces, 41
.ENTER, 28, 48, 52, 67, 81, reserving a single-word, 108 source file, 15
83, 95, 102 reserving storage, 60, 78, 115 space number, initialized with,
.FLOAT, 88 and initializing to specified 108
.HALF, 89 value, 62 spaces
.LEAVE, 28, 48, 52, 67, 81, 83, initializing to ASCII values, $DEBUG$, 41
95, 102 109 $PRIVATE$, 40, 41, 43, 49, 74
.SPNUM, 108 initializing to specified value, $TEXT$, 40, 41, 43
.STRING, 109 89 .SPACE directive, 41, 106
.STRINGZ, 109 result 64-bit environment, 44
.WORD, 115 absolute, 29 code, 39
list of, 55 relocatable, 29 data, 39
ret0 declaring, 106
Q registers, 136 declaring new, 106
quadrant attribute and returning description, 39
subspaces, 42 to old space, 106 identifiers, 39
to old subspace, 111 memory layout on HP-UX, 41
offsets, 40
quadrant, 40
200 Index
Index
Index 201
Index
options, 124
V
valid symbols, 21
version
.SHLIB_VERSION directive,
105
in object file, 105
inserting string, 114
version levels of PA-RISC, 58, 93
virtual address, 39
W
warnings
messages, 142, 178
202 Index