تبلیغات
تبلیغات
HP pTAL Reference
Manual
Abstract
This publication describes the syntax of pTAL, the Portable Transaction Application
Language for HP NonStop™ systems [TNS/R pTAL compiler (T9248) and TNS/E
EpTAL compiler (T0561)] for system and application programmers.
Product Version
pTAL D44
EpTAL H01
Supported Release Version Updates (RVUs)
This publication supports D44.00, G06.20, H06.08 and all subsequent D-series,
G-series, and H-series RVUs unless otherwise indicated by its replacement
publication.
Part Number
Published
523746-006
November 2006
Document History
Part Number
Product Version
Published
115327
pTAL D40
December 1995
523746-001
pTAL D40
May 2003
523746-002
pTAL D44
September 2003
523746-005
pTAL D44, EpTAL H01
July 2005
523746-006
pTAL D44, EpTAL H01
November 2006
HP pTAL Reference Manual
Glossary
Index
What’s New in This Manual xxxi
Manual Information xxxi
New and Changed Information
Examples
Figures
xxxi
About This Manual xxxiii
Audience xxxiii
Additional Information xxxiii
Notation Conventions xxxvii
1. Introduction to pTAL
pTAL and TAL Compatibility 1-1
EpTAL, pTAL, and TAL Compilers
pTAL Applications 1-3
pTAL Features 1-4
Procedures 1-4
Subprocedures 1-4
Private Data Area 1-4
Recursion 1-5
Parameters 1-5
Data Types 1-5
Data Grouping 1-5
Pointers 1-6
Data Operations 1-6
Bit Operations 1-6
Built-in Routines 1-6
Compiler Directives 1-6
Modular Programming 1-6
System Services 1-6
System Procedures 1-7
pTAL and the CRE 1-7
1-2
Hewlett-Packard Company—523746-006
i
Tables
2. Language Elements
Contents
2. Language Elements
Character Set 2-2
Keywords 2-2
Delimiters 2-4
Operators 2-5
Base Address Symbols 2-7
Indirection Symbols 2-7
Declarations 2-8
Identifiers 2-8
Variables 2-10
Scope 2-10
Constants 2-12
Statements 2-12
3. Data Representation
Data Types 3-1
Specifying Data Types 3-3
Data Type Aliases 3-4
Operations by Data Type 3-4
Address Types 3-5
Storing Addresses in Variables 3-7
Converting Between Address Types and Numeric Data Types 3-7
Converting Between Address Types 3-7
Using Indexes to Access Array Elements 3-9
Incrementing and Decrementing Addresses (Stepping Pointers) 3-10
Constants 3-12
Character String 3-12
STRING Numeric 3-14
INT Numeric 3-15
INT(32) Numeric 3-16
FIXED Numeric 3-17
REAL and REAL(64) Numeric 3-19
Constant Lists 3-21
Constant List Alignment Specification 3-22
4. Data Alignment
Misalignment Tracing Facility
Misalignment Handling 4-3
4-1
HP pTAL Reference Manual—523746-006
ii
5. Expressions
Contents
5. Expressions
Data Types of Expressions 5-2
Operator Precedence 5-3
Arithmetic Expressions 5-5
Signed Arithmetic Operators 5-6
Scaling of FIXED Operands 5-7
Using FIXED(*) Variables 5-8
Unsigned Arithmetic Operators 5-8
Bitwise Logical Operators 5-10
Using Bitwise Logical Operators and INT(32) Operands
Comparing Addresses 5-11
Extended Addresses 5-12
Nonextended Addresses 5-12
Constant Expressions 5-14
Conditional Expressions 5-15
NOT, OR, and AND Operators 5-17
Relational Operators 5-18
Special Expressions 5-20
Assignment 5-20
CASE 5-21
IF 5-23
Group Comparison 5-24
Bit Operations 5-31
Bit Extractions 5-31
Bit Shifts 5-33
6. LITERALs and DEFINEs
Declaring Literals 6-1
Declaring DEFINEs 6-3
Calling DEFINEs 6-5
How the Compiler Processes DEFINEs 6-6
Passing Actual Parameters to DEFINEs 6-7
7. Simple Variables
Declaring Simple Variables 7-1
Specifying Simple Variable Address Types 7-3
Initializing Simple Variables With Numbers 7-4
Initializing Simple Variables With Character Strings
Examples 7-4
7-4
HP pTAL Reference Manual—523746-006
iii
5-10
8. Arrays
Contents
8. Arrays
Declaring Arrays 8-2
Declaring Read-Only Arrays 8-6
Using Constant Lists in Array Declarations
Read-Only Arrays 8-8
Nonstring Arrays 8-9
8-8
9. Structures
Structure Layout 9-3
Overview of Structure Alignment 9-4
Structures Aligned at Odd-Byte Boundaries 9-5
Overview of Field Alignment 9-5
SHARED2 9-6
SHARED8 9-6
PLATFORM 9-7
AUTO 9-7
Differences Between PLATFORM and AUTO 9-8
Field and Base Alignment 9-8
Base Alignment 9-9
Structure Alignment Examples 9-9
Array Alignment in Structures 9-13
Structure Alignment 9-15
Substructure Alignment 9-16
Alignment Considerations for Substructures 9-19
FIELDALIGN Clause 9-20
FIELDALIGN Compiler Directive 9-20
SHARED2 Parameter 9-20
SHARED8 Parameter 9-22
Alignment of Fields 9-24
Optimizing Structure Layouts 9-24
Structure Length 9-26
Alignment of UNSIGNED(17-31) Fields 9-27
Reference Alignment With Structure Pointers 9-27
REFALIGNED Clause 9-28
Default Reference Alignment 9-29
REFALIGNED(2) 9-29
REFALIGNED(8) 9-31
Code Generation for Structure References 9-32
STRUCTALIGN (MAXALIGN) Attribute 9-32
HP pTAL Reference Manual—523746-006
iv
9. Structures (continued)
Contents
9. Structures (continued)
VOLATILE Attribute 9-33
Declaring Definition Structures 9-33
Declaring Template Structures 9-35
Declaring Referral Structures 9-38
Declaring Simple Variables in Structures 9-40
Declaring Arrays in Structures 9-40
Declaring Substructures 9-42
Definition Substructures 9-42
Referral Substructures 9-45
Declaring Filler 9-46
Declaring Simple Pointers in Structures 9-48
Using Simple Pointers 9-49
Assigning Addresses to Pointers in Structures
Declaring Structure Pointers in Structures 9-51
Declaring Redefinitions 9-53
Simple Variable 9-54
Array 9-55
Definition Substructure 9-56
Referral Substructure 9-59
Simple Pointer 9-61
Structure Pointer 9-63
9-50
10. Pointers
Overview of Pointer Declaration 10-2
Declaring VOLATILE Pointers 10-4
Simple 10-4
Structure 10-5
Address Types 10-5
BADDR and WADDR 10-9
SGBADDR, SGWADDR, SGXBADDR, and SGXWADDR
(System Globals)
10-9
PROCADDR (Procedures, Procedure Pointers, and Procedure Entry Points)
10-10
EXTADDR 10-11
Declaring Simple Pointers 10-12
Initializing Simple Pointers 10-14
HP pTAL Reference Manual—523746-006
v
10. Pointers (continued)
Contents
10. Pointers (continued)
Declaring Structure Pointers 10-16
Initializing Structure Pointers 10-17
Declaring System Global Pointers 10-20
11. Equivalenced Variables
Declaring Equivalenced Variables 11-2
Memory Allocation 11-4
Declaring Nonstructure Equivalenced Variables 11-5
Memory Usage for Nonstructured Equivalenced Variables 11-7
Equivalenced Arrays 11-7
Indirect Arrays 11-8
Equivalenced Simple Variables 11-8
Equivalenced Simple Pointers 11-10
Equivalencing PROCADDR Variables and PROCPTR Variables 11-15
Declaring Equivalenced Definition Structures 11-16
Structure Variants 11-20
Memory Usage for Structured Equivalenced Variables 11-21
FIELDALIGN Clause 11-22
System Global Equivalenced Variable Declarations 11-22
Equivalenced Simple Variable 11-23
Equivalenced Definition Structure 11-24
Equivalenced Referral Structure 11-25
Equivalenced Simple Pointer 11-27
Equivalenced Structure Pointer 11-28
12. Statements
Using Semicolons in Statements 12-2
Compound Statements 12-2
ASSERT 12-3
Assignment 12-4
Pointer Assignment 12-6
Assigning Numbers to FIXED Variables
Assigning Character Strings 12-7
Examples 12-8
Bit-Deposit Assignment 12-9
CALL 12-10
CASE 12-12
Empty CASE 12-12
12-7
HP pTAL Reference Manual—523746-006
vi
13. Hardware Indicators
Contents
CASE (continued)
Labeled CASE 12-13
Unlabeled CASE 12-15
DO-UNTIL 12-17
DROP 12-19
Dropping Labels 12-19
Dropping Temporary Variables 12-20
FOR 12-20
Nested 12-21
Standard 12-21
Optimized 12-22
GOTO 12-23
Local 12-23
Nonlocal 12-24
GOTO and Target Statements With Different Trapping States
IF 12-26
Testing Address Types 12-27
Testing Hardware Indicators 12-27
Move 12-28
Destination Shorter Than Source 12-32
$FILL8, $FILL16, and $FILL32 Statements 12-33
RETURN 12-34
Functions 12-35
Procedures and Subprocedures 12-36
Condition Codes 12-37
SCAN and RSCAN 12-40
Determining What Stopped a Scan 12-42
Extended Pointers 12-42
Crossing Variable Boundaries 12-43
P-Relative Arrays 12-43
USE 12-45
WHILE 12-45
13. Hardware Indicators
Managing Overflow Traps 13-1
[NO]OVERFLOW_TRAPS Procedure Attribute 13-2
[EN|DIS]ABLE_OVERFLOW_TRAPS Block Attribute 13-2
Hardware Indicators After Assignments 13-3
$OVERFLOW 13-3
HP pTAL Reference Manual—523746-006
vii
12-24
14. Procedures, Subprocedures, and Procedure
Pointers
Contents
Hardware Indicators After Assignments (continued)
$CARRY 13-4
Condition Codes 13-4
Hardware Indicators in Conditional Expressions 13-8
Nesting Condition Code Tests 13-12
Using Hardware Indicators Across Procedures 13-14
Testing a Hardware Indicator Set in the Calling Procedure 13-14
Returning a Condition Code to the Calling Procedure 13-15
Returning the Value of $OVERFLOW or $CARRY to the Calling Procedure
13-16
14. Procedures, Subprocedures, and Procedure Pointers
Procedure Declarations 14-2
Procedure Attributes 14-5
Parameters and VARIABLE and EXTENSIBLE Procedures 14-8
VARIABLE, EXTENSIBLE and RETURNSCC Procedures as Actual
Parameters 14-9
Formal Parameter Specification 14-10
Using STRUCT as a Formal Parameter 14-16
Passing an .EXT Parameter to a Non-EXTENDED Reference Parameter
Using the PROC Formal Parameter 14-16
Referencing Parameters 14-16
Procedure Body 14-17
Subprocedure Declarations 14-19
Subprocedure Body 14-21
Entry-Point Declarations 14-22
Procedure Entry-Point Identifiers 14-23
Subprocedure Entry-Point Identifiers 14-24
Procedure Pointers 14-26
Declaring PROCPTR Variables 14-29
Declaring PROCPTR in Structures 14-30
Declaring PROCPTRs as Formal Parameters 14-32
Assignments to PROCPTRs 14-33
Dynamically Selected Procedure Calls 14-35
Labels in Procedures 14-37
15. Built-In Routines
Privileged Mode 15-1
Parameters 15-2
Addresses as Parameters 15-2
Expressions as Parameters 15-3
HP pTAL Reference Manual—523746-006
viii
14-16
15. Built-In Routines (continued)
Contents
15. Built-In Routines (continued)
Hardware Indicators 15-4
Atomic Operations 15-4
$ATOMIC_ADD 15-5
$ATOMIC_AND 15-6
$ATOMIC_DEP 15-7
$ATOMIC_GET 15-8
$ATOMIC_OR 15-9
$ATOMIC_PUT 15-10
Nonatomic Operations 15-11
pTAL Privileged Routines 15-11
Type-Conversion Routines 15-12
Address-Conversion Routines 15-14
Character-Test Routines 15-14
Minimum and Maximum Routines 15-15
Arithmetic Routines 15-15
Carry and Overflow Routines 15-15
FIXED-Expression Routines 15-15
Variable-Characteristic Routines 15-16
Procedure-Parameter Routines 15-16
Miscellaneous Routines 15-16
$ABS 15-22
$ALPHA 15-23
$ASCIITOFIXED 15-24
$AXADR 15-26
$BADDR_TO_EXTADDR 15-26
$BADDR_TO_WADDR 15-27
$BITLENGTH 15-28
$BITOFFSET 15-29
$CARRY 15-30
$CHECKSUM 15-31
$COMP 15-32
$COUNTDUPS 15-33
$DBL 15-34
$DBLL 15-35
$DBLR 15-36
$DFIX 15-36
$EFLT 15-37
$EFLTR 15-38
HP pTAL Reference Manual—523746-006
ix
15. Built-In Routines (continued)
Contents
15. Built-In Routines (continued)
$EFLTR 15-38
$EXCHANGE 15-39
$EXECUTEIO 15-40
$EXTADDR_TO_BADDR 15-41
$EXTADDR_TO_WADDR 15-42
$FILL8, $FILL16, and $FILL32 15-42
$FIX 15-44
$FIXD 15-44
$FIXEDTOASCII 15-45
$FIXEDTOASCIIRESIDUE 15-46
$FIXI 15-47
$FIXL 15-48
$FIXR 15-48
$FLT 15-49
$FLTR 15-50
$FREEZE 15-51
$HALT 15-51
$HIGH 15-52
$IFIX 15-52
$INT 15-53
$INT_OV 15-54
$INTERROGATEHIO 15-55
$INTERROGATEIO 15-57
$INTR 15-58
$LEN 15-59
$LFIX 15-60
$LMAX 15-61
$LMIN 15-61
$LOCATESPTHDR 15-62
$LOCKPAGE 15-63
$MAX 15-64
$MIN 15-64
$MOVEANDCXSUMBYTES 15-65
$MOVENONDUP 15-67
$NUMERIC 15-68
$OCCURS 15-69
$OFFSET 15-71
$OPTIONAL 15-73
HP pTAL Reference Manual—523746-006
x
15. Built-In Routines (continued)
Contents
15. Built-In Routines (continued)
$OVERFLOW 15-76
$PARAM 15-77
$POINT 15-78
$PROCADDR 15-78
$READBASELIMIT 15-79
$READCLOCK 15-80
$READSPT 15-80
$READTIME 15-81
$SCALE 15-82
$SGBADDR_TO_EXTADDR 15-83
$SGBADDR_TO_SGWADDR 15-83
$SGWADDR_TO_EXTADDR 15-84
$SGWADDR_TO_SGBADDR 15-85
$SPECIAL 15-85
$STACK_ALLOCATE 15-86
$TRIGGER 15-88
$TYPE 15-88
$UDBL 15-89
$UDIVREM16 15-90
$UDIVREM32 15-91
$UNLOCKPAGE 15-93
$WADDR_TO_BADDR 15-93
$WADDR_TO_EXTADDR 15-94
$WRITEPTE 15-95
$XADR 15-96
16. Compiling and Linking pTAL Programs
Compiling Source Files 16-2
Input Files 16-3
Output Files 16-3
Running the Compiler 16-4
Completion Codes Returned by the Compiler 16-6
Linking Object Files 16-7
Creating a Dynamic Linked Library (DLL) 16-12
Compiling With Global Data Blocks 16-12
Declaring Global Data 16-12
Allocating Global Data Blocks 16-15
Address Assignments 16-15
HP pTAL Reference Manual—523746-006
xi
17. Compiler Directives
Contents
Compiling With Global Data Blocks (continued)
Sharing Global Data Blocks 16-16
Compiling With Saved Global Data 16-17
Using the Code Coverage Tool 16-17
17. Compiler Directives
Specifying Compiler Directives 17-1
Compilation Command 17-1
Directive Line 17-2
File Names as Compiler Directive Arguments 17-3
Directive Stacks 17-4
Pushing Directive Settings 17-4
Popping Directive Settings 17-4
Example 17-5
Toggles 17-5
Named Toggles 17-6
Numeric Toggles 17-6
Examples 17-6
Saving and Using Global Data Declarations 17-8
Saving Global Data Declarations 17-9
Retrieving Global Data Declarations 17-9
Examples 17-10
Migrating from TNS/R to TNS/E 17-11
Summary of Compiler Directives 17-13
ASSERTION 17-19
BEGINCOMPILATION 17-20
BLOCKGLOBALS 17-21
CALL_SHARED 17-22
CHECKSHIFTCOUNT 17-23
CODECOV 17-24
COLUMNS 17-24
DEFEXPAND 17-26
DEFINETOG 17-27
DO_TNS_SYNTAX 17-28
ENDIF 17-29
ERRORFILE 17-30
ERRORS 17-33
EXPORT_GLOBALS 17-33
FIELDALIGN 17-35
HP pTAL Reference Manual—523746-006
xii
17. Compiler Directives (continued)
Contents
17. Compiler Directives (continued)
FMAP 17-36
GLOBALIZED 17-36
GMAP 17-37
GP_OK
17-38
IF and IFNOT 17-39
INNERLIST 17-42
INVALID_FOR_PTAL 17-43
LINES 17-44
LIST 17-44
MAP 17-45
OPTIMIZE 17-47
OPTIMIZEFILE 17-47
OVERFLOW_TRAPS 17-49
PAGE 17-51
PRINTSYM 17-52
REFALIGNED 17-53
RESETTOG 17-54
ROUND 17-55
SAVEGLOBALS 17-56
SECTION 17-57
SETTOG 17-58
SOURCE 17-60
Section Names 17-61
Nesting Levels 17-62
Effect of Other Directives 17-62
Including System Procedure Declarations
Examples 17-64
SRL 17-65
SUPPRESS 17-65
SYMBOLS 17-66
SYNTAX 17-67
TARGET 17-68
USEGLOBALS 17-69
WARN 17-71
17-63
18. pTAL Cross Compiler
NonStop pTAL (ETK) 18-2
pTAL or EpTAL (PC Command Line)
18-3
HP pTAL Reference Manual—523746-006
xiii
18. pTAL Cross Compiler (continued)
Contents
18. pTAL Cross Compiler (continued)
Compilation and Linking 18-5
Debugging 18-6
Tools and Utilities 18-6
NonStop ar Utility 18-6
TACL DEFINE Tool (ETK) 18-7
PC-to-NonStop-Host Transfer Tools
Documentation 18-8
18-7
A. Syntax Summary
Data Types A-1
Constants A-1
Character String A-2
STRING Numeric A-2
INT Numeric A-2
INT(32) Numeric A-2
FIXED Numeric A-3
REAL and REAL(64) Numeric
Constant List A-3
Expressions A-4
Arithmetic A-4
Conditional A-5
Assignment A-5
CASE A-5
IF A-5
Group Comparison A-6
Bit Extraction A-6
Bit Shift A-6
Declarations A-7
LITERAL A-7
DEFINE A-7
Simple Variable A-8
Array A-8
Read-Only Array A-9
Structures A-9
Redefinition A-16
Pointer A-21
Equivalenced Variable A-22
Procedure and Subprocedure
A-3
A-28
HP pTAL Reference Manual—523746-006
xiv
A. Syntax Summary (continued)
Contents
A. Syntax Summary (continued)
Statements A-39
Compound A-39
ASSERT A-40
Assignment A-40
Bit Deposit Assignment A-40
CALL A-41
Labeled CASE A-41
Unlabeled CASE A-42
DO-UNTIL A-42
DROP A-42
FOR A-43
GOTO A-43
IF A-43
Move A-44
RETURN A-44
SCAN and RSCAN A-45
USE A-45
WHILE A-45
Overflow Traps A-46
OVERFLOW_TRAPS Directive A-46
[EN|DIS]ABLE_OVERFLOW_TRAPS Block Attribute
Built-in Routines A-46
Atomic A-46
Nonatomic A-49
Compiler Directives A-87
Directive Line A-89
ASSERTION A-89
BEGINCOMPILATION A-90
BLOCKGLOBALS A-90
CALL_SHARED A-91
CHECKSHIFTCOUNT A-92
CODECOV A-92
COLUMNS A-93
DEFEXPAND A-94
DEFINETOG A-95
DO_TNS_SYNTAX A-96
ENDIF A-96
ERRORFILE A-96
HP pTAL Reference Manual—523746-006
xv
A-46
B. Disk File Names and HP TACL Commands
Contents
Compiler Directives (continued)
ERRORS A-97
EXPORT_GLOBALS A-97
FIELDALIGN A-98
FMAP A-98
GLOBALIZED A-99
GMAP A-99
GP_OK A-100
IF, IFNOT, and ENDIF A-100
INNERLIST A-103
INVALID_FOR_PTAL A-103
LINES A-104
LIST A-104
MAP A-105
OPTIMIZE A-105
OPTIMIZEFILE A-106
OVERFLOW_TRAPS A-107
PAGE A-108
PRINTSYM A-108
REFALIGNED A-109
RESETTOG A-110
ROUND A-111
SAVEGLOBALS A-111
SECTION A-112
SETTOG A-113
SOURCE A-114
SRL A-115
SUPPRESS A-115
SYMBOLS A-116
SYNTAX A-116
TARGET A-117
USEGLOBALS A-118
WARN A-119
B. Disk File Names and HP TACL Commands
Disk File Names B-1
Parts of a Disk File Name
Partial File Names B-3
Logical File Names B-4
B-2
HP pTAL Reference Manual—523746-006
xvi
C. Differences Between the pTAL and EpTAL
Compilers
Contents
Disk File Names (continued)
Internal File Names B-4
HP TACL Commands B-4
DEFINE B-5
PARAM SWAPVOL B-7
ASSIGN B-7
C. Differences Between the pTAL and EpTAL Compilers
General C-1
Data Types and Alignment
Routines C-2
Compiler Directives C-3
C-1
D. RETURN, RETURNSCC, and C/C++ on TNS/E
Glossary
Index
Examples
Example 2-1.
Example 2-2.
Example 2-3.
Example 2-4.
Example 3-1.
Example 3-2.
Example 3-3.
Example 3-4.
Example 3-5.
Example 3-6.
Example 5-1.
Example 5-2.
Example 5-3.
Example 5-4.
Example 5-5.
Example 5-6.
Example 5-7.
Example 5-8.
Example 5-9.
Example 5-10.
Correct Identifiers 2-9
Incorrect Identifiers 2-9
Scope of Declared Items 2-11
Global and Local Variable With the Same Name 2-11
Constant Expressions in Data Type Specifications 3-4
Using Indexing to Access an Array Element 3-9
Adding Integer Values to Addresses 3-10
Subtracting Integer Values From Addresses 3-10
Signed and Unsigned Operators in Address Arithmetic 3-10
Assigning Character Strings to Variables 3-13
Extended Addresses 5-12
Constant Expressions 5-14
Short-Circuit Expression Evaluation 5-17
CASE Expression 5-22
Array Comparison 5-30
Structure Comparison 5-30
Constant Comparison 5-30
Bit Extraction 5-32
Bit Extraction From an Array 5-32
Modifying Bits Before Extracting Them 5-32
HP pTAL Reference Manual—523746-006
xvii
Examples (continued)
Contents
Examples (continued)
Example 5-11.
Example 5-12.
Example 6-1.
Example 6-2.
Example 6-3.
Example 6-4.
Example 6-5.
Example 6-6.
Example 6-7.
Example 6-8.
Example 6-9.
Example 6-10.
Example 6-11.
Example 6-12.
Example 6-13.
Example 7-1.
Example 7-2.
Example 7-3.
Example 7-4.
Example 7-5.
Example 7-6.
Example 8-1.
Example 8-2.
Example 8-3.
Example 8-4.
Example 8-5.
Example 8-6.
Example 8-7.
Example 8-8.
Example 8-9.
Example 8-10.
Example 9-1.
Example 9-2.
Example 9-3.
Example 9-4.
Example 9-5.
Example 9-6.
Example 9-7.
Checking a Bit for a Nonzero Value 5-32
Arithmetic Left Shift 5-34
Literal Declarations 6-2
DEFINE Declarations 6-5
STRUCT and DEFINE Macro Items With the Same Name 6-5
Parenthesized and Nonparenthesized DEFINE Bodies 6-6
Fewer Actual Parameters Than Formal Parameters 6-7
No Actual Parameters 6-7
More Actual Parameters Than Formal Parameters 6-7
Commas in an Actual Parameter 6-7
Parentheses in an Actual Parameter 6-8
Assignment Statement Using DEFINE Macro Identifier 6-8
Incrementing and Decrementing Utilities 6-8
Filling an Array With Zeros 6-8
Checking a Condition Code 6-9
Declaring Simple Variables Without Initializing Them 7-5
Declaring and Initializing Simple Variables 7-5
Effect of fpoint on FIXED Simple Variables 7-5
Initializing Simple Variables With Constants and Variables* 7-6
Declaring Simple VOLATILE Variables 7-6
PROCADDR and PROCPTR 7-6
Declaring Arrays With Various Bounds 8-4
Declaring Arrays and Initializing Them With Constants 8-4
Declaring Arrays and Initializing Them With Constant Lists 8-5
Initializing Arrays 8-5
Array With Positive fpoint 8-5
Array With Negative fpoint 8-5
Read-Only Array Declaration With Indirection Symbol 8-7
Declaring and Initializing a Read-Only Array 8-7
Declaring Read-Only Arrays With Constant Lists 8-8
Declaring Nonstring Arrays With Constant Lists 8-9
Arrays Within Structures 9-13
SHARED2: 2-Byte Alignment 9-14
SHARED8: 4-Byte Alignment 9-14
8-Byte Alignment and 4-Byte Alignment 9-15
SHARED8 Structures With Different Base Alignments 9-15
Well-Aligned Structure With Well-Aligned Substructure 9-16
SHARED8 Structures With SHARED2 Substructures 9-17
HP pTAL Reference Manual—523746-006
xviii
Examples (continued)
Contents
Examples (continued)
Example 9-8.
Example 9-9.
Example 9-10.
Example 9-11.
Example 9-12.
Example 9-13.
Example 9-14.
Example 9-15.
Example 9-16.
Example 9-17.
Example 9-18.
Example 9-19.
Example 9-20.
Example 9-21.
Example 9-22.
Example 9-23.
Example 9-24.
Example 9-25.
Example 9-26.
Example 9-27.
Example 9-28.
Example 9-29.
Example 9-30.
Example 9-31.
Example 9-32.
Example 9-33.
Example 9-34.
Example 9-35.
Example 9-36.
Example 9-37.
Example 9-38.
Example 9-39.
Example 9-40.
Example 9-41.
Example 9-42.
Example 9-43.
Example 9-44.
Example 9-45.
SHARED2 Structures With SHARED8 Substructure 9-17
SHARED8 Structure With SHARED2 Substructure 9-18
Combining SHARED2 and SHARED8 Structures 9-18
AUTO Field Alignment in Structure (Error) 9-19
FIELDALIGN(SHARED2) and REFALIGNED(2) Directives 9-21
Byte Offsets (Decimal) of Fields of a SHARED2 Structure 9-22
Filler Forcing Alignment in a SHARED8 Structure 9-24
Structure With SHARED2 Field Alignment 9-25
Structure With SHARED8 Field Alignment 9-25
Optimized Structure With SHARED8 Field Alignment 9-25
Structures That Need Filler 9-26
Structure Field Crossing an Even-Byte Address (Error) 9-26
Structure That Needs Filler 9-26
SHARED8 Structure With Misaligned UNSIGNED Fields 9-27
SHARED8 Structure With Correctly Aligned UNSIGNED Fields 9-27
REFALIGNED Clause With Structure Pointers 9-28
REFALIGNED Clause 9-28
Default Reference Alignment 9-29
REFALIGNED(2) 9-30
REFALIGNED(8) 9-31
VOLATILE Attribute 9-33
Template Structure Declaration 9-37
Template Structure With STRUCTALIGN(MAXALIGN) 9-37
Referral Structure That References a Template Structure 9-39
Simple Variables Within a Structure 9-40
Arrays Within a Structure 9-41
Using a Zero-Length Array to Initialize a Structure 9-42
Declaring Definition Substructures 9-44
Declaring a Referral Substructure 9-46
Filler Byte Declarations 9-47
Filler Bit Declaration 9-47
Simple Pointers Within a Structure 9-49
Assigning Addresses to Pointers in Structures 9-50
Assigning Addresses to Pointers in Structures 9-51
Declaring a Structure Pointer Within a Structure 9-53
Simple Variable Redefinition 9-55
Array Redefinition 9-56
Definition Substructure Redefinition 9-58
HP pTAL Reference Manual—523746-006
xix
Examples (continued)
Contents
Examples (continued)
Example 9-46.
Example 9-47.
Example 9-48.
Example 9-49.
Example 10-1.
Example 10-2.
Example 10-3.
Example 10-4.
Example 10-5.
Example 10-6.
Example 10-7.
Example 10-8.
Example 10-9.
Example 10-10.
Example 10-11.
Example 10-12.
Example 10-13.
Example 10-14.
Example 10-15.
Example 10-16.
Example 10-17.
Example 10-18.
Example 10-19.
Example 10-20.
Example 11-1.
Example 11-2.
Example 11-3.
Example 11-4.
Example 11-5.
Example 11-6.
Example 11-7.
Example 11-8.
Example 11-9.
Example 11-10.
Example 11-11.
Definition Substructure Redefinition 9-59
Referral Substructure Redefinition 9-60
Simple Pointer Redefinition 9-62
Structure Pointer Redefinition 9-64
Declaring VOLATILE Simple Pointers 10-4
Declaring VOLATILE Structure Pointers 10-5
Determining Address Types 10-7
BADDR and WADDR 10-9
SGBADDR, SGWADDR, SGXBADDR, and SGXWADDR 10-9
PROCADDR 10-10
CBADDR and CWADDR 10-11
EXTADDR Declarations 10-11
Declaring But Not Initializing a Simple Pointer 10-15
Declaring and Initializing a Simple Pointer 10-15
Declaring and Initializing a STRING Simple Pointer 10-15
Declaring and Initializing Simple Pointers 10-15
Declaring and Initializing a Simple Pointer, Using $XADR 10-16
Declaring and Initializing an Extended Simple Pointer 10-16
Declaring and Initializing a Structure Pointer, Using $OFFSET 10-18
Declaring and Initializing a STRING Structure Pointer 10-18
Declaring and Initializing a Local Structure Pointer 10-19
Declaring and Initializing a Local STRING Structure Pointer 10-19
Declaring and Initializing a Local STRING Structure Pointer 10-19
System Global Pointer Declaration 10-20
Declaring Equivalenced Variables 11-3
Equivalenced Pointers 11-4
Memory Usage for Nonstructured Equivalenced Variables 11-7
Read-Only Pointer 11-12
Equivalenced Objects of Unequal Length 11-14
REFALIGNED Clause for Equivalenced Simple Pointers 11-15
Equivalencing PROCADDR and PROCPTR Variables 11-15
Declaring Equivalenced Structures 11-18
Structure Variants 11-20
Structure Variants 11-20
Memory Usage for Structured Equivalenced Variables
(Incorrect) 11-21
Example 11-12. Memory Usage for Structured Equivalenced Variables
(Correct) 11-21
HP pTAL Reference Manual—523746-006
xx
Examples (continued)
Contents
Examples (continued)
Example 11-13.
Example 11-14.
Example 11-15.
Example 11-16.
Example 11-17.
Example 11-18.
Example 12-1.
Example 12-2.
Example 12-3.
Example 12-4.
Example 12-5.
Example 12-6.
Example 12-7.
Example 12-8.
Example 12-9.
Example 12-10.
Example 12-11.
Example 12-12.
Example 12-13.
Example 12-14.
Example 12-15.
Example 12-16.
Example 12-17.
Example 12-18.
Example 12-19.
Example 12-20.
Example 12-21.
Example 12-22.
Example 12-23.
Example 12-24.
Example 12-25.
Example 12-26.
Example 12-27.
Example 12-28.
Example 12-29.
FIELDALIGN Clause in Structured Equivalenced Variables 11-22
Equivalenced Simple Variable Declaration 11-24
Equivalenced Definition Structure Declaration 11-25
Equivalenced Referral Structure Declaration 11-26
Equivalenced Simple Pointer Declaration 11-28
Equivalenced Structure Pointer Declaration 11-29
Null Compound Statement 12-3
Compound Statement 12-3
ASSERTION Directive and ASSERT Statement 12-4
Assignment Statements 12-8
Assignment Statements Equivalent to a Constant List 12-8
Assignment Statement With Assignment Expressions 12-8
CALL Statement 12-12
Empty CASE Statement 12-12
Labeled CASE Statement 12-14
Labeled CASE Statement 12-15
Unlabeled CASE Statement 12-16
Unlabeled CASE Statement 12-17
Unlabeled CASE Statement Assigning Text to Array 12-17
DO-UNTIL Statement 12-18
DO-UNTIL Statement 12-18
DO-UNTIL Statement With Hardware Indicator 12-19
DO-UNTIL Statement With GOTO Statement 12-19
Nested FOR Statement 12-21
Standard FOR Statement 12-22
Standard and Optimized FOR Statements 12-22
Local GOTO Statement 12-23
Nonlocal GOTO Statement 12-24
Local GOTO and Target Statements That Have Different Trapping
States 12-24
Nonlocal GOTO and Target Statements That Have Different Trapping
States 12-25
IF Statement 12-26
MOVE Statement Copying to an Array 12-31
MOVE Statement Copying Bracketed and Unbracketed
Constants 12-31
MOVE Statement Copying From One Structure to Another 12-31
MOVE Statement Copying a Substructure 12-32
HP pTAL Reference Manual—523746-006
xxi
Examples (continued)
Contents
Examples (continued)
Example 12-30.
Example 12-31.
Example 12-32.
Example 12-33.
Example 12-34.
Example 12-35.
Example 12-36.
Example 12-37.
Example 12-38.
Example 12-39.
Example 12-40.
Example 12-41.
Example 12-42.
Example 12-43.
Example 12-44.
Example 12-45.
Example 12-46.
Example 12-47.
Example 12-48.
Example 12-49.
Example 12-50.
Example 12-51.
Example 12-52.
Example 13-1.
Example 13-2.
Example 13-3.
Example 13-4.
Example 13-5.
Example 13-6.
Example 13-7.
Example 14-1.
Example 14-2.
MOVE Statement With Destination Shorter Than Source 12-32
FILL16 Statement 12-33
RETURN Statements Nested in an IF Statement 12-35
RETURN Statement That Returns a Value and a Condition
Code 12-35
Testing a Condition Code 12-35
RETURN Statement in a Procedure 12-36
RETURN Statement in a Procedure That Returns a Condition
Code 12-37
Procedure Without RETURNSCC 12-37
Procedure With RETURNSCC 12-37
Function Without RETURNSCC 12-38
Function With RETURNSCC 12-38
Condition Code Returned by Function Called by CALL
Statement 12-39
Condition Code Based on Numeric Value 12-39
Condition Code That Is Independent of the Function’s Value 12-40
Invalid Function That Attempts to Return an Explicit Condition
Code 12-40
SCAN UNTIL Statement 12-42
Determining What Stopped a Scan 12-42
Extended Pointers in SCAN and RSCAN Statements 12-42
Scanning Adjacent Fields Within a Structure 12-43
Scanning Data in a P-Relative Array 12-44
Scanning Data in a P-Relative Array 12-44
WHILE Statement 12-46
WHILE Statement 12-46
OVERFLOW_TRAPS Compiler Directive and Procedure
Attribute 13-2
ENABLE_OVERFLOW_TRAPS and DISABLE_OVERFLOW_TRAPS
Block Attributes 13-3
Assignments After Which You Can Test Condition Codes 13-7
Hardware Indicators in DO-UNTIL Statements 13-9
Hardware Indicators in WHILE Statements 13-9
Testing a Hardware Indicator Set in a Calling Procedure 13-15
Returning the Value of $OVERFLOW in a Reference
Parameter 13-16
Procedure Declaration 14-4
EXTENSIBLE Procedures as Actual Parameters 14-9
HP pTAL Reference Manual—523746-006
xxii
Examples (continued)
Contents
Examples (continued)
Example 14-3.
Example 14-4.
Example 14-5.
Example 14-6.
Example 14-7.
Example 14-8.
Example 14-9.
Example 14-10.
Example 14-11.
Example 14-12.
Example 14-13.
Example 14-14.
Example 14-15.
Example 14-16.
Example 14-17.
Example 14-18.
Example 14-19.
Example 14-20.
Example 14-21.
Example 15-1.
Example 15-2.
Example 15-3.
Example 15-4.
Example 15-5.
Example 15-6.
Example 15-7.
Example 15-8.
Example 15-9.
Example 15-10.
Example 15-11.
Example 15-12.
Example 15-13.
Example 15-14.
Example 15-15.
Example 15-16.
Example 15-17.
Example 15-18.
Function With Value and Reference Formal Parameters 14-15
Reference Structure as a Formal Reference Parameter 14-15
Using a Referral STRUCT as a Formal Parameter 14-16
Procedures 14-18
FORWARD Declaration for a Procedure 14-18
Function Subprocedure 14-22
Procedure Entry-Point Identifiers 14-23
FORWARD Declarations for Entry Points 14-24
Subprocedure Entry-Point Identifiers 14-25
PROCPTRs as Variables and Formal Parameters 14-30
PROCPTR in a Structure 14-31
PROCPTRs in Structure 14-31
Code That Uses the Structure in Example 14-14 on
page 14-31 14-31
PROCPTRs as Formal Parameters 14-32
Assignments to PROCPTRs 14-33
Assignments to PROCPTRs 14-34
Dynamically Selected Procedure Call 14-35
Dynamically Selected Procedure Call 14-36
IF Statements Identified by Labels 14-37
Built-In Routine With Address Parameter 15-2
Built-In Routine With Address Output Parameter 15-3
$ATOMIC_ADD Routine 15-5
$ATOMIC_AND Routine 15-6
$ATOMIC_DEP Routine 15-7
$ATOMIC_GET Routine 15-8
$ATOMIC_OR Routine 15-9
$ATOMIC_PUT Routine 15-10
$ABS Routine 15-23
$ALPHA Routine 15-24
$ASCIITOFIXED Routine 15-25
$AXADR Routine 15-26
$BADDR_TO_EXTADDR Routine 15-27
$BADDR_TO_WADDR Routine 15-27
$BITLENGTH Routine 15-28
$BITOFFSET Routine 15-29
$CARRY Routine 15-30
$CHECKSUM Routine 15-32
HP pTAL Reference Manual—523746-006
xxiii
Examples (continued)
Contents
Examples (continued)
Example 15-19.
Example 15-20.
Example 15-21.
Example 15-22.
Example 15-23.
Example 15-24.
Example 15-25.
Example 15-26.
Example 15-27.
Example 15-28.
Example 15-29.
Example 15-30.
Example 15-31.
Example 15-32.
Example 15-33.
Example 15-34.
Example 15-35.
Example 15-36.
Example 15-37.
Example 15-38.
Example 15-39.
Example 15-40.
Example 15-41.
Example 15-42.
Example 15-43.
Example 15-44.
Example 15-45.
Example 15-46.
Example 15-47.
Example 15-48.
Example 15-49.
Example 15-50.
Example 15-51.
Example 15-52.
Example 15-53.
Example 15-54.
Example 15-55.
Example 15-56.
$COMP Routine 15-32
$COUNTDUPS Routine 15-34
$DBL Routine 15-35
$DBLL Routine 15-35
$DBLR Routine 15-36
$DFIX Routine 15-37
$EFLT Routine 15-37
$EFLTR Routine 15-38
$EFLTR Routine 15-39
$EXECUTEIO Routine 15-41
$EXTADDR_TO_BADDR Routine 15-41
$EXTADDR_TO_WADDR Routine 15-42
$FILL8 Procedure 15-43
$FIX Routine 15-44
$FIXD Routine 15-45
$FIXEDTOASCII Routine 15-46
$FIXEDTOASCIIRESIDUE Routine 15-47
$FIXI Routine 15-48
$FIXL Routine 15-48
$FIXR Routine 15-49
$FLT Routine 15-50
$FLTR Routine 15-50
$HIGH Routine 15-52
$IFIX Routine 15-53
$INT Routine 15-54
$INT Routine 15-54
Difference Between $INT and $INT_OV 15-55
$INTERROGATEHIO Routine 15-56
$INTERROGATEIO Routine 15-58
$INTR Routine 15-59
$LEN Routine 15-59
$LEN Routine 15-60
$LEN Routine 15-60
$LFIX Routine 15-61
$LMAX Routine 15-61
$LMIN Routine 15-62
$LOCATESPTHDR Routine 15-63
$LOCKPAGE Routine 15-64
HP pTAL Reference Manual—523746-006
xxiv
Examples (continued)
Contents
Examples (continued)
Example 15-57.
Example 15-58.
Example 15-59.
Example 15-60.
Example 15-61.
Example 15-62.
Example 15-63.
Example 15-64.
Example 15-65.
Example 15-66.
Example 15-67.
Example 15-68.
Example 15-69.
Example 15-70.
Example 15-71.
Example 15-72.
Example 15-73.
Example 15-74.
Example 15-75.
Example 15-76.
Example 15-77.
Example 15-78.
Example 15-79.
Example 15-80.
Example 15-81.
Example 15-82.
Example 15-83.
Example 15-84.
Example 15-85.
Example 15-86.
Example 15-87.
Example 15-88.
Example 15-89.
Example 15-90.
Example 15-91.
Example 15-92.
Example 15-93.
Example 15-94.
$MAX Routine 15-64
$MIN Routine 15-65
$MOVEANDCXSUMBYTES Routine 15-66
$MOVENONDUP Routine 15-68
$NUMERIC Routine 15-68
$OCCURS Routine With Nonstructure Arrays 15-70
$OCCURS Routine With Structure Arrays 15-71
$OCCURS Routine With Template Structure Arrays 15-71
$OFFSET Routine 15-72
$OFFSET Routine 15-72
$OFFSET Routine Applied to a Template Structure 15-73
Parameters Passed Conditionally and Unconditionally 15-74
Parameters Omitted Conditionally and Unconditionally 15-75
Parameters Passed Conditionally 15-75
$OPTIONAL Routine for a Front-End Interface 15-75
$OVERFLOW Routine 15-77
$PARAM Routine 15-77
$POINT Routine 15-78
$READBASELIMIT Routine 15-79
$READCLOCK Routine 15-80
$READSPT Routine 15-81
$READTIME Routine 15-81
$SCALE Routine 15-82
Using the $SCALE Routine to Maintain Precision 15-83
$SGBADDR_TO_EXTADDR Routine 15-83
$SGBADDR_TO_SGWADDR Routine 15-84
$SGWADDR_TO_EXTADDR Routine 15-85
$SGWADDR_TO_SGBADDR Routine 15-85
$SPECIAL Routine 15-86
$STACK_ALLOCATE Routine 15-87
$TRIGGER Routine 15-88
$TYPE Routine 15-89
$UDBL Routine 15-90
$UDIVREM16 Routine 15-91
$UDIVREM32 Routine 15-92
$UNLOCKPAGE Routine 15-93
$WADDR_TO_BADDR Routine 15-94
$WADDR_TO_EXTADDR Routine 15-94
HP pTAL Reference Manual—523746-006
xxv
Examples (continued)
Contents
Examples (continued)
Example 15-95.
Example 15-96.
Example 16-1.
Example 16-2.
Example 16-3.
Example 16-4.
Example 16-5.
Example 16-6.
Example 17-1.
Example 17-2.
Example 17-3.
Example 17-4.
Example 17-5.
Example 17-6.
Example 17-7.
Example 17-8.
Example 17-9.
Example 17-10.
Example 17-11.
Example 17-12.
Example 17-13.
Example 17-14.
Example 17-15.
Example 17-16.
Example 17-17.
Example 17-18.
Example 17-19.
Example 17-20.
Example 17-21.
Example 17-22.
Example 17-23.
Example 17-24.
Example 17-25.
Example 17-26.
Example 17-27.
Example 17-28.
$WRITEPTE Routine 15-95
$XADR Routine 15-96
Compiler Command Lines 16-2
Naming a Compilation Unit 16-13
Declaring a Named Data Block 16-13
Data Block and Variable With the Same Name 16-13
Declaring a Private Data Block 16-14
Declaring Unblocked Data 16-14
Compilation Commands With Compiler Directives 17-2
Pushing and Popping a Directive Stack 17-5
DEFINETOG, IF, and ENDIF Directives 17-7
DEFINETOG, IFNOT, and ENDIF Directives Directive 17-7
SETTOG, IF, and ENDIF Directives 17-7
SETTOG, IFNOT, and ENDIF Directives 17-7
SETTOG, RESETTOG, IF, and ENDIF Directives 17-8
MYPROG Source File for Example 17-9 Through
Example 17-12 17-10
Saving Global Data Declarations and Data Initializations 17-10
Retrieving Global Data Declarations and Data Initializations 17-11
Checking the Syntax of Global Data Declarations 17-11
Recompiling MYPROG After Correcting Errors 17-11
Original SAVEGLOBALS Compilation Source File 17-12
New GLOBALS Source File 17-12
Corrected SAVEGLOBALS Compilation Source File 17-13
DEFEXPAND Directive 17-27
FIXERRS Macro 17-32
ERRORFILE Directive 17-32
ERRORS Directive 17-33
GP_OK, NOGP_OK, PUSHGP_OK, and POPGP_OK
Directive 17-39
IF Directive Without Matching ENDIF Directive 17-41
IF Directive With Matching ENDIF Directive 17-42
INNERLIST and NOINNERLIST Directives 17-43
Listing Source Code But Not System Declarations 17-45
File for OPTIMIZEFILE Directive 17-48
OVERFLOW_TRAPS Compiler Directive 17-50
PAGE Directive 17-51
PRINTSYM Directive 17-52
HP pTAL Reference Manual—523746-006
xxvi
Examples (continued)
Contents
Examples (continued)
Example 17-29. ROUND Directive 17-56
Example 17-30. SECTION Directive 17-58
Example 17-31. SOURCE Directive Specifying System Procedure
Declarations 17-63
Example 17-32. Procedure That Calls Procedures Specified by SOURCE
Directive 17-64
Example 17-33. SOURCE Directive 17-64
Example 17-34. SOURCE Directive 17-64
Example 17-35. SOURCE Directive 17-64
Example 17-36. SUPPRESS Directive 17-66
Example 17-37. SYMBOLS Directive 17-67
Example 17-38. SYNTAX Directive 17-68
Example 17-39. SYNTAX Directive 17-68
Example B-1.
Disk File Name B-2
Example B-2.
DEFINE Names B-6
Example D-1. C Procedure Extracting Two pTAL Return Values from a 64-Bit Value
(Works Only on TNS/R Systems—Not Recommended) D-2
Example D-2. C Procedure Extracting Only the Traditional Function Value from a 64Bit Value (Works Only on TNS/R Systems) D-3
Example D-3. Migrating a pTAL Procedure With Two Return Values to TNS/E
(Works on TNS/R and TNS/E Systems) D-3
Figures
Figure 5-1.
Figure 5-2.
Figure 5-3.
Figure 9-1.
Figure 9-2.
Figure 9-3.
Figure 9-4.
Figure 11-1.
Figure 11-2.
Figure 11-3.
Figure 11-4.
Figure 11-5.
Figure 16-1.
Parentheses’ Effect on Operator Precedence 5-4
Ending Address After Comparing INT Strings 5-27
Ending Address After Comparing Strings of Data Type STRING and
INT 5-28
Alignment of SHARED8 Structure With Base Alignment of 8 9-10
Well-Aligned and Misaligned SHARED8 Structures With Base Alignment
of 8 9-11
Alignment of a SHARED8 Structure With Base Alignment of 4 9-12
Well-Aligned and Misaligned SHARED8 Structures With Base Alignment
of 4 9-13
Indirect Array 11-8
Equivalenced Simple Variables 11-10
The Object and Address Types of a Pointer 11-13
Equivalenced Simple Pointer Declaration 11-14
Equivalenced Definition Structure for CISC Architecture 11-19
Compiling and Linking pTAL Programs 16-1
HP pTAL Reference Manual—523746-006
xxvii
Figures (continued)
Contents
Figures (continued)
Figure 16-2.
Figure 16-3.
Figure 16-4.
Figure 16-5.
Creating a Loadfile on TNS/E for TNS/E 16-8
Creating Loadfiles on TNS/R for TNS/R 16-9
Creating a Loadfile on TNS for TNS/R 16-10
Producing Hybrid Loadfiles 16-11
Tables
Table i.
Table ii.
Table iii.
Table iv.
Table 1-1.
Table 1-2.
Table 2-1.
Table 2-2.
Table 2-3.
Table 2-4.
Table 2-5.
Table 2-6.
Table 2-7.
Table 2-8.
Table 2-9.
Table 3-1.
Table 3-2.
Table 3-3.
Table 3-4.
Table 3-5.
Table 4-1.
Table 5-1.
Table 5-2.
Table 5-3.
Table 5-4.
Table 5-5.
Table 5-6.
Table 5-7.
Table 5-8.
Table 5-9.
Table 5-10.
Table 5-11.
Related Manuals xxxiv
System Manuals xxxiv
Programming Manuals xxxiv
Program Development Manuals xxxv
EpTAL, pTAL, and TAL Compiler Characteristics 1-2
HP NonStop Operating Systems 1-2
Special Characters 2-2
Reserved Keywords 2-3
Nonreserved Keywords 2-3
Delimiters 2-4
Operators 2-5
Base Address Symbols 2-7
Indirection Symbols 2-7
Identifier Classes 2-9
Variable Types 2-10
Storage Units 3-1
Data Types 3-1
Operations by Data Type 3-4
Data Types and Their Address Types 3-5
Valid Address Conversions 3-9
TNS/R Native Atomic Misalignment Handling Methods
Precedence of Operators 5-3
Operands in Arithmetic Expressions 5-5
Arithmetic Expressions 5-6
Signed Arithmetic Operators 5-6
Signed Arithmetic Operand and Result Types 5-6
Unsigned Arithmetic Operators 5-8
Unsigned Arithmetic Operand and Result Types 5-9
Bitwise Logical Operators 5-10
Valid Address-Type Comparisons 5-11
Valid Address Expressions 5-13
Conditional Expressions 5-16
HP pTAL Reference Manual—523746-006
xxviii
4-3
Tables (continued)
Contents
Tables (continued)
Table 5-12.
Table 5-13.
Table 5-14.
Table 5-15.
Table 5-16.
Table 5-17.
Table 5-18.
Table 9-1.
Table 9-2.
Table 9-3.
Table 9-4.
Table 9-5.
Table 9-6.
Table 9-7.
Table 9-8.
Table 10-1.
Table 10-2.
Table 11-1.
Table 11-2.
Table 11-3.
Table 11-4.
Table 12-1.
Table 13-1.
Table 14-1.
Table 15-1.
Table 15-2.
Table 15-3.
Table 15-4.
Table 15-5.
Table 15-6.
Table 15-7.
Table 15-8.
Table 15-9.
Table 15-10.
Table 15-11.
Table 15-12.
Table 15-13.
Table 15-14.
Conditions in Conditional Expressions 5-16
Results of NOT, OR, and AND Operators 5-17
Signed Relational Operators 5-18
Unsigned Relational Operators 5-19
Special Expressions 5-20
Bit Operations 5-31
Bit-Shift Operators 5-34
Kinds of Structures 9-1
Structure Items 9-3
Base Alignment and Field Alignment Relationships 9-9
Field Alignment of Substructures 9-19
Variable Alignment 9-22
Data Accessed by Simple Pointers 9-49
Addresses in Simple Pointers 9-50
Addresses in Structure Pointers 9-53
Address Types 10-6
Object Data Types and Their Addresses 10-7
Equivalenced Variables 11-1
Equivalenced Variable Terminology 11-1
Valid Equivalenced Variable Declarations 11-2
Data Types for Equivalenced Variables 11-13
Summary of Statements 12-1
Hardware Indicators 13-1
Formal Parameter Specification 14-14
Built-In Routines for Atomic Operations 15-4
pTAL Privileged Routines 15-11
Built-In Type-Conversion Routines 15-12
Built-In Address-Conversion Routines 15-14
Built-In Character-Test Routines 15-14
Built-In Minimum and Maximum Routines 15-15
Built-In Arithmetic Routines 15-15
Built-In Carry and Overflow Routines 15-15
Built-In FIXED-Expression Routines 15-15
Built-In Variable-Characteristic Routines 15-16
Built-In Procedure-Parameter Routines 15-16
Miscellaneous Built-In Routines 15-16
Built-In Routines for Nonatomic Operations 15-17
$OCCURS for Nonstructure Arrays 15-69
HP pTAL Reference Manual—523746-006
xxix
Tables (continued)
Contents
Tables (continued)
Table 15-15.
Table 16-1.
Table 17-1.
Table 17-2.
Table 17-3.
Table 18-1.
$OCCURS for Structure Arrays and Arrays Within Structures
Completion Codes 16-6
Compiler Directives by Category 17-14
Compiler Directives by Name 17-17
Data Block Names 17-21
pTAL Cross Compiler Platforms 18-1
HP pTAL Reference Manual—523746-006
xxx
15-70
What’s New in This Manual
Manual Information
HP pTAL Reference Manual
Abstract
This publication describes the syntax of pTAL, the Portable Transaction Application
Language for HP NonStop™ systems [TNS/R pTAL compiler (T9248) and TNS/E
EpTAL compiler (T0561)] for system and application programmers.
Product Version
pTAL D44
EpTAL H01
Supported Release Version Updates (RVUs)
This publication supports D44.00, G06.20, H06.08 and all subsequent D-series,
G-series, and H-series RVUs unless otherwise indicated by its replacement
publication.
Part Number
Published
523746-006
November 2006
Document History
Part Number
Product Version
Published
115327
pTAL D40
December 1995
523746-001
pTAL D40
May 2003
523746-002
pTAL D44
September 2003
523746-005
pTAL D44, EpTAL H01
July 2005
523746-006
pTAL D44, EpTAL H01
November 2006
New and Changed Information
This manual has been updated to describe the following new features:
•
•
CODECOV directive (Guardian) and -codecov directive (Windows)
GLOBALIZED directive (Guardian) and -globalized directive (Windows)
HP pTAL Reference Manual—523746-006
xxxi
New and Changed Information
What’s New in This Manual
HP pTAL Reference Manual—523746-006
xxxii
About This Manual
The Portable Transaction Application Language for HP NonStop systems (pTAL) is a
high-level, block-structured language used to write systems software and transactionoriented applications.
This manual gives guidelines for using the pTAL language and the EpTAL and pTAL
compilers, including:
•
•
•
How to create, structure, compile, and run a pTAL program
The process environment, addressing modes, and storage allocation
How to declare and access procedures and variables
You can compile pTAL source programs with either the pTAL compiler or the EpTAL
compiler (for their differences, see Table 1-1 on page 1-2).
In this manual:
Word
Meaning (unless otherwise specified)
compiler
The pTAL and EpTAL compilers
linker
The nld, ld, and eld linkers
Topics:
•
•
•
Audience on page xxxiii
Additional Information on page xxxiii
Notation Conventions on page xxxvii
Audience
This manual is intended for system programmers and application programmers familiar
with NonStop systems.
Additional Information
•
•
•
•
Table i, Related Manuals, on page xxxiv
Table ii, System Manuals, on page xxxiv
Table iii, Programming Manuals, on page xxxiv
Table iv, Program Development Manuals, on page xxxv
HP pTAL Reference Manual—523746-006
xxxiii
Additional Information
About This Manual
Table i. Related Manuals
Manual
Description
pTAL Conversion Guide
Provides information needed to convert TAL
programs to pTAL programs.
pTAL Guidelines for TAL Programmers
Gives guidelines for writing TAL code that you
can migrate later to pTAL code with as few
changes as possible.
TAL Programmer’s Guide
Helps you get started in creating, structuring,
compiling, running and debugging programs.
Explains how to declare and access procedures
and variables and how the TAL compiler
allocates storage for variables.
TAL Reference Manual
Describes the syntax for declaring variables and
procedures and for specifying expressions,
statements, built-in routines, and compiler
directives. Lists error and warning messages.
TAL Reference Summary
Summarizes the TAL syntax diagrams.
Table ii. System Manuals
Manual
Description
D-Series System Migration Planning Guide
Gives guidelines for migrating from a C-series
system to a D-series system
Introduction to D-Series Systems
Provides an overview of D-series
enhancements to the Guardian operating
system
Introduction to Tandem NonStop Systems
Provides an overview of the system hardware
and software
TACL Reference Manual
Describes the syntax of HP TACL
Table iii. Programming Manuals (page 1 of 2)
Manual
Description
C/C++ Programmer’s Guide
Contains information that you need
about HP C and C++ for NonStop
systems if you plan to call HP C and
C++ routines from pTAL programs
COBOL Manual for TNS and TNS/R Programs
Contains information that you need
about HP COBOL for TNS and TNS/R
programs if you plan to call
HP COBOL routines from pTAL
programs
HP pTAL Reference Manual—523746-006
xxxiv
Additional Information
About This Manual
Table iii. Programming Manuals (page 2 of 2)
Manual
Description
COBOL Manual for TNS/E Programs
Contains information that you need
about HP COBOL for TNS/E
programs if you plan to call
HP COBOL routines from pTAL
programs
CRE Programmer’s Guide
Explains how to use the Common
Runtime Environment (CRE) for
running mixed-language programs
Guardian Application Conversion Guide
Gives guidelines for converting
C-series TNS programs to D-series
TNS programs, and for converting
TNS programs to TNS/R programs
Guardian Procedure Calls Reference Manual
Describes the syntax and
programming considerations for using
system procedures
Guardian Procedure Errors and Messages Manual
Describes error codes, error lists,
system messages, and trap numbers
for system procedures
Guardian Programmer’s Guide
Explains how to use the programmatic
interface of the operating system
H-Series Application Migration Guide
Explains how to migrate programs
from TNS/R to TNS/E
TAL Programmer’s Guide
Contains information that you need
about the HP Transaction Application
Language (TAL) if you plan to call TAL
routines from TNS HP COBOL
programs
TAL Programmer’s Guide Data Alignment
Addendum
Documents the data alignment
requirements of TAL
Table iv. Program Development Manuals (page 1 of 3)
Manual
Description
Accelerator Manual
Explains how to accelerate TNS object files
for a TNS/R system
Accelerator Manual Data Alignment
Addendum
Documents the data alignment
requirements of the Accelerator
Binder Manual
Explains how to bind TNS compilation units
(or modules) using Binder
CROSSREF Manual
Explains how to collect cross-reference
information using the stand-alone Crossref
product
HP pTAL Reference Manual—523746-006
xxxv
Additional Information
About This Manual
Table iv. Program Development Manuals (page 2 of 3)
Manual
Description
Debug Manual
Explains how to debug programs using the
Debug machine-level interactive debugger
DLL Programmer’s Guide for TNS/E Systems
Explains position-independent code (PIC)
and dynamic-link libraries (DLLs) on TNS/E
systems
DLL Programmer’s Guide for TNS/R Systems
Explains position-independent code (PIC)
and dynamic-link libraries (DLLs) on TNS/R
systems
Edit User’s Guide and Reference Manual
Explains how to create and edit a text file
using the Edit line and virtual-screen text
editor
eld Manual
Explains how to use the eld utility to link
and change the attributes of TNS/E object
files
EMS Manual
Describes the Event Management Service
(EMS). The misalignment tracing facility
generates EMS events (see Misalignment
Tracing Facility on page 4-1)
enoft Manual
Explains how to use the enoft utility to
display TNS/E object files
Inspect Manual
Explains how to debug programs using the
Inspect source-level and machine-level
interactive debugger
ld Manual
Explains how to use the ld utility to link and
change the attributes of TNS/R PIC object
files
Native Inspect Manual
Explains how to debug programs using the
Native Inspect source-level and machinelevel interactive debugger
nld Manual
Explains how to use the nld utility to link
and change the attributes of TNS/R nonPIC object files and how the ar utility works
noft Manual
Explains how to use the noft utility to
display TNS/R object files (PIC and nonPIC)
Object Code Accelerator Manual
Explains how to accelerate TNS and TNS/R
object files for a TNS/E system.
PS Text Edit Reference Manual
Explains how to create and edit a text file
using the PS Text Edit full-screen text editor
HP pTAL Reference Manual—523746-006
xxxvi
Notation Conventions
About This Manual
Table iv. Program Development Manuals (page 3 of 3)
Manual
Description
SCF Reference Manual for the Kernel
Subsystem
Describes the Subsystem Control Facility
(SCF), whose user interface you can use to
control tracing (see Misalignment Tracing
Facility on page 4-1)
Visual Inspect online help
Explains how to debug programs using the
Visual Inspect source-level and machinelevel interactive debugger
Code Coverage Tool Reference Manual
Explains how to use the Code Coverage
Tool to generate code coverage reports.
Notation Conventions
•
•
•
•
Hypertext Links on page xxxvii
Syntax Diagram Conventions on page xxxvii
Notation for Messages on page xli
Change Bar Notation on page xlii
Hypertext Links
Blue underline is used to indicate a hypertext link within text. By clicking a passage of
text with a blue underline, you are taken to the location described. For example:
This requirement is described under Audience on page xxxiii.
Syntax Diagram Conventions
This manual presents syntax in railroad diagrams. Here is a generic railroad diagram:
KEYWORD
item1
item3
item2
,
item4
«item5»
VST406.vsd
HP pTAL Reference Manual—523746-006
xxxvii
Syntax Diagram Conventions
About This Manual
To use a railroad diagram, follow the direction of the arrows and specify syntactic items
as indicated by the diagram pieces:
Diagram Piece
Meaning
Type KEYWORD as shown. You can type letters in uppercase or
lowercase.
KEYWORD
VST412.vsd
Replace item with a value that fits its description, which follows the
syntax diagram.
item
VST413.vsd
Type content (punctuation mark, symbol, or letter) as shown. You can
type a letter in uppercase or lowercase.
,
VST414.vsd
Some examples of the meanings of simple diagrams are:
Diagram Piece
Meaning
Choose item1 or item2.
item1
item2
VST407.vsd
Choose item1, item2, or neither.
item1
item2
VST408.vsd
item
,
Specify item one or more times, separating occurrences
with commas.
VST409.vsd
item
Specify item at most n times.
n
VST742.vsd
Note. To refer to a particular railroad diagram or figure when giving feedback to HP, use the
number at the bottom right corner of that railroad diagram or figure (for example, VST742.vsd).
HP pTAL Reference Manual—523746-006
xxxviii
Syntax Diagram Conventions
About This Manual
Spacing rules are:
•
If the arrow between two diagram pieces is labelled “ns,” put no spaces between
the syntactic items that they represent. For example:
ns
volume
$
VST420.vsd
means that you type:
$NEWVOL
not
$ NEWVOL
•
An “ns” on the top line of a choice structure applies to the lower lines in the choice
structure as well. For example:
ns
"
ns
RETURN^SORT^ERRORS
"
RETURN_SORT_ERRORS_
VST185.vsd
means that you type one of the following:
"^RETURN^SORT^ERRORS"
"RETURN_SORT_ERRORS_"
•
If two diagram pieces are not separated by a separator character (such as a
comma, semicolon, or parenthesis), separate the syntactic items that they
represent by at least one space or a new line. For example:
MULTIPLY
integer1
integer2
VST410.vsd
means that you type:
MULTIPLY 3 4
not
MULTIPLY34
HP pTAL Reference Manual—523746-006
xxxix
Syntax Diagram Conventions
About This Manual
•
If two diagram pieces are separated by a separator character, separating the
syntactic items that they represent by spaces is optional. For example:
MULTIPLY
integer1
,
integer2
VST411.vsd
means that you type:
MULTIPLY 3,4
or
MULTIPLY 3, 4
•
If a diagram piece is immediately followed by a period, putting spaces between the
syntactic item and the period is optional. For example:
END
PROGRAM
program-name
.
VST374.vsd
means that you can type:
END PROGRAM SORT.
or
END PROGRAM SORT .
•
Diagram elements need not be on the same line. For example:
block-name
BLOCK
BEGIN
VST184.vsd
BLOCK DATA BEGIN
is equivalent to:
BLOCK DATA
BEGIN
•
Explicit spacing rules given for individual railroad diagrams override the
aforementioned rules.
HP pTAL Reference Manual—523746-006
xl
Notation for Messages
About This Manual
Notation for Messages
The following list summarizes the notation conventions for the presentation of
displayed messages in this manual.
Bold Text. Bold text in an example indicates user input entered at the terminal. For
example:
ENTER RUN CODE
?123
CODE RECEIVED:
123.00
The user must press the Return key after typing the input.
Nonitalic text. Nonitalic letters, numbers, and punctuation indicate text that is displayed or
returned exactly as shown. For example:
Backup Up.
lowercase italic letters. Lowercase italic letters indicate variable items whose values are
displayed or returned. For example:
p-register
process-name
[ ] Brackets. Brackets enclose items that are sometimes, but not always, displayed. For
example:
BLOCK = BEGIN [: block_attribute ]
declarations
END;
A group of items enclosed in brackets is a list of all possible items that can be
displayed, of which one or none might actually be displayed. The items in the list might
be arranged either vertically, with aligned brackets on each side of the list, or
horizontally, enclosed in a pair of brackets and separated by vertical lines. For
example:
LANGUAGE [ UNSPECIFIED | C | PASCAL | FORTRAN ]
{ } Braces. A group of items enclosed in braces is a list of all possible items that can be
displayed, of which one is actually displayed. The items in the list might be arranged
either vertically, with aligned braces on each side of the list, or horizontally, enclosed in
a pair of braces and separated by vertical lines. For example:
BLOCK_ATTRIBUTE = { ENABLE_OVERFLOW_TRAPS | DISABLE_OVERFLOW_TRAPS }
| Vertical Line. A vertical line separates alternatives in a horizontal list that is enclosed in
brackets or braces. For example:
Transfer status: { OK | Failed }
HP pTAL Reference Manual—523746-006
xli
Change Bar Notation
About This Manual
% Percent Sign. A percent sign precedes a number that is not in decimal notation. The %
notation precedes an octal number. The %B notation precedes a binary number. The
%H notation precedes a hexadecimal number. For example:
%005400
%B101111
%H2F
Change Bar Notation
Change bars are used to indicate substantive differences between this edition of the
manual and the preceding edition. Change bars are vertical rules placed in the right
margin of changed portions of text, figures, tables, examples, and so on. Change bars
highlight new or revised information. For example:
The CRE has many new message types and some new message type codes for
old message types. In the CRE, the message type SYSTEM includes all messages
except LOGICAL-CLOSE and LOGICAL-OPEN.
HP pTAL Reference Manual—523746-006
xlii
1
Introduction to pTAL
pTAL is based on the HP Transaction Application Language (TAL). You can compile
pTAL source code with either the pTAL or EpTAL compiler.
Topics:
•
•
•
•
•
•
•
pTAL and TAL Compatibility on page 1-1
EpTAL, pTAL, and TAL Compilers on page 1-2
pTAL Applications on page 1-3
pTAL Features on page 1-4
System Services on page 1-6
System Procedures on page 1-7
pTAL and the CRE on page 1-7
pTAL and TAL Compatibility
The pTAL and TAL languages are the same except that TAL supports constructs that
depend on characteristics of the underlying TNS architecture, while pTAL (with a few
exceptions) does not depend on the underlying TNS/R architecture or TNS/E
architecture. For example, pTAL code cannot:
•
•
•
Access a caller’s stack marker
Use CODE statements to execute instructions
Build parameter masks for calls to variable or EXTENSIBLE procedures
Because pTAL uses few machine-dependent constructs, it works efficiently with the
system hardware to provide optimal object program performance and is more portable
than TAL.
Most pTAL and TAL declarations and executable statements have the same syntax
and semantics. Minor semantic differences might affect your programs; for these
differences, you must change your source code.
To accommodate migration from TAL to pTAL, pTAL retains some of TAL’s operability.
For information about pTAL and TAL differences, see:
•
•
pTAL Conversion Guide
pTAL Guidelines for TAL Programmers
HP pTAL Reference Manual—523746-006
1 -1
EpTAL, pTAL, and TAL Compilers
Introduction to pTAL
EpTAL, pTAL, and TAL Compilers
Note. This topic includes only enough information about the TAL compiler to compare it to the
EpTAL and pTAL compilers. For complete information about the TAL compiler, see:
•
•
•
TAL Reference Manual
TAL Programmer’s Guide
TAL Programmer’s Guide Data Alignment Addendum
You can compile pTAL source programs using either the pTAL compiler or the EpTAL
compiler.
Table 1-1. EpTAL, pTAL, and TAL Compiler Characteristics
Compiler
Object Code Generated
EpTAL
TNS/E object code—PIC (position-independent code)
pTAL
TNS/R object code—Non-PIC (default) or PIC
TAL
TNS object code—Non-PIC
Difference between pTAL and EpTAL compilers:
pTAL Compiler
EpTAL Compiler
On Guardian platforms, object files have the
file code 700
On Guardian platforms, object files have the
file code 800
The compilers in Table 1-1 on page 1-2 execute under control of the HP NonStop
operating systems in Table 1-2 on page 1-2.
Table 1-2. HP NonStop Operating Systems
Architecture
RVU
TNS/E
G06.20 and later
H06.01 and later
TNS/R
D40 and later
TNS
C-series
D-series
This manual indicates when pTAL behaves differently on TNS/E and TNS/R
architectures. When no architecture is specifically mentioned, the syntax works the
same way on TNS/E and TNS/R architectures.
HP pTAL Reference Manual—523746-006
1 -2
pTAL Applications
Introduction to pTAL
For more information:
Topic
Source
Itanium® chips used in TNS/E
systems
Intel Itanium Architecture Software Developer’s Manual
RISC chips used in TNS/R
systems
MIPS RISC Architecture by Gerry Kane and Joe Heinrich
TNS/R or TNS/E architecture
System description manual for your system
Compiling pTAL source
programs
Section 16, Compiling and Linking pTAL Programs
pTAL Applications
The pTAL language is appropriate for writing applications where optimal performance
has high priority, for example:
•
•
Systems software
°
°
°
°
°
Operating system components
Compilers and interpreters
Command interpreters
Special subsystems
Special routines that support data communication activities
Transaction-oriented applications
°
°
Server processes used with HP data management software
°
°
Procedures that are callable from programs written in other languages
Conversion routines that allow data transfer between HP software and other
applications
Applications that require optimal performance
You cannot embed SQL/MP or SQL/MX statements in pTAL source code.
HP pTAL Reference Manual—523746-006
1 -3
pTAL Features
Introduction to pTAL
pTAL Features
•
•
•
•
•
•
•
•
•
•
•
•
•
Procedures on page 1-4
Subprocedures on page 1-4
Private Data Area on page 1-4
Recursion on page 1-5
Parameters on page 1-5
Data Types on page 1-5
Data Grouping on page 1-5
Pointers on page 1-6
Data Operations on page 1-6
Bit Operations on page 1-6
Built-in Routines on page 1-6
Compiler Directives on page 1-6
Modular Programming on page 1-6
Procedures
Each pTAL program contains one or more procedures. A procedure is a discrete
sequence of declarations and statements that performs a specific task. A procedure is
callable from anywhere in the program.
Each procedure executes in its own environment and can contain local variables that
are not affected by the actions of other procedures. When a procedure calls another
procedure, the operating system saves the caller’s environment and restores that
environment when the called procedure returns control to the caller.
Subprocedures
A procedure can contain subprocedures, callable only from within the same procedure.
A subprocedure can have sublocal variables that are not affected by the actions of
other subprocedures. When a subprocedure calls another subprocedure, the caller’s
environment remains in place. The operating system saves the location in the caller to
which control is to return when the called subprocedure terminates.
Private Data Area
Each activation of a procedure or subprocedure has its own data area. Upon
termination, each activation relinquishes its private data area, thereby minimizing the
amount of memory that the program uses.
HP pTAL Reference Manual—523746-006
1 -4
Recursion
Introduction to pTAL
Recursion
Because each activation of a procedure or subprocedure has its own data area, a
procedure or subprocedure can call itself or can call another procedure that in turn
calls the original procedure.
Parameters
A procedure or subprocedure can have optional or required parameters. The same
procedure or subprocedure can process different sets of variables sent by different
calls to it.
Data Types
A pTAL program can declare and refer to the following types of data:
Data Type
Description
STRING
8-bit integer byte
INT, INT(16)
16-bit integer word
INT(32)
32-bit integer doubleword
FIXED, FIXED(0), INT(64)
64-bit integer quadrupleword
FIXED(-19 to -1)
Fixed-point quadrupleword
FIXED(1 to 19)
Fixed-point quadrupleword
REAL, REAL(32)
32-bit floating-point doubleword
REAL(64)
64-bit floating-point quadrupleword
UNSIGNED(n)
n-bit field, where 1 <= n <= 31
BADDR
32-bit byte address
WADDR
32-bit 2-byte address
CBADDR
32-bit byte code word address
CWADDR
32-bit 2-byte code word address
SGBADDR
16-bit SG-relative byte address
SGWADDR
16-bit SG-relative 2-byte address
SGXBADDR
32-bit SG-relative 2-byte address
SGXWADDR
32-bit SG-relative 2-byte address
EXTADDR
32-bit byte address
PROCADDR
32-bit code byte address
Data Grouping
A pTAL program can declare and use groups of related variables, such as arrays and
structures (records).
HP pTAL Reference Manual—523746-006
1 -5
Pointers
Introduction to pTAL
Pointers
A pTAL program can declare pointers (variables that can contain addresses) and use
them to access locations throughout memory. You can store addresses in pointers
when you declare them or later in your program.
Data Operations
A pTAL program can copy a contiguous group of words or bytes and compare one
group with another. It can scan a series of bytes for the first byte that matches (or fails
to match) a given character.
Bit Operations
A pTAL program can perform bit deposits, bit extractions, and bit shifts.
Built-in Routines
A pTAL program can use built-in routines to convert data types and addresses, test for
an ASCII character, or determine the length, offset, type, or number of occurrences of
a variable.
Compiler Directives
You can use directives to control a compilation. You can, for example, check the syntax
in your source code or control the content of compiler listings.
Modular Programming
You can divide a large pTAL program into modules, compile them separately, and then
link the resulting object files into a new object file.
System Services
Your program can ignore many things such as the presence of other running programs
and whether your program fits into memory. For example, programs are loaded into
memory for you and absent pages are brought from disk into memory as needed.
HP pTAL Reference Manual—523746-006
1 -6
System Procedures
Introduction to pTAL
System Procedures
The file system treats all devices as files, including disk files, disk packs, terminals,
printers, and programs running on the system. File-system procedures provide a
file-access method that lets you ignore the peculiarities of devices. Your program can
refer to a file by the file’s symbolic name without knowing the physical address or
configuration status of the file.
Your program can call system procedures that activate and terminate programs
running on any processor on the system, and can also call system procedures that
monitor the operation of a running program or processor. If the monitored program
stops or a processor fails, your program can determine this fact.
For more information about system procedures see:
•
•
Guardian Procedure Calls Reference Manual
Guardian Programmer’s Guide
pTAL and the CRE
pTAL does not have a run-time environment defined by a run-time library such as HP C
and HP COBOL. The CRE provides a common foundation for language-specified runtime libraries that enables mixed-language programming.
A program with a pTAL main routine cannot run in the CRE because pTAL does not
perform the necessary initialization of the run-time environment. pTAL routines can run
in the CRE if they are called from a program with an HP C main routine. There are
additional restrictions on what operations can be performed in the pTAL routines. For
complete details on writing pTAL routines that run in the CRE, see the CRE
Programmer’s Guide.
HP pTAL Reference Manual—523746-006
1 -7
pTAL and the CRE
Introduction to pTAL
HP pTAL Reference Manual—523746-006
1 -8
2
Language Elements
The elements that make up the pTAL language include:
•
•
•
•
•
•
•
•
•
Character Set on page 2-2
Keywords on page 2-2
Delimiters on page 2-4
Operators on page 2-5
Base Address Symbols on page 2-7
Indirection Symbols on page 2-7
Declarations on page 2-8
Constants on page 2-12
Statements on page 2-12
HP pTAL Reference Manual—523746-006
2 -1
Character Set
Language Elements
Character Set
pTAL supports the complete ASCII character set, which includes:
•
•
•
Uppercase and lowercase alphabetic characters (A through Z.)
Numeric characters (0 through 9)
Special characters
Table 2-1. Special Characters
Character
Description
Character
Description
!
Exclamation point
"
Quotation mark
$
Dollar sign
%
Percent sign
&
Ampersand
'
Apostrophe
(
Opening parenthesis
)
Closing parenthesis
*
Asterisk
+
Plus
,
Comma
-
Hyphen (minus)
.
Period (decimal point)
/
Right slash
:
Colon
;
Semicolon
<
Less than
=
Equals
>
Greater than
?
Question mark
@
Commercial at sign
[
Opening bracket
\
Back slash
]
Closing bracket
^
Circumflex
_
Underscore
`
Grave accent
{
Opening brace
|
Vertical line
}
Closing brace
~
Tilde
Keywords
Keywords have predefined meanings to the compiler when used as shown in the
syntax diagrams in this manual.
Keyword Type
Description
Reserved
Reserved by the compiler. Do not use reserved keywords (shown in
Table 2-2 on page 2-3) for your identifiers.
Nonreserved
You can use nonreserved keywords anywhere identifiers are allowed
except as noted in the Restrictions column of Table 2-3 on page 2-3.
HP pTAL Reference Manual—523746-006
2 -2
Keywords
Language Elements
.
Table 2-2. Reserved Keywords
AND
DOWNTO
INT
PROC
SGXWADDR
ASSERT
ELSE
INTERRUPT
PROCADDR
UNTIL
BADDR
END
LABEL
PROCPTR
USE
BEGIN
ENTRY
LAND
REAL
VARIABLE
BY
EXTERNAL
LITERAL
REFALIGNED
VOLATILE
CALL
EXTADDR
LOR
RESIDENT
WADDR
CALLABLE
FIELDALIGN
MAIN
RETURN
WHILE
CASE
FIXED
NOT
RSCAN
XOR
CBADDR
FOR
OF
SCAN
SGXWADDR
CWADDR
FORWARD
OR
SGBADDR
DEFINE
GOTO
OTHERWISE
SGWADDR
DO
IF
PRIV
SGXBADDR
Table 2-3. Nonreserved Keywords (page 1 of 2)
Keyword
Restrictions
AT
Allowed in BLOCK declarations
AUTO
None
BELOW
Allowed in BLOCK declarations
BIT_FILLER
Not to be used as an identifier within a structure
BLOCK
Not to be used as an identifier in a source file that contains the NAME
declaration
BYTES
Not to be used as an identifier of a LITERAL or DEFINE
C
None
ELEMENTS
Not to be used as an identifier of a LITERAL or DEFINE
EXT
None
EXTENSIBLE
None
FILLER
Not to be used as an identifier within a structure
LANGUAGE
None
NAME
None
NODEFAULT
None
PRIVATE
Not to be used as an identifier in a source file that contains the NAME
declaration
RETURNSCC
None
SHARED2
None
HP pTAL Reference Manual—523746-006
2 -3
Delimiters
Language Elements
Table 2-3. Nonreserved Keywords (page 2 of 2)
Keyword
Restrictions
SHARED8
None
UNSPECIFIED
None
WORDS
Not to be used as an identifier of a LITERAL or DEFINE
Delimiters
Delimiters are symbols that begin, end, or separate fields of information. Delimiters tell
the compiler how to handle the fields of information.
Table 2-4. Delimiters (page 1 of 2)
Symbol
Character
Representation
Uses
!
Exclamation mark
Begins and optionally ends a comment
--
Two consecutive
hyphens
Begins a comment
,
Comma
Separates fields of information, such as in declarations,
statements, directives, and constant lists
;
Semicolon
.
Period
Separates identifier levels in a qualified structure item
identifier
<n :n >
Angle brackets
Delimits a bit field in a bit operation
:
Colon
()
Parentheses
•
•
•
•
•
•
•
•
•
•
•
[n :n ]
Square brackets
Terminates data declarations
Separates statements
Separates declaration options
Denotes a statement label
Denotes a procedure entry point
Denotes an ASSERT statement assert level
Denotes a parameter pair
Delimit subexpressions within an expression
Delimit the parameter list of a DEFINE, procedure,
subprocedure, or CALL statement
Delimit the referral in a structure pointer
declaration
Delimit the implied decimal point position in a
FIXED variable
Delimit the bounds specification in the declaration of an
array, structure, or substructure
HP pTAL Reference Manual—523746-006
2 -4
Operators
Language Elements
Table 2-4. Delimiters (page 2 of 2)
Symbol
->
Character
Representation
Hyphen plus right
angle bracket
Uses
•
•
•
•
Begins one or more labels in a labeled CASE
statement
Begins a next-addr clause in a SCAN or
RSCAN statement
Begins a next-addr clause in a move statement
Begins a next-addr clause in a group
comparison expression
"string "
Quotation marks
Delimit a character string
""
Consecutive
quotation marks
The first quotation mark indicates that the second
quotation mark is not a delimiter in a character string
=
Equal sign
= body #
Equal sign and hash
mark
Delimit the body in a DEFINE declaration
‘,’
Single quotation
marks
Delimit a comma that is not a delimiter in a DEFINE
parameter
$
Dollar sign
Denotes a built-in routine (such as $ABS) or a built-in
routine (such as $ASCIITOFIXED)
?
Question mark
Begins a directive line
•
•
•
Used in LITERAL declarations
Used in equivalence variable declarations
Used in redefinition declarations
Operators
Operators specify operations, such as arithmetic or assignments, that you want to
perform on data items.
Table 2-5. Operators (page 1 of 2)
Context
Operator
Description
Assignment
:=
Data declaration initialization; assignment
statement, FOR statement, and
assignment expression
Move statement
':='
Left-to-right move
'=:'
Right-to-left move
&
Concatenated move
Labeled CASE statement
. .(two periods)
Describes a range of case alteratives
Remove indirection
@
Accesses the address contained in a
pointer or the address of a nonpointer item
Repetition
* (asterisk)
Repetition factor in a constant list
HP pTAL Reference Manual—523746-006
2 -5
Operators
Language Elements
Table 2-5. Operators (page 2 of 2)
Context
Operator
Description
Template structure
(*)
Template structure declaration
FIXED(*) parameter type
(*)
Value parameter to be treated as FIXED
Bit-field access
. (period)
Accesses a bit-deposit or bit-extraction
field (<n > or <n :n >)
Bit shift
<<
Signed left shift
>>
Signed right shift
'<<'
Unsigned left shift
'>>'
Unsigned right shift
+
Signed addition
-
Signed subtraction
*
Signed multiplication
/
Signed division
'+'
Unsigned addition
'-'
Unsigned subtraction
'*'
Unsigned multiplication
'/'
Unsigned division
'\'
Unsigned modulo division
LOR
Logical OR bit-wise operation
LAND
Logical AND bit-wise operation
XOR
Exclusive OR bit-wise operation
<
Signed less than
=
Signed equal to
>
Signed greater than
<=
Signed less than or equal to
>=
Signed greater than or equal to
<>
Signed not equal to
'<'
Unsigned less than
'='
Unsigned equal to
'>'
Unsigned greater than
'<='
Unsigned less than or equal to
'>='
Unsigned greater than or equal to
'<>'
Unsigned not equal to
AND
Logical conjunction
OR
Logical disjunction
NOT
Logical negation
Arithmetic expression
Relational expression
HP pTAL Reference Manual—523746-006
2 -6
Base Address Symbols
Language Elements
Base Address Symbols
Base address symbols let you declare pointers to specific data segments.
Table 2-6. Base Address Symbols
Symbol
Description
'P'
P-register addressing (read-only array declaration)
'SG'
Define base address equivalencies, system global space (privileged
procedures only)
'SGX'
References data in the system data segment.
Indirection Symbols
Indirection symbols determine the address types of variables. Use indirection symbols
when declaring formal parameters to cause them to be passed by reference (rather
than by value).
Table 2-7. Indirection Symbols
Symbol
. (period)
.EXT
Declares ...
•
•
•
•
An array or structure as having standard direct addressing
A simple pointer or structure pointer
An array or structure as having extended addressing
An extended (32-bit) simple pointer or structure pointer
.SG
A standard (16-bit) system global pointer
.SGX
An extended (32-bit) system global pointer
HP pTAL Reference Manual—523746-006
2 -7
Declarations
Language Elements
Declarations
Declarations allocate storage and associate identifiers with declarable objects in a
program; that is:
•
•
•
•
•
Variables
LITERALs and DEFINEs (see Section 6, LITERALs and DEFINEs)
Procedures (see Section 14, Procedures, Subprocedures, and Procedure Pointers)
Labels (see Labels in Procedures on page 14-37)
Entry points (see Entry-Point Declarations on page 14-22)
Topics:
•
•
•
Identifiers on page 2-8
Variables on page 2-10
Scope on page 2-10
Identifiers
Identifiers must conform to these rules:
•
•
•
•
•
•
Identifiers can have up to 132 characters. You can limit the identifier to 31
characters by setting the DO_TNS_SYNTAX on page 17-28.
Identifiers begin with an alphabetic character, an underscore (_), or a
circumflex (^).
Identifiers contain alphabetic characters, numeric characters, underscores, or
circumflexes.
Identifiers contain lowercase and uppercase alphabetic characters. The compiler
treats all characters as uppercase.
Identifiers cannot be reserved keywords (see Table 2-2 on page 2-3).
Identifiers can be nonreserved keywords, except as noted in Table 2-3 on
page 2-3.
In addition to the preceding rules, HP recommends that you:
•
•
Use underscores rather than circumflexes to separate words in identifiers (for
example, use Name_Using_Circumflexes rather than
Name^Using^Circumflexes). This guideline reflects international character-set
standards, which allow the character printed for the circumflex to vary by country.
Do not end identifiers with an underscore. The trailing underscore is reserved for
identifiers supplied by the operating system (such as
Name_Using_Trailing_Underscore_).
HP pTAL Reference Manual—523746-006
2 -8
Identifiers
Language Elements
Example 2-1. Correct Identifiers
a2
HP
_2345678012_31_characters
name_with_exactly_31_characters
Example 2-2. Incorrect Identifiers
Identifier
Problem
2abc
Begins with a number
ab%99
Contains % symbol
VARIABLE
Reserved word
Each identifier belongs to an identifier class. The compiler determines the identifier
class based on how you declare the identifier.
.
Table 2-8. Identifier Classes
Class
Description
Block
Global data block
Code
Read only (P-relative) array
Variable
Simple variable, array, nonstructure pointer, structure pointer, structure, or
structure data item
DEFINE*
Named text
Function
Procedure or subprocedure that returns a value
Label
Statement label
LITERAL
Named constant
PROC
Procedure or subprocedure that does not return a value
Template
Template structure
* Available only on Guardian platforms.
HP pTAL Reference Manual—523746-006
2 -9
Variables
Language Elements
Variables
A variable is a symbolic representation of data. It can be a single-element variable or a
multiple-element variable. You use variables to store data that can change during
program execution.
Before you can access data stored in a variable you must either:
•
•
Initialize the variable with a value when you declare the variable
Assign a value to the variable after you declare the variable
.
Table 2-9. Variable Types
Variable Type
Description
Simple variable
A variable that contains one element of a specified data type
Array
A variable that contains multiple elements of the same data type
Structure
A variable that can contain variables of different data types
Substructure
A structure nested within a structure or substructure
Structure item
A simple variable, array, simple pointer, substructure, or
structure pointer declared in a structure or substructure; also
known as a structure field
Nonstructure pointer
A variable that contains a memory address, usually of a simple
variable or an array element, which you can access with this
nonstructure pointer
Structure pointer
A variable that contains the memory address of a structure,
which you can access with this structure pointer
Scope
Every declared item in a pTAL program has a scope that determines where in the
program it is visible (after the point of declaration).
Scope
Declared in a ...
Visible ...
Global
Program
Everywhere in the program
Local
Procedure
Only in the procedure that declares it (including the
subprocedures of that procedure)
Sublocal
Subprocedure
Only in the subprocedure that declares it
Formal parameters of procedures and subprocedures have local and sublocal scope,
respectively.
HP pTAL Reference Manual—523746-006
2- 10
Scope
Language Elements
Example 2-3. Scope of Declared Items
int i;
! i has global scope and is visible everywhere
! from this point forward.
proc p;
! p has global scope. If p had formal
! parameters, they would have local scope.
begin
int j := i;
subproc s;
! j has local scope and is visible everywhere in
! procedure p from this point forward.
! s has local scope. If s had formal parameters,
! they would have sublocal scope.
begin
int k := i + j;
! k has sublocal scope and is visible only
! in subprocedure s.
end;
! k is not visible here. It is created and destroyed every
! time subprocedure s is called.
end;
! j is not visible here. It is created and destroyed every time
! procedure p is called.
! i is accessible here and exists as long as the program is
! running.
Variables that have different scopes can have the same name, but they are different
variables.
Example 2-4. Global and Local Variable With the Same Name
int(32) i;
proc p;
begin
int i;
i := i + 1D;
end;
! This i is global
! This i is local to procedure p, different
! from global variable i, and makes access to
! global variable i impossible ("hides" it).
! ERROR: local variable i is INT(16)
For local and sublocal variables, the compiler generates code to evaluate and store an
initialization expression. For example, for the expression
int k := i * j;
if i, j, and k are local or sublocal variables, the compiler generates code to multiply i
by j and store the product in k.
For global variables, the compiler does not generate such initialization code. Initial
values assigned to global variables are determined by the linker.
HP pTAL Reference Manual—523746-006
2- 11
Constants
Language Elements
Constants
A constant is a value you can store in a variable, declare as a LITERAL, or use as part
of an expression. Constants can be numbers or character strings. The following are
examples of constants:
Constant Type
Example
Character string
"abc"
Numeric
654
You can specify numeric constants in binary, octal, decimal, or hexadecimal base,
depending on the data type of the item. The default number base in pTAL is decimal.
The following are example constants in each number base:
Number Base
Example
Decimal
47
Binary
%B101111
Octal
%57
Hexadecimal
%H2F
Statements
A statement specifies operations to be performed on declared objects. Statements are
discussed in Section 12, Statements, and summarized in Table 12-1 on page 12-1.
HP pTAL Reference Manual—523746-006
2- 12
3
Data Representation
A program operates on data—variables and constants—which it stores in the storage
units that Table 3-1 on page 3-1 describes.
Table 3-1. Storage Units
Storage Unit
Number of Bits
Description
Byte
8
Smallest addressable unit of memory.
Word
16
2 bytes, with byte 0 (most significant) on the left and
byte 1 (least significant) on the right
Doubleword
32
4 bytes
Quadrupleword
64
8 bytes
n-bit field
1-16
Contiguous bit fields within 2 bytes
17-31
Contiguous bit fields within 4 bytes
Topics:
•
•
•
Data Types on page 3-1
Address Types on page 3-5
Constants on page 3-12
Data Types
When you declare a variable, you specify its data type, which determines:
•
•
•
•
Its storage unit
The values that you can assign to it
The operations that you can perform on it
Its address type
Table 3-2. Data Types (page 1 of 2)
Data Type
Storage Unit1
STRING
Byte
Values the Data Type Can Represent
•
•
ASCII character
Unsigned 8-bit integer in the range 0 through
255
1. Table 3-1 on page 3-1 describes storage units.
2. INT and INT(16) are the same type.
3. FIXED, FIXED(0), and INT(64) are the same type.
4. REAL and REAL(32) are the same type.
HP pTAL Reference Manual—523746-006
3 -1
Data Types
Data Representation
Table 3-2. Data Types (page 2 of 2)
Data Type
Storage Unit1
INT
INT(16)2
Word
Values the Data Type Can Represent
•
•
•
String of one or two ASCII characters
Unsigned 6-bit integer in the range 0 through
65,535
Signed 6-bit integer in the range -32,768 through
32,767
INT(32)
Doubleword
32-bit integer in the range -2,147,483,648 through
+2,147,483,647
REAL
REAL(32)4
Doubleword
32-bit floating-point number in the range
±8.6361685550944444E-78 through
±1.15792089237316192E, precise to approximately
6.5 significant decimal digits.
FIXED
FIXED(0)
INT(64)3
FIXED(-19 to -1)
FIXED(1 to 19)
Quadrupleword
64-bit fixed-point number. For FIXED, FIXED(0),
FIXED (*), and INT(64) the range is
-9,223,372,036,854,775,808 through
+9,223,372,036,854,775,807.
REAL(64)
Quadrupleword
64-bit floating-point number in the same range as
data type REAL but precise to approximately 16.5
significant decimal digits.
UNSIGNED
n-bit field
UNSIGNED(1-15) and UNSIGNED(17-31): Unsigned
integer in the range 0 through (2n - 1)
UNSIGNED(16):
•
•
Unsigned integer in the range 0 through 65,535
Signed integer in the range -32,768 through
32,767
UNSIGNED simple variable: The bit field can be 1 to
31 bits.
UNSIGNED array: The element bit field can be 1, 2,
4, or 8 bits.
1. Table 3-1 on page 3-1 describes storage units.
2. INT and INT(16) are the same type.
3. FIXED, FIXED(0), and INT(64) are the same type.
4. REAL and REAL(32) are the same type.
Topics:
•
•
•
Specifying Data Types on page 3-3
Data Type Aliases on page 3-4
Operations by Data Type on page 3-4
HP pTAL Reference Manual—523746-006
3 -2
Specifying Data Types
Data Representation
Specifying Data Types
The syntax for specifying the data type in a variable declaration is:
STRING
INT
REAL
(
width
)
UNSIGNED
(
width
)
(
fpoint
)
FIXED
*
VST214.vsd
width
is a constant expression that specifies the width, in bits, of the variable. The value
of width must be appropriate for the data type (see Example 3-1 on page 3-4):
Data Type
Value of width
INT (16)*
16
INT (32)
32
INT (64)*
64
REAL(32)*
32
REAL(64)
64
UNSIGNED(n )
In the range 1 through 31
* Data type alias (see Data Type Aliases on page 3-4)
fpoint
is the implied fixed-point (decimal-point) setting. fpoint is an integer in the range
-19 through 19. The default fpoint is 0 (no decimal places).
A positive fpoint specifies the number of places to the right of the decimal point:
FIXED(3) x := 0.642F;
! Stored as 642
A negative fpoint specifies a number of places to the left of the decimal point.
When the value is stored, it is truncated leftward from the decimal point by the
specified number of digits. When the value is accessed, zeros replace the
truncated digits:
FIXED(-3) y := 642945F;
! Stored as 642; accessed as 642000
HP pTAL Reference Manual—523746-006
3 -3
Data Type Aliases
Data Representation
*(asterisk)
prevents scaling of the initialization values (for an explanation of scaling, see
Scaling of FIXED Operands on page 5-7).
Example 3-1. Constant Expressions in Data Type Specifications
LITERAL a = 2,
b = 35;
INT(a + 30) aaa;
! OK: INT(32) is valid
INT(b - 5) bbb;
! ERROR: expression must evaluate to valid
! bit length (16, 32, or 64 for an INT)
REAL (b - 19) ccc;
! ERROR: expression must evaluate to valid
! bit length (32 or 64 for REAL)
REAL (b + 29) ddd;
! OK: REAL(64) is valid
UNSIGNED (a) eee;
! OK: UNSIGNED fields can be any number of
! bits from 1 to 31.
Data Type Aliases
The compiler accepts these data type aliases:
Data Type
Aliases
INT
INT(16)
REAL
REAL(32)
FIXED
FIXED(0)
INT(64)
The remainder of this manual avoids using data type aliases.
Operations by Data Type
The data type of a variable determines the operations you can perform on the variable.
Table 3-3. Operations by Data Type
Operation
STRING
INT or
UNSIGNED
(1-16)
INT(32) or
UNSIGNED
(17-31)
FIXED
REAL or
REAL(64)
Unsigned arithmetic
Yes
Yes
Yes
No
No
Signed arithmetic
Yes
Yes
Yes
Yes
Yes
Logical operations
Yes
Yes
Yes
No
No
Relational operations
Yes
Yes
Yes
Yes
Yes
Bit shifts
Yes
Yes
Yes
No
No
Byte scans
Yes
Yes
Yes
Yes
Yes
HP pTAL Reference Manual—523746-006
3 -4
Address Types
Data Representation
The data type of a variable also determines which built-in routines you can use with the
variable (see Section 15, Built-In Routines).
Address Types
Every identifier that you declare has both a data type and an address type. The data
type describes the data item itself. The address type describes the address of the data
item. If you declare a pointer to the data item, the value that you assign to the pointer
must be of that address type.
You cannot explicitly declare the address type of a pointer. When you declare a pointer,
the compiler determines its address type.
Table 3-4. Data Types and Their Address Types (page 1 of 2)
Pointer Declaration
Data Type
Address Type
Storage Unit1
STRING
INT
INT(32)
REAL
REAL(64)
FIXED
UNSIGNED(n)
STRUCT
SUBSTRUCT
addr-type 2
.s;
.i;
.j;
.r;
.s;
.f;
.u;
.t;
.v;
.a;
STRING
INT
INT(32)
REAL
REAL(64)
FIXED
UNSIGNED
none
none
address_type 3
BADDR
WADDR
WADDR
WADDR
WADDR
WADDR
WADDR
WADDR
BADDR
WADDR
Byte
Word
Word
Word
Word
Word
Word
Word
Byte
Word
STRING
INT
INT(32)
REAL
REAL(64)
FIXED
UNSIGNED(n)
STRUCT
SUBSTRUCT
addr-type 2
.EXT
.EXT
.EXT
.EXT
.EXT
.EXT
.EXT
.EXT
.EXT
.EXT
STRING
INT
INT(32)
REAL
REAL(64)
FIXED
UNSIGNED
none
none
address_type 3
EXTADDR
EXTADDR
EXTADDR
EXTADDR
EXTADDR
EXTADDR
EXTADDR
EXTADDR
EXTADDR
EXTADDR
Byte
Byte
Byte
Byte
Byte
Byte
Byte
Byte
Byte
Byte
STRING
INT
INT(32)
REAL
REAL(64)
FIXED
UNSIGNED(n)
addr-type 2
.SG
.SG
.SG
.SG
.SG
.SG
.SG
.SG
STRING
INT
INT(32)
REAL
REAL(64)
FIXED
UNSIGNED
address_type 3
SGBADDR
SGWADDR
SGWADDR
SGWADDR
SGWADDR
SGWADDR
SGWADDR
SGWADDR
Byte
Word
Word
Word
Word
Word
Word
Word
s;
i;
j;
r;
s;
f;
u;
t;
v;
a;
s;
i;
j;
r;
s;
f;
u;
a;
1. Table 3-1 on page 3-1 describes storage units.
2. addr-type is any of the ten address types.
3. address_type is the same address type as specified in the declaration.
HP pTAL Reference Manual—523746-006
3 -5
Address Types
Data Representation
Table 3-4. Data Types and Their Address Types (page 2 of 2)
Data Type
Address Type
Storage Unit1
STRING
INT
INT(32)
REAL
REAL(64)
FIXED
UNSIGNED
address_type 3
SGXBADDR
SGXWADDR
SGXWADDR
SGXWADDR
SGXWADDR
SGXWADDR
SGXWADDR
SGXWADDR
Byte
Word
Word
Word
Word
Word
Word
Word
PROC p;
PROCPTR p(); END
PROCPTR
procedure e;
ENTRY
PROC
PROCPTR
PROCADDR
PROCADR
Doubleword
Doubleword
PROC
PROCADDR
Doubleword
STRING v ='p':="ab";
INT
v ='p':="ab";
SUBPROC
Subprocedure ENTRY e;
LABEL 1;
STRING
INT
SUBPROC
CBADDR
CWADDR
CWADDR
CWADDR
CWADDR
Byte
Word
Word
Word
Word
Pointer Declaration
STRING
INT
INT(32)
REAL
REAL(64)
FIXED
UNSIGNED(n)
addr-type 2
.SGX
.SGX
.SGX
.SGX
.SGX
.SGX
.SGX
.SGX
s;
i;
j;
r;
s;
f;
u;
a;
LABEL
1. Table 3-1 on page 3-1 describes storage units.
2. addr-type is any of the ten address types.
3. address_type is the same address type as specified in the declaration.
You can compare addresses using the relational operators described in Table 2-5 on
page 2-5.
Topics:
•
•
•
•
•
•
•
•
•
•
Storing Addresses in Variables on page 3-7
Converting Between Address Types and Numeric Data Types on page 3-7
Converting Between Address Types on page 3-7
Using Indexes to Access Array Elements on page 3-9
Incrementing and Decrementing Addresses (Stepping Pointers) on page 3-10
Computing the Number of Bytes Between Addresses on page 3-11
Comparing Addresses to Addresses on page 3-11
Comparing Addresses to Constants on page 3-11
Comparing PROCADDRs and PROCPTRs on page 3-11
Testing a Pointer for a Nonzero Value on page 3-12
HP pTAL Reference Manual—523746-006
3 -6
Storing Addresses in Variables
Data Representation
Storing Addresses in Variables
You can store an address into a variable when either of the following is true:
•
•
The address is the same data type as the variable into which you are storing the
address.
The address is convertible to the data type of the variable into which you are
storing the address.
Converting Between Address Types and Numeric Data Types
You can move any 16-bit integer value—a constant or variable—into any system global
address type (SGBADDR, SGWADDR, SGXBADDR, or SGXWADDR). Conversely,
you can move the value of any system global data type into a 16-bit integer variable.
You can move an EXTADDR into an INT(32), or an INT(32) into an EXTADDR.
Exceptions: You cannot convert the following address types to numeric data types:
•
•
•
CBADDR
CWADDR
PROCADDR
Converting Between Address Types
You can convert an address from one address type to another using either:
•
•
Built-in address-conversion functions (see Table 15-4 on page 15-14)
Shift operations and low-level built-in routines
These conversions are supported for compatibility with TAL. HP recommends that
you use the equivalent pTAL routine when you write pTAL code.
Expression
Operand Type
Equivalent Routine Call
e '<<' 1
WADDR
$WADDR_TO_BADDR(e )
e '<<' 1
SGWADDR
$SGWADDR_TO_SGBADDR(e )
e '<<' 1
SGXWADDR
$SGWADDR_TO_SGBADDR(e )
e '>>' 1
BADDR
$BADDR_TO_WADDR(e )
e '>>' 1
SGBADDR
$SGBADDR_TO_SGWADDR(e )
e '>>' 1
SGXBADDR
$SGBADDR_TO_SGWADDR(e )
$UDBL(e )
BADDR
$BADDR_TO_EXTADDR(e )
$DBLL(0,e )
BADDR
$BADDR_TO_EXTADDR(e )
$UDBL(e ) '<<' 1
WADDR
$WADDR_TO_EXTADDR(e )
$DBLL(0,e ) '<<' 1
WADDR
$WADDR_TO_EXTADDR(e )
HP pTAL Reference Manual—523746-006
3 -7
Converting Between Address Types
Data Representation
The compiler generates code for implicit conversions for the following operations:
•
Block moves and compares
The compiler automatically converts an address type if required for the source or
destination pointer in a block move or block compare instruction.
•
Call-by-reference actual parameters
The compiler automatically converts the address type of an actual parameter to the
address type of a formal parameter if the conversion could not cause data loss. For
example:
°
°
°
BADDR can be converted to EXTADDR
WADDR can be converted to EXTADDR
EXTADDR cannot be converted to WADDR
HP pTAL Reference Manual—523746-006
3 -8
Using Indexes to Access Array Elements
Data Representation
Table 3-5. Valid Address Conversions
FROM
C
B
A
D
D
R
C
W
A
D
D
R
S
G
B
A
D
D
R
S
G
X
B
A
D
D
R
S
G
W
A
D
D
R
S
G
X
W
A
D
D
R
E
X
T
A
D
D
R
P
R
O
C
A
D
D
R
TO
B
A
D
D
R
W
A
D
D
R
BADDR
=
R
R
R
WADDR
R
=
R
R
CBADDR
INT
=
CWADDR
=
SGBADDR
=
=
R
R
I
SGXBADDR
=
=
R
R
I
SGWADDR
R
R
=
=
I
SGXWADDR
R
R
=
=
I
R
R
R
R
EXTADDR
R
R
E
E
=
PROCADDR
I
=
INT
I
I
I
I
INT(32)
Key to Symbols
INT(32)
I
=
E
E
=
=
Same type, conversion unnecessary
V
Valid
I
Implicit conversion for assignments, actual parameters (passed either by value
or by reference), and RETURN statements
R
Implicit conversion for parameters passed by reference, explicit conversion
required in other contexts
E
Explicit conversion required (see Address-Conversion Routines on page 15-14)
Blank
Unsupported and illegal
Using Indexes to Access Array Elements
Indexing produces the correct result for all data types including structures. Use
indexing wherever possible to adjust pointers.
Example 3-2. Using Indexing to Access an Array Element
int .p;
@p := @p[2]
@p := @p '+' 4;
! This statement is equivalent to
! this statement
HP pTAL Reference Manual—523746-006
3 -9
Data Representation
Incrementing and Decrementing Addresses
(Stepping Pointers)
Incrementing and Decrementing Addresses (Stepping Pointers)
You can increment or decrement the value of a pointer (step a pointer) by:
•
•
•
•
•
•
Using Arithmetic Operations to Adjust Addresses on page 3-10
Computing the Number of Bytes Between Addresses on page 3-11
Comparing Addresses to Addresses on page 3-11
Comparing Addresses to Constants on page 3-11
Comparing PROCADDRs and PROCPTRs on page 3-11
Testing a Pointer for a Nonzero Value on page 3-12
Using Arithmetic Operations to Adjust Addresses
You can add an integer value to any address type except PROCADDR. The address
can be on either side of the operator.
Example 3-3. Adding Integer Values to Addresses
INT .p;
@p := @p '+' 4;
@p := 4 '+' @p;
@p := @p[2];
! Increment WADDR pointer by four 16-bit words
! Increment WADDR pointer by four 16-bit words
You can subtract an integer value from any address type except PROCADDR. The
address must be on the left side of the subtraction operator and the integer must be on
the right.
Example 3-4. Subtracting Integer Values From Addresses
INT .p;
@p := @p '-' 4;
@p := 4 '-' @p;
! Decrement WADDR pointer by four 16-bit words
! ERROR: The address must be on the right,
! the integer on the left
You must use signed operators for operations on EXTADDRs and unsigned operators
for all other address types.
Example 3-5. Signed and Unsigned Operators in Address Arithmetic
INT .p;
INT .EXT e;
@p := @p '-' 4;
@p := 4 '+' @p;
@e := @e + 8D;
! Unsigned arithmetic on WADDRs
! Unsigned arithmetic on WADDRs
! Signed arithmetic on EXTADDRs
HP pTAL Reference Manual—523746-006
3- 10
Data Representation
Incrementing and Decrementing Addresses
(Stepping Pointers)
If you increment or decrement a pointer, the number that you add to, or subtract from,
a byte address (such as BADDR) is the number of bytes to move the pointer. Similarly,
the number that you add to a word address (such as WADDR) is the number of 16-bit
words to move the pointer, not the number of 32-bit words.
If you step a byte address (such as BADDR), the number you specify is added to, or
subtracted from, the address in the pointer.
If you step a word address (such as WADDR), the address is incremented
decremented by twice the number you specify, because addresses on TNS/R and
TNS/E architecture are represented as byte addresses.
Computing the Number of Bytes Between Addresses
You can subtract two addresses except PROCADDR addresses. The address types of
both operands must be the same except that SGBADDR and SGXBADDR are
interchangeable, and SGWADDR and SGXWADDR are interchangeable.
Comparing Addresses to Addresses
You can compare addresses only if both addresses are the same address type, except
that:
•
•
SGBADDR and SGXBADDR are interchangeable with one another
SGWADDR and SGXWADDR are interchangeable with one another
You must use signed relational operators (<, =, >,<=, <>, >=) to compare EXTADDR
addresses. For all other address types, you must use unsigned relational operators
(‘<‘, ‘=’, ‘>’, ‘<=’, ‘<>’, ‘>=’), or signed equal (‘=’) or signed not equal operators (‘<>’).
The result of comparing two addresses is an INT value that indicates whether the
relationship is true (nonzero) or false (zero).
You can test the condition code after an IF statement that compares two addresses
only if certain conditions are met. These conditions are described in Section 13,
Hardware Indicators.
Comparing Addresses to Constants
You can compare a BADDR, WADDR, SGBADDR, SGWADDR, SGXBADDR, or
SGXWADDR address to a 16-bit constant value. The requirements for Comparing
Addresses to Addresses on page 3-11 also apply to comparing addresses to
constants.
Comparing PROCADDRs and PROCPTRs
You can compare PROCADDR addresses and PROCPTR addresses for equality and
inequality. The result of comparing the addresses of two different procedures is always
“not equal,” but the result of comparing the two addresses of the same procedure is not
always “equal.”
HP pTAL Reference Manual—523746-006
3- 11
Constants
Data Representation
Testing a Pointer for a Nonzero Value
You can test a pointer for a nonzero value without specifying the constant zero. For
example, if i is declared:
int .i;
Then these two statements are equivalent:
if (@i) then ...
if (@i <> 0) ...
You can test an EXTADDR pointer for a nonzero value without specifying the constant
zero. For example, if j is declared:
int.ext j;
Then these two statements are equivalent:
if (@j) then ...
if (@j <> 0D) ...
Constants
•
•
•
•
•
•
•
•
Character String on page 3-12
STRING Numeric on page 3-14
INT Numeric on page 3-15
INT(32) Numeric on page 3-16
FIXED Numeric on page 3-17
REAL and REAL(64) Numeric on page 3-19
Constant Lists on page 3-21
Constant List Alignment Specification on page 3-22
Character String
A character string constant consists of one or more ASCII characters stored in a
contiguous group of bytes.
"
string
"
VST001.vsd
HP pTAL Reference Manual—523746-006
3- 12
Character String
Data Representation
string
is a sequence of one or more ASCII characters enclosed in quotation mark
delimiters. If a quotation mark is a character within the sequence of ASCII
characters, use two quotation marks (in addition to the quotation mark delimiters).
The compiler does not upshift lowercase characters.
Each character in a character string requires one byte of contiguous storage. The
maximum length of a character string you can specify differs for initializations and for
assignments.
Initializations
You can initialize simple variables or arrays of any data type with character strings.
When you initialize a simple variable, the character string can have the same number
of bytes as the simple variable or fewer. This example declares an INT variable and
initializes it with a character string:
INT chars := "AB";
When you initialize an array, the character string can have up to 127 characters and
must fit on one line. If a character string is too long for one line, use a constant list
(described Constant Lists on page 3-21) to break the character string into smaller
character strings.
Assignments
You can assign character strings to STRING, INT, and INT(32) variables, but not to
FIXED, REAL, or REAL(64) variables.
In assignment statements, a character string can contain at most four characters,
depending on the data type of the variable:
Number of Bytes in String
Data Types to Which String Can Be Assigned
1
STRING, INT
2
STRING, INT
3
INT(32)
4
INT(32)
Example 3-6. Assigning Character Strings to Variables
string s;
int i;
s := "a";
s := "ab";
s := "abc";
! OK
! OK: same as s := "b"
! ERROR: too big
i := "a";
i := "ab";
i := "abc";
! OK
! OK: same as s := "b"
! ERROR: too big
HP pTAL Reference Manual—523746-006
3- 13
STRING Numeric
Data Representation
STRING Numeric
Representation
Unsigned 8-bit integer
Range
0 through 255
integer
base
VST002.vsd
base
indicates a number base as follows:
Octal
%
Binary
%b
Hexadecimal
%h
If you omit the base, the default base is decimal.
integer
is one or more of the following digits:
Decimal
0 through 9
Octal
0 through 7
Binary
0 or 1
Hexadecimal
0 through 9, A through F (not case-sensitive)
Examples of STRING numeric constants:
Decimal
255
Octal
%12
Binary
%B101
Hexadecimal
%h2A
HP pTAL Reference Manual—523746-006
3- 14
INT Numeric
Data Representation
INT Numeric
Representation
Signed or unsigned 16-bit integer
Range (unsigned)
0 through 65,535
Range (signed)
-32,768 through 32,767
integer
base
+
-
VST027.vsd
base
indicates a number base as follows:
Octal
%
Binary
%b
Hexadecimal
%h
The default base is decimal.
integer
is one or more of the following digits:
Decimal
0 through 9
Octal
0 through 7
Binary
0 or 1
Hexadecimal
0 through 9, A through F (not case-sensitive)
Examples of INT numeric constants:
Decimal
3
-32045
Octal
%177
-%5
Binary
%B01010
%b1001111000010001
Hexadecimal
%H1A
%h2f
The system stores signed integers in two’s complement notation. It obtains the
negative of a number by inverting each bit position in the number, and then adding 1.
2 is stored as
0000000000000010
-2 is stored as
1111111111111110
HP pTAL Reference Manual—523746-006
3- 15
INT(32) Numeric
Data Representation
INT(32) Numeric
Representation
Signed or unsigned 32-bit integer
Range
-2,147,483,648 through 4,294,967,295
ns
D
integer
base
+
ns
%D
VST028.vsd
base
indicates a number base as follows:
Octal
%
Binary
%b
Hexadecimal
%h
The default base is decimal.
integer
is one or more of the following digits:
Decimal
0 through 9
Octal
0 through 7
Binary
0 or 1
Hexadecimal
0 through 9, A through F (not case-sensitive)
D
%D
are suffixes that specify INT(32) constants:
Decimal
D
Octal
D
Binary
D
Hexadecimal
%D
HP pTAL Reference Manual—523746-006
3- 16
FIXED Numeric
Data Representation
Examples of INT(32) numeric constants:
Decimal
0D
+14769D
-327895066d
Octal
%1707254361d
-%24700000221D
Binary
%B000100101100010001010001001d
Hexadecimal
%h096228d%d
-%H99FF29%D
For readability, always specify the % in the %D hexadecimal suffix to prevent the suffix
from being confused with the integer part of the constant. The following format, where
a space replaces the % in the %D suffix, is allowed but not recommended:
-%H99FF29 D
The system stores signed integers in two’s complement notation (see INT Numeric on
page 3-15).
FIXED Numeric
Representation
Signed 64-bit fixed-point number
Range
-9,223,372,036,854,775,808 through +9,223,372,036,854,775,807
integer
+
base
-
F
.
fraction
%F
VST005.vsd
base
indicates a number base as follows:
Octal
%
Binary
%B
Hexadecimal
%H
The default base is decimal.
HP pTAL Reference Manual—523746-006
3- 17
FIXED Numeric
Data Representation
integer
is one or more of the following digits:
Decimal
0 through 9
Octal
0 through 7
Binary
0 or 1
Hexadecimal
0 through 9, A through F
fraction
is one or more decimal digits. fraction is legal only for decimal base.
F
%F
are suffixes that specify FIXED constants:
Decimal
F
Octal
F
Binary
F
Hexadecimal
%F
Examples of FIXED numeric constants:
Decimal
1200.09F
0.1234567F
239840984939873494F
-10.09F
Octal
%765235512F
Binary
%B1010111010101101010110F
Hexadecimal
%H298756%F
For readability, always specify the % in the %F hexadecimal suffix to prevent the suffix
from being confused with the integer part of the constant. The following format, where
a space replaces the % in the %F suffix, is allowed but not recommended:
-%H99FF29 F
The system stores a FIXED number in binary notation. When the system stores a
FIXED number, it scales the constant as dictated by the declaration or expression.
Scaling means the system multiplies or divides the constant by powers of 10 to move
the decimal.
For information about scaling of FIXED values in expressions, see Section 5,
Expressions. For information about scaling of FIXED values in declarations, see
Section 7, Simple Variables.
HP pTAL Reference Manual—523746-006
3- 18
REAL and REAL(64) Numeric
Data Representation
REAL and REAL(64) Numeric
integer
.
fraction
+
-
exponent
E
L
+
VST006.vsd
Representation
Signed 32-bit REAL or 64-bit REAL(64) floating-point number
Range
±8.6361685550944446 * 10-78 through
±1.15792089237316189 * 10+77
Precision
REAL—to approximately 6.5 significant decimal digits
REAL(64)—to approximately 16.5 significant decimal digits
integer
is one or more decimal digits that compose the integer part.
fraction
is one or more decimal digits that compose the fractional part.
E
specifies the floating-point constant REAL.
L
specifies the floating-point constant REAL(64).
exponent
is one or two decimal digits that compose the exponential part.
HP pTAL Reference Manual—523746-006
3- 19
REAL and REAL(64) Numeric
Data Representation
Examples of REAL and REAL(64) numeric constants, showing the integer part, the
fractional part, the E or L suffix, and the exponent part:
Decimal Value
REAL
REAL(64)
0
0.0E0
0.0L0
2
2.0e0
0.2E1
20.0E-1
2.0L0
0.2L1
20.0L-1
-17.2
-17.2E0
-1720.0E-2
-17.2L0
-1720.0L-2
The system stores the number in binary scientific notation in the form:
x * 2y
x is a value of at least 1 but less than 2. Because the integer part of x is always 1, only
the fractional part of x is stored.
The exponent can be in the range -256 through 255 (%377). The system adds 256
(%400) to the exponent before storing it as y. Thus, the value stored as y is in the
range 0 through 511 (%777), and the exponent is y minus 256.
If the value of the number to be represented is zero, the sign is 0, the fraction is 0, and
the exponent is 0.
The system stores the parts of a floating-point constant as follows:
Data Type
Sign Bit
Fraction
Exponent
REAL
<0>
<1:22>
<23:31>
REAL(64)
<0>
<1:54>
<55:63>
Examples of storage formats:
1. For the following REAL constant, the sign bit is 0, the fraction bits are 0, and the
exponent bits contain %400 + 2, or %402:
4 = 1.0 * 22 stored as %000000 %000402
2. For the following REAL constant, the sign bit is 1, the fraction bits contain %.2
(decimal .25 is 2/8), and the exponent bits contain %400 + 3, or %403:
-10 = -(1.25 * 23) stored as %120000 %000403
3. For the following REAL(64) constant, the sign bit is 0, the fraction bits contain the
octal representation of .33333..., and the exponent bits contain %400 - 2, or %376:
1/3 = .33333…* 2-2 stored as %025252 %125252 %125252 %125376
HP pTAL Reference Manual—523746-006
3- 20
Constant Lists
Data Representation
Constant Lists
A constant list is a list of one or more constants. You can use constant lists in:
•
•
•
initializations of array declarations that are not contained in structures
group comparison expressions
move statements
You cannot use constant lists in assignment statements
repetition-constant-list
]
repetition-constant-list
[
FIELDALIGN-clause
constant-list-seq
VST621.vsd
repetition-constant-list
[
repetition-factor
constant-list-seq
]
*
VST008.vsd
repetition-factor
is an INT constant that specifies the number of times constant-list-seq
occurs.
constant-list-seq
is a list of one or more constants, each stored on an element boundary:
constant
repetition-constant-list
,
VST029.vsd
constant
is a character string, a number, or a LITERAL specified as a single
operand. The range and syntax for specifying constants depends on the
data type, as described for each data type on preceding pages.
HP pTAL Reference Manual—523746-006
3- 21
Constant List Alignment Specification
Data Representation
FIELDALIGN-clause
FIELDALIGN
(
SHARED2
)
SHARED8
VST065.vsd
specifies how you want the compiler to align the base of the structure and fields in
the structure. The offsets of fields in a structure are aligned relative to the base of
the structure. For more information about constant list alignment, see Constant List
Alignment Specification on page 3-22.
SHARED2
specifies that the base of the structure and each field in the structure must
begin at an even byte address except STRING fields, which can begin at any
byte address, and UNSIGNED fields.
SHARED8
specifies that the offset of each field in the structure from the base of the
structure must be begin at an address that is an integral multiple of the width of
the field.
Constant List Alignment Specification
A constant list alignment specification controls the alignment of elements of constant
lists whose element type is not STRING. Such a constant list can have an alignment of
SHARED2 or SHARED8. Nested constant lists cannot have an alignment specification;
they inherit the alignment of the containing constant list. SHARED2 causes alignment
identical to TAL. SHARED8 additionally requires that 4-byte and 8-byte scalars are
aligned to their size. You must insert filler constants of ensure proper alignment of
4-byte and 8-byte aligned items. A SHARED8 constant list containing an item that is
misaligned is an error.
An optional alignment specification gives the alignment of a constant list. It occurs
immediately before the opening bracket of the constant list. There is no default
constant list alignment. The alignment specification is required if SHARED2 and
SHARED8 would give different results.
A1 ':=' [1,2,3,4];
! No alignment specification
! required
A1 ':=' FIELDALIGN(SHARED2) [1,2D,4];
! Alignment specification required
! to specify 2-byte alignment for
! 2D
HP pTAL Reference Manual—523746-006
3- 22
Constant List Alignment Specification
Data Representation
Examples of constant lists:
1. In each of the following pairs, the list on the left is equivalent to the list on the right:
[ "A", "BCD" , "...", "Z" ]
[ "ABCD...Z" ]
10 * [0];
[0,0,0,0,0,0,0,0,0,0]
[3 * [2 * [1], 2 * [0]]]
[1,1,0,0,1,1,0,0,1,1,0,0]
10 * [" "]
["
"]
2. The following is an example of the FIELDALIGN clause:
STRING i [0:3] := FIELDALIGN(SHARED2) [0,1,2,3];
3. The following example shows how you can break a constant string that is too long
for one line into smaller constant strings specified as a constant list. The system
stores one character to a byte:
STRING
a[0:99] := ["These three constant strings will ",
"appear as if they were one constant ",
"string continued on multiple lines."];
4. The following example initializes a STRING array with a repetition constant list:
STRING b[0:79] := 80 * [" "];
5. The following example initializes an INT(32) array with a mixed constant list
containing values of the same data type. The diagram shows how the compiler
allocates storage for the variable and the constant list that initializes the variable:
INT(32) c[0:4];
["abcd", 1D, 3D, "XYZ",
%20D];
"a"
"b"
"c"
"d"
c[0]
!Mixed constant list
c[1]
1D
c[2]
3D
"X"
"Y"
"Z"
0
c[3]
c[4]
%20D
VST331.vsd
HP pTAL Reference Manual—523746-006
3- 23
Data Representation
Constant List Alignment Specification
HP pTAL Reference Manual—523746-006
3- 24
4
Data Alignment
In native mode, a data item is aligned if its address is a multiple of its size. For
example, a 4-byte data item is aligned if its address is a multiple of four. An address
that is not aligned is called misaligned. In native mode, a compiler requires data to be
aligned unless otherwise indicated. Unexpected misalignment causes the program to
run slowly, but usually with the expected results.
The only time a nonprivileged program running in TNS/R native mode could have data
alignment problems is when calling the atomic routines whose names begin with
“$ATOMIC_”. Those routines operate correctly only when given aligned operand
addresses. This section explains some ways to diagnose bad calls at run time.
TNS-compiled programs must follow more stringent alignment rules, which apply to all
data. Those rules are explained in:
Product
T Number
Document
Accelerator
T9276
Accelerator Manual Data Alignment Addendum
TNS C
T9255
C/C++ Programmer’s Guide
TNS C++
T9541
C/C++ Programmer’s Guide
TNS c89
T8629
C/C++ Programmer’s Guide
TNS COBOL
T9257
COBOL Manual for TNS and TNS/R Programs
TAL
T9250
TAL Programmer’s Guide Data Alignment Addendum
Topics:
•
•
Misalignment Tracing Facility on page 4-1
Misalignment Handling on page 4-3
Misalignment Tracing Facility
The misalignment tracing facility is enabled or disabled on a system-wide basis (that is,
for all processors in the node). By default, it is enabled (set to ON). It can be disabled
(set to OFF) only by the persons who configure the system, by means of the
Subsystem Control Facility (SCF) attribute MISALIGNLOG. Instructions are in the SCF
Reference Manual for the Kernel Subsystem.
Note. HP recommends that the MISALIGNLOG attribute be left ON (its default setting) so that
a process that is subject to rounding of misaligned addresses generates log entries, facilitating
diagnosis and repair of the code. Only if the volume of misalignment events degrades
performance should this attribute be turned OFF.
HP pTAL Reference Manual—523746-006
4 -1
Misalignment Tracing Facility
Data Alignment
When a misaligned address causes an exception that RVUs prior to G06.17 would
have rounded down, the tracing facility traces the exception.
Note. The tracing facility does not count and trace every misaligned address, only those that
cause round-down exceptions. Other accesses that use misaligned addresses without
rounding them down do not cause exceptions and are not counted or traced. Also, only a
periodic sample of the counted exceptions are traced by means of their own EMS event
messages.
While a process runs, the tracing facility:
•
•
Counts the number of misaligned-address exceptions that the process causes (the
exception count)
Records the program address and code-file name of the instruction that causes the
first misaligned-address exception
Because a process can run for a long time, the tracing facility samples the process
(that is, checks its exception data) periodically (approximately once an hour). If the
process recorded an exception since the previous sample, the tracing facility records
an entry in the EMS log. If the process ends and an exception has occurred since the
last sample, the operating system produces a final Event Management Service (EMS)
event.
The EMS event includes:
•
•
The process’s exception count
Details about one misaligned-address exception, including the program address,
data address, and relevant code-file names
Sampling is short and infrequent enough to avoid flooding the EMS log, even for a
continuous process with many misaligned-address exceptions. One sample logs a
maximum of 100 events, and at most one event is logged for any process.
If misaligned-address exceptions occur in different periods of a process, the operating
system produces multiple EMS events for the same process, and these EMS events
might have different program addresses.
For more information about EMS events or the EMS log, see the EMS Manual.
HP pTAL Reference Manual—523746-006
4 -2
Misalignment Handling
Data Alignment
Misalignment Handling
Misalignment handling is determined by the following SCF attributes, which are set
system-wide (that is, for all processors in the node) by the persons who configure the
system:
•
•
•
MISALIGNLOG
TNSMISALIGN (applies only to programs running in TNS mode or TNS
accelerated mode, and therefore, does not apply to pTAL programs)
NATIVEATOMICMISALIGN
MISALIGNLOG enables or disables the tracing facility (see Misalignment Tracing
Facility on page 4-1).
NATIVEATOMICMISALIGN applies to atomic routines in programs running in TNS/R
native mode; that is, the pTAL and TAL routines whose names begin with “$ATOMIC_”
For normal, nonatomic access in TNS/R native mode, the system uses the operand’s
full address (never rounded down) to complete the operation.
For normal, nonatomic access in TNS/R native mode, the system uses the operand’s
full address (never rounded down) to complete the operation.
Table 4-1 on page 4-3 lists and describes the possible settings for
NATIVEATOMICMISALIGN. Each setting represents a different misalignment handling
method. For more information about NATIVEATOMICMISALIGN, see the SCF
Reference Manual for the Kernel Subsystem.
Table 4-1. TNS/R Native Atomic Misalignment Handling Methods
Method
Description
ROUND
(default)
After rounding down a misaligned address, the system proceeds to access
the address atomically, as in G06.16 and earlier RVUs.
FAIL
Instead of rounding down a misaligned address, the system considers the
call to have failed.
This failure generates a SIGILL signal (signal #4). By default, this signal
causes process termination, but the program can specify other behavior (for
example, entering the debugger or calling a specified signal-handler
procedure). The signal cannot be ignored. For information about signal
handling, see the explanation of the sigaction() function in the Open
System Services System Calls Reference Manual.
The method that you choose does not apply to every misaligned address, only to those
that would have been rounded down in earlier RVUs.
Note. ROUND misalignment handling is intended as a temporary solution, not as a substitute
for changing your atomic calls to ensure that they have only aligned addresses. ROUND
misalignment handling cannot be migrated to past and future NonStop OS platforms .
HP pTAL Reference Manual—523746-006
4 -3
Misalignment Handling
Data Alignment
HP pTAL Reference Manual—523746-006
4 -4
5
Expressions
An expression is a sequence of operands and operators that, when evaluated,
produces a single value. Operands in an expression include variables, constants, and
routine identifiers. Operators in an expression perform arithmetic or conditional
operations on the operands. pTAL supports the following types of expressions:
Expression
Description
Examples
Arithmetic
expression
An expression, consisting of operands and
arithmetic operators, that produces a single
numeric value.
398 + num / 84
Address
expression
An expression containing relational operators,
that allows you to compare addresses, or
compare an address to a constant.
IF @p = 0 THEN ...
Constant
expression
An arithmetic expression that contains only
constants, LITERALs, and DEFINEs as operands.
398 + 46 / 84
Conditional
expression
An expression establishing the relationship
between values and resulting in a true or false
value. A conditional expression consists of
relational conditions and conditional operators.
a < c
10 LOR 12
a OR b
Expressions can appear in:
•
•
•
•
•
•
LITERAL declarations
Variable initialization and assignments
Array and structure bounds
Indexes to variables
Conditional statements
Parameters to procedures or subprocedures
An expression can be:
•
•
•
•
A single operand, such as the number 5
A unary plus or minus (+ or -) operator applied to a single operand, such as -5
A binary operator applied to two operands, such as 5 * 8
A complex sequence such as:
(((alpha + beta) / chi) * (delta - 145.9)) / zeta
HP pTAL Reference Manual—523746-006
5 -1
Data Types of Expressions
Expressions
Topics:
•
•
•
•
•
•
•
•
•
•
Data Types of Expressions on page 5-2
Operator Precedence on page 5-3
Arithmetic Expressions on page 5-5
Signed Arithmetic Operators on page 5-6
Unsigned Arithmetic Operators on page 5-8
Comparing Addresses on page 5-11
Constant Expressions on page 5-14
Conditional Expressions on page 5-15
Special Expressions on page 5-20
Bit Operations on page 5-31
Data Types of Expressions
The result of an expression can be any data type or address type except STRING or
UNSIGNED. The compiler determines the data type of the result from the data type of
the operands in the expression. All operands in an expression must have the same
data type, with the following exceptions:
•
•
An INT expression can include STRING, INT, and UNSIGNED(1-16) operands. The
system treats STRING and UNSIGNED(1-16) operands as if they were 16-bit
values. That is, the system:
°
Puts a STRING operand in the right byte of a 16-bit word and sets the left byte
to 0, with no sign extension.
°
Puts an UNSIGNED(1-16) operand in the right bits of a 16-bit word and sets
the unused left bits to 0, with no sign extension. For example, for an
UNSIGNED(2) operand, the system fills the 14 leftmost bits of the word with
zeros.
An INT(32) expression can include INT(32) and UNSIGNED(17-31) operands. The
system treats UNSIGNED(17-31) operands as if they were 32-bit values. The
system places an UNSIGNED(17-31) operand in the right bits of a doubleword and
sets the unused left bits to 0, with no sign extension. For example, for an
UNSIGNED(29) operand, the system fills the three leftmost bits of the doubleword
with zeros.
In all other cases, if the data types do not match, use the type transfer functions
described in Section 15, Built-In Routines.
HP pTAL Reference Manual—523746-006
5 -2
Operator Precedence
Expressions
Operator Precedence
Operators in expressions can be arithmetic (signed, unsigned, or logical) or conditional
(relational, signed or unsigned). Within an expression, the compiler evaluates the
operators in the order of precedence. Within each level of precedence, the compiler
evaluates the operators from left to right.
Table 5-1. Precedence of Operators (page 1 of 2)
Operator
Operation
Precedence
<<
Signed left bit shift
0 (highest)
>>
Signed right bit shift
'<<'
Unsigned left bit shift
'>>'
Unsigned right bit shift
[n ]
Indexing
@
Address of identifier
+
Unary plus
-
Unary minus
<...>
Bit extraction
2
*
Signed multiplication
3
/
Signed division
'*'
Unsigned multiplication
'/'
Unsigned division
'\'
Unsigned remainder
+
Signed addition
-
Signed subtraction
'+'
Unsigned addition
'-'
Unsigned subtraction
LOR
Bitwise logical OR
LAND
Bitwise logical AND
XOR
Bitwise exclusive OR
1
4
HP pTAL Reference Manual—523746-006
5 -3
Operator Precedence
Expressions
Table 5-1. Precedence of Operators (page 2 of 2)
Operator
Operation
Precedence
<
Signed less than
5
=
Signed equal to
>
Signed greater than
<=
Signed less than or equal to
>=
Signed greater than or equal to
<>
Signed not equal to
'<'
Unsigned less than
'='
Unsigned equal to
'>'
Unsigned greater than
'<='
Unsigned less than or equal to
'>='
Unsigned greater than or equal to
'<>'
Unsigned not equal to
NOT
Negation
6
AND
Conjunction
7
OR
Disjunction
8
:=
Assignment
9 (lowest)
<...> :=
Bit deposit
You can use parentheses to override the precedence of operators. You can nest the
parenthesized operations. The compiler evaluates nested parenthesized operations
outward starting with the innermost level.
Figure 5-1. Parentheses’ Effect on Operator Precedence
c * (a + b)
c * ( (a + b) / d)
Result
(a OR b) AND c
Result
Result
VST003.vsd
HP pTAL Reference Manual—523746-006
5 -4
Arithmetic Expressions
Expressions
Arithmetic Expressions
An arithmetic expression is a sequence of operands and arithmetic operators that
computes a single numeric value of a specific data type.
operand
arithmetic-operator
+
operand
VST010.vsd
+
are unary plus and minus operators. The default is unary plus.
operand
is one of the elements in Table 5-2 on page 5-5.
arithmetic-operator
is one of the following:
Signed arithmetic operator
+, -, *, /
Unsigned arithmetic operator
'+', '-', '*', '/', '\'
Logical operator
LOR, LAND, XOR
Table 5-2. Operands in Arithmetic Expressions
Element
Description
Example
Variable
The identifier of a simple variable, array element,
pointer, structure data item, or equivalenced variable,
with or without @ or an index
var[10]
Constant
A character string or numeric constant
103375
LITERAL
The identifier of a named constant
file_size
Function
invocation
The invocation of a procedure that returns a value
$LEN (x)
expression
Any expression
x := y
(expression)
Any expression, enclosed in parentheses
(x := y)
Code space item
The identifier of a procedure, subprocedure, or label
prefixed with @ or a read-only array optionally prefixed
with @, with or without an index
@label_a
HP pTAL Reference Manual—523746-006
5 -5
Signed Arithmetic Operators
Expressions
Table 5-3. Arithmetic Expressions
Syntax
Example
operand
var-1
- operand
-var-1
+ operand arithmetic-operator operand
+var-1 * 2
operand arithmetic-operator operand
var-1 / var-2
operand arithmetic-operator operand
var-1 / (-var-2)
expression operand expression
2 *3 + var / 2
expression operand expression
2 * var * 4
A condition code cannot appear inside an arithmetic expression; for example, the
following is not valid in pTAL:
a := <;
!Illegal
Signed Arithmetic Operators
Table 5-4. Signed Arithmetic Operators
Operator
Operation
Operand Type*
Example
+
Unary plus
Any data type
+5
-
Unary minus
Any data type
-5
+
Binary signed addition
Any data type
alpha + beta
-
Binary signed subtraction
Any data type
alpha - beta
*
Binary signed multiplication
Any data type
alpha * beta
/
Binary signed division
Any data type
alpha / beta
* The data type of the operands must match, except as noted in Data Types of Expressions on page 5-2.
In Table 5-5 on page 5-6, the order of the data types is interchangeable.
Table 5-5. Signed Arithmetic Operand and Result Types (page 1 of 2)
Operand Type
Operand Type
Result Type
Example
STRING
STRING
INT
byte1 + byte2
INT
INT
INT
word1 - word2
INT(32)
INT(32)
INT(32)
dbl1 * dbl2
REAL
REAL
REAL
real1 + real2
REAL(64)
REAL(64)
REAL(64)
quad1 + quad2
FIXED
FIXED
FIXED
fixed1 * fixed2
INT
STRING
INT
word1 / byte1
HP pTAL Reference Manual—523746-006
5 -6
Scaling of FIXED Operands
Expressions
Table 5-5. Signed Arithmetic Operand and Result Types (page 2 of 2)
Operand Type
Operand Type
Result Type
Example
INT
UNSIGNED(1-16)
INT
word + unsign12
INT(32)
UNSIGNED(17-31)
INT(32)
double + unsign20
UNSIGNED(1-16)
UNSIGNED(1-16)
INT
unsign6 + unsign9
UNSIGNED(17-31)
UNSIGNED(17-31)
INT(32)
unsign26 + unsign31
The compiler treats a STRING or UNSIGNED(1-16) operand as an INT operand. If
bit <0> contains 0, the operand is positive; if bit <0> contains 1, the operand is
negative. For more information, see Data Types of Expressions on page 5-2.
The compiler treats an UNSIGNED(17-31) operand as a positive INT(32) operand.
Signed arithmetic operators affect the hardware indicators as described in Section 13,
Hardware Indicators.
Topics:
•
•
Scaling of FIXED Operands on page 5-7
Using FIXED(*) Variables on page 5-8
Scaling of FIXED Operands
When you declare a FIXED variable, you can specify an implied fixed-point (fpoint )
setting (see Specifying Data Types on page 3-3).
When FIXED operands in an arithmetic expression have different fixed-points, the
system “scales” them, depending on the operation:
Operation
Scaling
Addition or
subtraction
The system adjusts the smaller fixed-point to match the larger fixed-point.
The result inherits the larger fixed-point. For example, the system adjusts
the smaller fixed-point in 3.005F + 6.01F to 6.010F, and the result is
9.015F.
Multiplication
The fixed-point of the result is the sum of the fixed-points of the two
operands. For example, 3.091F * 2.56F results in the FIXED(5) value
7.91296F.
Division
The fixed-point of the result is the fixed-point of the dividend minus the
fixed-point of the divisor (some precision is lost). For example,
4.05F / 2.10F results in the FIXED value 1.
To retain precision when you divide operands that have nonzero fixed-points, use the
routine $SCALE on page 15-82.
HP pTAL Reference Manual—523746-006
5 -7
Using FIXED(*) Variables
Expressions
Using FIXED(*) Variables
pTAL does not scale data items that it stores into FIXED(*) items.
The following procedure has one local variable whose data type is FIXED(*):
PROC p;
BEGIN
FIXED(*) f;
f := 1234F;
END;
The data type of a FIXED(*) variable is the same as a FIXED variable when it is used
in an expression:
FIXED(*) f1 := 123F;
FIXED(2) f2;
f2 := f1;
! f2 is assigned 123.00
pTAL does not scale data when it is stored into a FIXED(*) variable:
FIXED(2) f1 := 1.23F;
FIXED(*) f2;
FIXED
f3;
f2 := f1;
! f2 is assigned 123
f3 := f1;
! f3 is assigned 1
The following example further illustrates this:
FIXED(*) f1;
FIXED(3) f2 := 1.234F;
f1 := f2;
f2 := f1;
f1 := f2;
f2 := f1;
f1 := f2;
f2 := f1;
!
!
!
!
!
!
f1
f2
f1
f2
f1
f2
=
=
=
=
=
=
1234
1234.000
1234000
1234000.000
1234000000
1234000000.000
Unsigned Arithmetic Operators
Typically, you use binary unsigned arithmetic on operands with values in the range 0
through 65,535. For example, you can use unsigned arithmetic with pointers that
contain standard addresses.
Table 5-6. Unsigned Arithmetic Operators (page 1 of 2)
Operator
Operation
Operand Type
Example
'+'
Unsigned addition
STRING, INT, or
UNSIGNED(1-16)
alpha '+' beta
'-'
Unsigned subtraction
STRING, INT, or
UNSIGNED(1-16)
alpha '-' beta
'*'
Unsigned multiplication
STRING, INT, or
UNSIGNED(1-16)
alpha '*' beta
HP pTAL Reference Manual—523746-006
5 -8
Unsigned Arithmetic Operators
Expressions
Table 5-6. Unsigned Arithmetic Operators (page 2 of 2)
Operator
Operation
Operand Type
Example
'/'
Unsigned division
INT(32) or UNSIGNED
(17-31) dividend and
STRING, INT, or
UNSIGNED(1-16) divisor
alpha '/' beta
'\'
Unsigned remainder*
INT(32) or UNSIGNED
(17-31) dividend and
STRING, INT, or
UNSIGNED(1-16) divisor
alpha '\' beta
* If the quotient exceeds 16 bits, an overflow condition occurs and the results will have unpredictable values. For
example, the operation 200000D '\' 2 causes an overflow because the quotient exceeds 16 bits.
In Table 5-7 on page 5-9, the order of the operand types in each combination is
interchangeable except in the last case.
Table 5-7. Unsigned Arithmetic Operand and Result Types
Operator
Operand Type
Operand Type
Result
Type
'+' '-'
STRING
STRING
INT
byte1 '-' byte2
INT
INT
INT
word1 '+' word2
INT
STRING
INT
byte1 '-' word1
INT
UNSIGNED (1-16)
INT
word1 '+' uns8
STRING
UNSIGNED (1-16)
INT
byte1 '-' uns5
UNSIGNED(1-16)
UNSIGNED(1-16)
INT
uns1 '+' uns7
STRING
STRING
INT(32)
byte1 '*' byte2
INT
INT
INT(32)
wrd1 '*' wrd2
STRING
INT
INT(32)
byte1 '*' wrd1
INT
UNSIGNED (1-16)
INT(32)
wrd1 '*' uns9
STRING
UNSIGNED (1-16)
INT(32)
uns1 '*' uns7
UNSIGNED(1-16)
UNSIGNED(1-16)
INT(32)
uns1 '*' uns7
UNSIGNED(17-31)
or INT(32) dividend
STRING, INT, or
UNSIGNED(1-16)
divisor
INT
dbwd '\' word1
'*'
'/' '\'
Example
Topics:
•
•
Bitwise Logical Operators on page 5-10
Using Bitwise Logical Operators and INT(32) Operands on page 5-10
HP pTAL Reference Manual—523746-006
5 -9
Bitwise Logical Operators
Expressions
Bitwise Logical Operators
Use bitwise logical operators (LOR, LAND, and XOR) to perform bit-by-bit operations
on STRING, INT, UNSIGNED(1-16) operands. Use INT(32) operands to return INT(32)
results. 16-bit operands produce a 16-bit result. 32-bit operands produce a 32-bit
result. Bitwise logical operators are not defined for 64-bit operands.
Table 5-8. Bitwise Logical Operators
Operator
Operation
Operand Type
Bit Operations
Example
LOR
Bitwise
logical OR
STRING, INT, or
UNSIGNED(1-16)
1 LOR 1 = 1
1 LOR 0 = 1
0 LOR 0 = 0
10 LOR 12 = 14
10
1 0 1 0
12
1 1 0 0
__
_ _ _ _
14
1 1 1 0
LAND
Bitwise
logical
ADD
STRING, INT, or
UNSIGNED(1-16)
1 LAND 1 = 1
1 LAND 0 = 0
0 LAND 0 = 0
10 LAND 12 = 8
10
1 0 1 0
12
1 1 0 0
__
_ _ _ _
8
1 0 0 0
XOR
Bitwise
exclusive
OR
STRING, INT, or
UNSIGNED(1-16)
1 XOR 1 = 0
1 XOR 0 = 1
0 XOR 0 = 0
10 XOR
10
12
__
6
12 = 6
1 0 1 0
1 1 0 0
_ _ _ _
0 1 1 0
The Bit Operations column in Table 5-8 on page 5-10 shows the bit-by-bit operations
that occur on 16-bit values. Each 1-bit operand pair results in a 1-bit result. The bit
operands are commutative.
Using Bitwise Logical Operators and INT(32) Operands
You can use INT(32) operands with:
•
Logical operators (LOR, LAND, and XOR)
The following example swaps the values stored in i and j:
INT(32) i;
INT(32) j;
i := i XOR j;
j := i XOR j;
i := i XOR j;
•
Unsigned relational operators ('<', '<=', '=', '<>', '>=', and '>')
The INT(32) operands are treated as nonnegative values in the range 0 to 232-1.
HP pTAL Reference Manual—523746-006
5- 10
Comparing Addresses
Expressions
•
Unsigned addition and subtraction operators ('+' and '-')
The INT(32) operands are treated as nonnegative values in the range 0 to 232-1.
Unsigned and signed addition and subtraction are the same except that
$OVERFLOW on page 15-76 returns false after an unsigned operation.
•
Unsigned multiplication operator ('*')
The INT(32) operands are treated as nonnegative values in the range 0 to 232-1.
The unsigned product of two INT(32) values is an FIXED value. $OVERFLOW on
page 15-76 returns false after an unsigned multiplication operator.
•
Unsigned division and remainder operators ('/' and '\')
You can use an FIXED dividend and INT(32) divisor with the unsigned-division and
remainder operators. The FIXED dividend is treated as a nonnegative value in the
range 0 to 264-1. The INT(32) divisor is treated as a nonnegative value in the
range 0 to 232-1.
The quotient or remainder of an FIXED dividend and an INT(32) divisor is an
INT(32) quotient in the range 0 to 232-1.
$OVERFLOW on page 15-76 returns false after an unsigned division or remainder
operator unless either of the following is true:
•
•
The divisor is 0
The quotient is greater than 216-1 for an INT quotient, 232-1 for an INT(32)
Comparing Addresses
pTAL rules for comparing address types are more restrictive than the rules for
comparing nonaddress types.
Table 5-9. Valid Address-Type Comparisons
Operators
Abbreviated forms
Extended Addresses
Non-Extended Addresses
Unsigned relational operators:
none
Unsigned relational operators:
'<', '=', '>', '<=', '<>', '>='
Signed relational operators:
<, =, >, <=, <>, >=
Signed relational operators:
=, <>
Testing address type as true or
false:
IF @p THEN
IF NOT @p THEN...
Testing address type as true or
false:
IF @p THEN
IF NOT @p THEN...
Topics:
•
•
Extended Addresses on page 5-12
Nonextended Addresses on page 5-12
HP pTAL Reference Manual—523746-006
5- 11
Extended Addresses
Expressions
Extended Addresses
The following rules apply when you compare extended addresses (EXTADDRs):
•
•
Use signed relational operators to compare extended addresses. Unsigned
operators are not valid.
If you compare an extended address to a constant, the constant must be a 32-bit
integer.
Example 5-1. Extended Addresses
EXTADDR e;
INT .EXT i;
IF e < @i THEN ...
IF @i >= 0D THEN ...
IF e = 0D THEN ...
IF e <> 0D THEN ...
IF e THEN ...
IF NOT e THEN ...
IF e > i THEN ...
IF e '<' @i THEN ...
!
!
!
!
!
!
!
!
!
OK: e and @i are both EXTADDR
OK: @i is EXTADDR, 0D is 32 bits
OK
OK
OK
OK
ERROR: e is EXTADDR, i is INT
ERROR: Unsigned operators are not valid
with EXTADDRs
Nonextended Addresses
The following rules apply when you compare nonextended addresses:
•
•
Use unsigned relational operators ( '<', '=', '>', '<=', '<>', '>='), a signed equality
operator (=), or a signed inequality operator (<>) to compare nonextended
addresses. The signed and unsigned equality operators produce the same results.
Similarly, the signed and unsigned inequality operators produce the same results.
Do not compare nonextended addresses using signed operators that test for
greater than or less than (<, <=, >, >=).
Valid comparisons:
INT .p, .q;
IF @p = 0 THEN ...
IF @p <> 0 THEN ...
IF @p = @q THEN ...
Both operands must have the same address type:
STRING .s;
BADDR .b;
IF @s = b THEN ...
IF @s = @b THEN ...
! OK: @s is BADDR, b is BADDR
! ERROR: @s is BADDR, @b is WADDR
HP pTAL Reference Manual—523746-006
5- 12
Nonextended Addresses
Expressions
•
If one operand of a relational operator is a nonextended address and the other is a
constant, the constant must be 16 bits in length:
INT .p;
IF @p = 100 THEN ...
IF @p = 100D THEN ...
! OK
! ERR
Table 5-10. Valid Address Expressions (page 1 of 2)
Template
Result Type
Examples
atype [k];
atype *
INT .EXT p;
@p := @p[2];
atype '+' INT16
atype *
INT .p;
@p := @p '+' 2;
@p := @p '-' 4;
int16 '+' atype
atype *
INT .p;
@p := 2 '+' @p;
EXTADDR '±' INT32
EXTADDR
INT .EXT p;
@p := @p '+' 4D;
INT32 '±' EXTADDR
EXTADDR
INT .EXT p;
@p := 4D '+' @p;
atype '-' atype
INT
INT .b, .bp, i;
i := @bp '-' @b;
The result of subtracting two byte-oriented
(BADDR, CBADDR, SGBADDR,
SGXBADDR) addresses is the number of
bytes between them.
The result of subtracting two wordoriented (WADDR, CWADDR,
SGWADDR, SGXWADDR) addresses is
the number of 16-bit words between them.
EXTADDR - EXTADDR
INT32
INT .EXT .b, bp, i32;
i32 := @bp - @b;
atype relational atype
INT
BADDR b1, b2;
INT i;
IF b1 '<' b2 THEN ...;
i := b1 '<' b2;
relational must be an unsigned
relational operation ('<', '=', '>', '<=', '<>',
'>=') or signed equal or not equal (=, <>).
* atype represents any address type except PROCADDR or EXTADDR.
HP pTAL Reference Manual—523746-006
5- 13
Constant Expressions
Expressions
Table 5-10. Valid Address Expressions (page 2 of 2)
Template
Result Type
Examples
EXTADDR relational
EXTADDR
INT
EXTADDR b1, b2;
INT i;
IF b1 < b2 THEN ...;
i := b1 < b2;
relational must be a signed relational
operation (<, =, >, <=, <>, >=).
INT
atype relational
CONSTANT
BADDR b1;
INT i;
IF b1 '>' 100 THEN ...;
i := b1 '<>' nil;
relational must be an unsigned
relational operation ('<', '=', '>', '<=', '<>',
'>=') or signed equal or not equal (=, <>).
EXTADDR relational
CONSTANT
INT
EXTADDR b1;
INT i;
IF b1 < 0D THEN ...;
i := b1 < 65535;
relational must be a signed relational
operation (<, =, >, <=, <>, >=).
* atype represents any address type except PROCADDR or EXTADDR.
Constant Expressions
A constant expression is an arithmetic expression that contains only constants,
LITERALs, or DEFINEs as operands.
You can use a constant expression anywhere a single constant is allowed.
Example 5-2. Constant Expressions
255
8 * 5 + 45 / 2
For more information, see Section 6, LITERALs and DEFINEs.
HP pTAL Reference Manual—523746-006
5- 14
Conditional Expressions
Expressions
Conditional Expressions
A conditional expression is a sequence of conditions and relational operators that
establishes the relationship between values. You can use conditional expressions to
direct program flow.
condition
NOT
AND
OR
VST996.vsd
NOT
is an operator that produces a true state if condition has the value false:
Value of a
Value of NOT a
True
False
False
True
condition
is an expression whose value is either true or false.
AND
is an operator that produces a true state if both its operands have the value true:
Value of a
Value of b
Value of a AND b
True
True
True
True
False
False
False
True
False
False
False
False
OR
is an operator that produces a true state if at least one of its operands has the
value true:
Value of a
Value of b
Value of a AND b
True
True
True
True
False
True
False
True
True
False
False
False
HP pTAL Reference Manual—523746-006
5- 15
Conditional Expressions
Expressions
Table 5-11. Conditional Expressions
Syntax
Example
condition
a
NOT condition
NOT a
condition OR condition
a OR b
condition AND condition
a AND b
condition AND NOT condition
a AND NOT b OR c
Table 5-12. Conditions in Conditional Expressions
Element
Description
Example
Relational
expression
Two conditions connected by a
relational operator. The result type
is INT; a -1 if true or a 0 if false.
The example is true if A equals B.
If a = b THEN ...
Group
comparison
expression
Unsigned comparison of a group
of contiguous elements with
another. The result type is INT; a
-1 if true or a 0 if false. The
example compares 20 words of
two INT arrays.
IF a = b FOR 20 WORDS THEN ...
(conditional
expression)
A conditional expression enclosed
in parentheses. The result type is
INT; a -1 if true or a 0 if false. The
example is true if both B and C
are false. The system evaluates
the parenthesized condition first,
then applies the NOT operator.
IF NOT (b OR c) THEN ...
Arithmetic
expression
An arithmetic, assignment, CASE,
or IF expression that has an INT
or INT(32) result*. The expression
is treated as true if its value is not
0 and false if its value is 0. The
example is true if the value of X is
not 0.
IF x THEN ...
Relational
operator
A signed or unsigned relational
operator that tests a condition
code. Condition code settings are
CCL (negative), CCE (0), or CCG
(positive). The example is true if
the condition code setting is CCL.
IF < THEN ...
* If an arithmetic expression has a result other than INT, use a signed relational expression.
HP pTAL Reference Manual—523746-006
5- 16
NOT, OR, and AND Operators
Expressions
Topics:
•
•
NOT, OR, and AND Operators on page 5-17
Relational Operators on page 5-18
NOT, OR, and AND Operators
You use the operators NOT, OR, and AND to set the state of a single value or the
relationship between two values.
Table 5-13. Results of NOT, OR, and AND Operators
Operator
Operation
Operand Type
Result
Example
NOT
Negation; tests condition
for false state
STRING, INT, or
UNSIGNED(1-16)
True/False
NOT a
OR
Disjunction; produces
true state if either
adjacent condition is
true
STRING, INT, or
UNSIGNED(1-16)
True/False
a OR b
AND
Conjunction; produces
true state if both
adjacent conditions are
true
STRING, INT, or
UNSIGNED(1-16)
True/False
a AND b
Topics:
•
•
Evaluating NOT, OR, and AND Operations on page 5-17
NOT, OR, and AND Operators and Condition Codes on page 5-18
Evaluating NOT, OR, and AND Operations
NOT, OR, and AND operations are evaluated by means of “short-circuit expression
evaluation;” that is:
•
•
Conditions connected by the OR operator are evaluated from left to right only until
a true condition occurs.
Conditions connected by the AND operator are evaluated from left to right until a
false condition occurs. The next condition is evaluated only if the preceding
condition is true.
In Example 5-3 on page 5-17, function f will not be called because a <> 0 is false.
Example 5-3. Short-Circuit Expression Evaluation
a := 0;
IF a <> 0 AND f(x) THEN ... ;
HP pTAL Reference Manual—523746-006
5- 17
Relational Operators
Expressions
NOT, OR, and AND Operators and Condition Codes
If the root operator in the conditional expression of an IF statement is a relational
operator (<, =, >, <=, <>, >=, '<', '=', '>', '<=', '<>', '>='), pTAL sets the condition code
according to the result of the comparison.
Relational operators that test the condition code (for example, IF < THEN...) do not set
the condition code.
NOT, OR, and AND operators set the condition code indicator as described in
Section 13, Hardware Indicators.
Relational Operators
•
•
Signed Relational Operators on page 5-18
Unsigned Relational Operators on page 5-19
Signed Relational Operators
Signed relational operators perform signed comparison of two operands and return a
true or false state.
Table 5-14. Signed Relational Operators
Operator
Meaning
Operand Type*
Result
<
Signed less than
Any data type
True/False
=
Signed equal to
Any data type
True/False
>
Signed greater than
Any data type
True/False
<=
Signed less than or equal to
Any data type
True/False
>=
Signed greater than or equal to
Any data type
True/False
<>
Signed not equal to
Any data type
True/False
* The data type of the operands must match except as noted in Data Types of Expressions on page 5-2.
HP pTAL Reference Manual—523746-006
5- 18
Relational Operators
Expressions
Unsigned Relational Operators
Unsigned relational operators perform unsigned comparison of two operands and
return a true or false state.
Table 5-15. Unsigned Relational Operators
Operator
Operation
Operand Type
Result
'<'
Unsigned less than
STRING, INT, INT(32),
UNSIGNED (1-16)
True/False
'='
Unsigned equal to
STRING, INT,
UNSIGNED (1-16)
True/False
'>'
Unsigned greater than
STRING, INT, INT(32),
UNSIGNED (1-16)
True/False
'<='
Unsigned less than or equal to
STRING, INT, INT(32),
UNSIGNED (1-16)
True/False
'>='
Unsigned greater than or equal to
STRING, INT, INT(32),
UNSIGNED (1-16)
True/False
'<>'
Unsigned not equal to
STRING, INT, INT(32),
UNSIGNED (1-16)
True/False
A condition code reflects the value of the most recently evaluated root operator.
Used with no operands, signed and unsigned operators are equivalent. The result
returned by such a relational operator is:
Relational
Operator
Result Returned
< or '<'
True if CCL
> or '>'
True if CCG
= or '='
True if CCE
<> or '<>'
True if not CCE
<= or '<='
True if CCL or CCE
>= or '>='
True if CCE or CCG
An example of an unsigned operator follows:
IF < THEN ... ;
HP pTAL Reference Manual—523746-006
5- 19
Special Expressions
Expressions
Special Expressions
Special expressions allow you to perform specialized arithmetic or conditional
operations.
Table 5-16. Special Expressions
Special Expression
Expression Type
Description
Assignment
Arithmetic
Assigns the value of an expression to a
variable
CASE
Arithmetic
Selects one of several expressions
IF
Arithmetic
Selects one of two expressions
Group Comparison
Conditional
Performs unsigned comparison of two sets
of data
Assignment
The assignment expression assigns the value of an expression to a variable.
variable
:=
expression
VST012.vsd
variable
is the identifier of a variable in which to store the result of expression
(variable can have an optional bit-deposit field).
expression
is an expression of the same data type as variable. The result of expression
becomes the result of the assignment expression. expression is either:
•
•
An arithmetic expression
A conditional expression (excluding a relational operator with no operands), the
result of which has data type INT.
Examples of assignment expressions:
1. This example decrements a. As long as a- 1 is not 0, the condition is true and the
THEN clause is executed:
IF (a := a - 1) THEN ... ;
2. This example shows the assignment form used as an index. It decrements a and
accesses the next array element:
IF array[a := a - 1] <> 0 THEN ... ;
HP pTAL Reference Manual—523746-006
5- 20
CASE
Expressions
3. This example mixes the assignment form with a relational form. It assigns the
value of b to a, then checks for equality with 0:
IF (a := b) = 0 THEN ... ;
CASE
The CASE expression selects one of several expressions.
CASE
selector
OF
expression-1
BEGIN
;
END
OTHERWISE
expression-2
;
VST013.vsd
selector
is an arithmetic expression [INT or INT(32)] that selects the expression to evaluate.
expression-1
is an expression of any data type. If you specify more than one expression-1,
their data types must be compatible.
expression-2
is an expression whose data type is compatible with the data type of
expression-1. It is evaluated if selector does not select an expression-1.
If you omit the OTHERWISE clause and an out-of-range case occurs, results are
unpredictable.
All expressions in the CASE statement must have compatible data types:
•
•
•
Every data type is compatible with itself.
String and unsigned (1-16) data types are compatible with INT
Unsigned (17-32) data types are compatible with INT(32)
HP pTAL Reference Manual—523746-006
5- 21
CASE
Expressions
•
All fixed-point data types are compatible with each other; however, if
expression-1 and expression-2 are differently scaled fixed-point
expressions, the data type of the IF expression is the data type of the fixed-point
expression whose scale factor is largest. The smaller operand is implicitly scaled to
match the type of the IF expression. For example, these return statements are
equivalent:
int i;
fixed(2)
fixed(3)
fixed(3)
begin
return
else
end
int i;
fixed(2)
fixed(3)
fixed(3)
begin
return
else
end
f2;
f3;
proc p;
if i then f2
f3;
f2;
f3;
proc p;
if i then $scale(f2,1);
f3;
The compiler numbers the instances of expression-1 consecutively, starting with 0.
If selector matches the compiler-assigned number of an expression-1, that
expression-1 is evaluated and becomes the result of the CASE expression. If
selector does not match a compiler-assigned number, expression-2 is
evaluated.
You can nest CASE expressions. CASE expressions resemble unlabeled CASE
statements except that CASE expressions select expressions rather than statements.
Example 5-4 on page 5-22 selects an expression based on the value of a and assigns
it to x:
Example 5-4. CASE Expression
INT x, a, b, c, d;
!Code to initialize variables
x := CASE a OF
BEGIN
b;
c;
d;
OTHERWISE -1;
END;
!
!
!
!
!
If a is
If a is
If a is
If a is
assign
0, assign
1, assign
2, assign
any other
-1 to x.
value of b to X.
value of c to X.
value of d to X.
value,
HP pTAL Reference Manual—523746-006
5- 22
IF
Expressions
IF
The IF expression selects one of two expressions, usually for assignment to a variable.
IF
condition
THEN
expression-1
ELSE
expression-2
VST014.vsd
condition
is either:
•
•
A conditional expression
An INT arithmetic expression. If the result of the arithmetic expression is not 0,
the condition is true. If the result is 0, condition is false.
expression-1
expression-2
are expressions of any data type, but their data types must be compatible:
•
•
•
•
Every data type is compatible with itself.
String and unsigned (1-16) data types are compatible with INT
Unsigned (17-32) data types are compatible with INT(32)
All fixed-point data types are compatible with each other; however, if
expression-1 and expression-2 are differently scaled fixed-point
expressions, the data type of the CASE expression is the data type of the
fixed-point expression whose scale factor is largest. For example, these return
statements are equivalent:
int i;
fixed(-2)
fixed(-3)
fixed(-4)
fixed(-2)
f2;
f3;
f4;
proc p;
begin
return case i of
begin
f3;
f2;
otherwise f4
end
end
int i;
fixed(-2)
fixed(-3)
fixed(-4)
fixed(-2)
f2;
f3;
f4;
proc p;
begin
return case i of
begin
$scale(f3,1);
f2;
otherwise $scale(f4,2)
end
end
If condition is true, the result of the expression-1 becomes the result of the
overall IF expression.
If condition is false, the result of expression-2 becomes the result of the overall
IF expression.
HP pTAL Reference Manual—523746-006
5- 23
Group Comparison
Expressions
You can nest IF expressions within an IF expression or within other expressions. The
IF expression resembles the IF on page 12-26 except that the IF expression:
•
•
Requires the ELSE clause
Contains expressions, not statements
Examples of IF expressions:
1. This example assigns an arithmetic expression to var based on the condition
length > 0:
var := IF length > 0 THEN 10 ELSE 20;
2. This example nests an IF expression (in parentheses) within another expression:
var * index + (IF index > limit THEN var * 2 ELSE var * 3)
3. This example nests an IF expression within another IF expression:
var := IF length < 0 THEN -1
ELSE IF length = 0 THEN 0
ELSE 1;
Group Comparison
The group comparison expression compares a variable with a variable or constant.
With PVU T9248AAD, you can compare any variable up to the current maximum
allowed size for any object of 127.5 megabytes.
var-1
var-2
relational-operator
FOR
count
count-unit
constant
[
constant
]
constant-list
->
next-addr
VST015.vsd
var-1
is the identifier of a variable, with or without an index, that you want to compare to
var-2, constant, or constant-list. var-1 can be a simple variable, array,
simple pointer, structure, structure data item, or structure pointer, but not a readonly array.
HP pTAL Reference Manual—523746-006
5- 24
Group Comparison
Expressions
relational-operator
is one of the following operators:
Signed relational operator
<, =, >, <=, >=, <>
Unsigned relational operator
'<', '=', '>', '<=', '>=', '<>'
All comparisons are unsigned whether you use a signed or unsigned operator.
var-2
is the identifier of a variable, with or without an index, to which var-1 is
compared. var-2 can be a simple variable, array, read-only array, simple pointer,
structure, structure item, or structure pointer.
count
is a unsigned INT arithmetic expression that defines the number of units in var-2
to compare. When count-unit is not present, the units compared are:
var-2
Data Type
Units Compared
Simple variable, array, simple pointer
(including those declared in structures)
STRING
INT
INT(32) or REAL
FIXED or REAL(64)
Bytes
Words
Doublewords
Quadruplewords
Structure
Not applicable
Words
Substructure
Not applicable
Bytes
Structure pointer
STRING
INT
Bytes
Words
HP pTAL Reference Manual—523746-006
5- 25
Group Comparison
Expressions
count-unit
is BYTES, WORDS, or ELEMENTS. count-unit changes the meaning of
count to the following:
BYTES
Compares count bytes; however, if var-1 and var-2 both
have word addresses, BYTES implicitly generates a word
comparison for (count +1)/2 words.
WORDS
Compares count words.
ELEMENTS
Compares count elements. The elements compared depend on
the nature of var-2 and its data type as follows:
var-2
Data Type
Units Compared
Simple variable, array,
simple pointer (including
those declared in
structures)
STRING
INT
INT(32) or REAL
FIXED or REAL(64)
Bytes
Words
Doublewords
Quadruplewords
Structure
Not applicable
Structure
occurrences
Substructure
Not applicable
Substructure
occurrences
Simple variable, array,
simple pointer (including
those declared in
structures)
STRING
INT
INT(32) or REAL
FIXED or REAL(64)
Bytes
Words
Doublewords
Quadruplewords
(For structure pointers,
STRING and INT have
meaning only in group
comparison expressions
and move statements.)
If count-unit is specified and is not BYTES, WORDS, or ELEMENTS, the
compiler issues an error. If you specify BYTES, WORDS, or ELEMENTS, the term
cannot also appear as an identifier in a LITERAL or DEFINE declaration in the
global declarations or in any procedure or subprocedure in which the group
comparison expression appears.
constant
is a number, a character string, or a LITERAL to which var-1 is compared.
If you enclose a simple numeric constant in brackets ([ ]) and if the destination has
a byte address or is a STRING structure pointer, the system compares a single
byte regardless of the size of constant. If you do not enclose constant in
brackets or if the destination has a word address or is an INT structure pointer, the
system compares a word, doubleword, or quadrupleword as appropriate for the
size of constant.
HP pTAL Reference Manual—523746-006
5- 26
Group Comparison
Expressions
constant-list
is a list of one or more constants, which are concatenated and compared to
var-1. Specify constant-list in the form shown in Section 3, Data
Representation.
next-addr
is a variable to contain the address of the first byte or word in var-1 that does not
match the corresponding byte or word in var-2. The compiler returns a 16-bit or
32-bit address as described in the following subsection.
pTAL programs access all data using byte addresses. pTAL uses the low-order bit of
addresses; therefore, when you use an odd-byte address to access a 16-bit word that
you have declared with .EXT, you access the data beginning at the odd-byte address.
You can use group comparisons for:
•
•
Changing the Data Type of the Data on page 5-27
Testing Group Comparisons on page 5-29
Changing the Data Type of the Data
You can compare two strings using a group comparison expression, and save the
address where the comparison stopped in a variable or pointer.
Figure 5-2 on page 5-27 and Figure 5-3 on page 5-28 show that changing the data
type of a variable from INT to STRING can affect whether the address stored in the
result pointer, p, is an even-byte or odd-byte address.
In Figure 5-2 on page 5-27, the IF statement compares x to y on a word-by-word
basis. Because the 16 bits in x are not equal to the 16 bits in y, the conditional
expression is false, and p points to the beginning of string x.
Figure 5-2. Ending Address After Comparing INT Strings (page 1 of 2)
PROC p;
BEGIN
INT x[0:1] := ["AB","CD"]
INT y
:= "AX";
INT .p;
INT q;
IF x = y FOR 1 WORDS -> @p THEN ... ;
q := p; ! Assign "AB" to q
END;
HP pTAL Reference Manual—523746-006
5- 27
Group Comparison
Expressions
Figure 5-2. Ending Address After Comparing INT Strings (page 2 of 2)
P
User Data Segment
A
B
C
D
A
X
X
Y
VST131.vsd
Figure 5-3 on page 28 is the same as Figure 5-2 on page 5-27 except that in
Figure 5-3 on page 5-28, y is a 2-byte STRING array. The IF statement, therefore,
compares x to y on a byte-by-byte basis. Because the first (upper) bytes of x and y
are equal, the comparison continues to the second byte.
Because the second byte of x is “B”, but the second byte of y is “C”, the conditional
expression is false. In Figure 5-3 on page 5-28, therefore, the IF statement stores in p
the address of the second (lower) byte of x.
Figure 5-3. Ending Address After Comparing Strings of Data Type STRING and
INT
PROC p;
BEGIN
INT
STRING
STRING
INT
x[0:1] := ["AB","CD"];
y[0:1] := ["A","C"];
p;
q;
IF x = y FOR 1 WORDS -> @p THEN ... ;
q := p; ! Assign "BC" to q
END;
P
User Data Segment
A
B
C
X
D
A
C
Y
VST132.vsd
HP pTAL Reference Manual—523746-006
5- 28
Group Comparison
Expressions
Testing Group Comparisons
If you use a group comparison in an IF statement, you can test the condition code after
the group comparison is evaluated by setting by using the following relational operators
(with no operands) in a conditional expression:
Operator
Meaning
<
CCL if var-1 '<' var-2
=
CCE if var-1 = var-2
>
CCG if var-1 '>' var-2
See Example 5-5 on page 5-30.
The compiler does a standard comparison and returns a 16-bit next-addr if:
•
•
Both var-1 and var-2 have standard byte addresses
Both var-1 and var-2 have standard word addresses
The compiler does an extended comparison (which is slightly less efficient) and returns
a 32-bit next-addr if:
•
•
Either var-1 or var-2 has a standard byte address and the other has a
standard word address
Either var-1 or var-2 has an extended address
Variables (including structure data items) are byte addressed or word addressed as
follows:
Byte addressed
STRING simple variables
STRING arrays
Variables to which STRING simple pointers point
Variables to which STRING structure pointers point
Substructures
Word addressed
INT, INT(32), FIXED, REAL, or REAL(64) simple variables
INT, INT(32), FIXED, REAL, or REAL(64) arrays
Variables to which INT, INT(32), FIXED, REAL, or REAL(64) simple
pointers point
Variables to which INT structure pointers point
Structures
After an element comparison, next-addr might point into the middle of an element,
rather than to the beginning of the element, because next-addr always refers to the
first byte or 16-bit word (as appropriate) that differs.
Example 5-5 on page 5-30 compares two arrays and then tests the condition code
setting to see if the value of the element in d_array that stopped the comparison is
less than the value of the corresponding element in s_array.
HP pTAL Reference Manual—523746-006
5- 29
Group Comparison
Expressions
Example 5-5. Array Comparison
INT d_array[0:9];
INT s_array[0:9];
! Code to assign values to arrays
IF d_array = s_array FOR 10 ELEMENTS -> @pointer THEN
BEGIN
! They matched
! Do something
END
ELSE
IF < THEN ... ;
! Pointer points to element of d_array
! Do something else
that is less than the corresponding
! element of s_array
When you compare array elements (as in Example 5-5 on page 5-30), the ELEMENTS
keyword is optional but provides clearer source code.
To compare structure or substructure occurrences, you must specify the ELEMENTS
keyword in the group comparison expression, as in Example 5-6 on page 5-30.
Example 5-6. Structure Comparison
STRUCT struct_one [0:9];
BEGIN
INT a[0:2];
INT b[0:7];
STRING c;
END;
STRUCT struct_two (struct_one) [0:9];
! Code here to assign values to structures
IF struct_one = struct_two FOR 10 ELEMENTS THEN ... ;
Example 5-7 on page 5-30 contrasts a comparison to a bracketed (single-byte)
constant with a comparison to an unbracketed (element) constant.
Example 5-7. Constant Comparison
STRING var[0:1];
...
IF var = [0] THEN ... ;
IF var = 0 THEN ... ;
! Compare var[0] to one byte
! Compare var[0:1] to two bytes or
! one 16-bit word
HP pTAL Reference Manual—523746-006
5- 30
Bit Operations
Expressions
Bit Operations
You can access individual bits or groups of bits in a STRING or INT variable.
Table 5-17. Bit Operations
Bit Operation
Description
Extraction
Accesses a bit-extraction field in an INT expression without altering the
expression
Deposit
Assigns a bit value to a bit-deposit field in a variable
Shift
Shifts a bit-shift field in an INT or INT(32) expression to the left or to the
right by a specified number of bits
Topics:
•
•
Bit Extractions on page 5-31
Bit Shifts on page 5-33
Bit Extractions
int-expression
.
<
>
left-bit
:
right-bit
VST016.vsd
int-expression
is an INT(32) expression.
left-bit
is an INT constant in the range 0 through 15 that specifies the bit number of either:
•
•
The leftmost bit of the bit-extraction field
The only bit (if right-bit is the same value as left-bit or is omitted)
If int-expression is a STRING value, left-bit must be in the range 8
through 15. (In a string value, bit 8 is the leftmost bit and bit 15 is the rightmost bit.)
right-bit
is an INT constant that specifies the rightmost bit of the bit field. If intexpression is a STRING value, right-bit must be in the range 8 through 15.
right-bit must be equal to or greater than left-bit. To access a single bit,
omit right-bit or specify the same value as left-bit.
HP pTAL Reference Manual—523746-006
5- 31
Bit Extractions
Expressions
You can perform bit extractions and deposits on 16-bit and 32-bit items. pTAL reports
an error, however, if you attempt to reference bits outside of the bits declared in the
variable’s declaration.
Example 5-8. Bit Extraction
INT
UNSIGNED(4)
STRING
INT(32)
i;
j;
k;
l;
i := j.<7:11>;
! ERROR: You can reference only bits 12
! through 15 of j
i := k.<0:7>;
! ERROR: You can reference only bits 8
! through 15 of k
i := l.<8:31>;
! OK: You can reference any of bits 0
! through 31 of l
Example 5-9. Bit Extraction From an Array
STRING right_byte;
INT array[0:7];
right_byte := array[5].<8:15>;
Example 5-10 on page 5-32 assigns bits 4 through 7 of the sum of two numbers to
RESULT. The parentheses cause the numbers to be added before the bits are
extracted.
Example 5-10. Modifying Bits Before Extracting Them
INT result;
INT num1 := 51;
INT num2 := 28;
result := (num1 + num2).<4:7>;
Example 5-11 on page 5-32 checks bit 15 for a nonzero value.
Example 5-11. Checking a Bit for a Nonzero Value
STRING var;
IF var.<15> THEN ... ;
HP pTAL Reference Manual—523746-006
5- 32
Bit Shifts
Expressions
Bit Shifts
A bit shift operation shifts a bit field a specified number of positions to the left or to the
right within a variable without altering the variable. RISC and Itanium architectures do
not include a signed left-shift operation, so pTAL compiles a signed left shift (for
example, i << 8) as an unsigned left shift (i '<<' 8).
int-expression
shift-operator
positions
dbl-expression
VST017.vsd
int-expression
is an INT arithmetic expression. int-expression can contain STRING, INT, or
UNSIGNED(1-16) operands. The bit shift occurs within a word.
dbl-expression
is an INT(32) arithmetic expression. dbl-expression can contain INT(32) or
UNSIGNED(17-31) operands. The bit shift occurs within a doubleword.
shift-operator
is one of the operators described in Table 5-1 on page 5-3.
positions
is an INT expression that specifies the number of bit positions to shift the bit field.
A value greater than 31 gives undefined results.
The shift count must be less than the number of bits in the shifted value; therefore, you
can shift an INT value up to 15 bits left or right, and an INT(32) value up to 31 bits left
or right.
The compiler reports an error if the shift count is a constant and its value is greater
than the number of bits in the value to shift.
If the shift amount is a dynamic expression and is greater than the maximum allowed
(one bit less than the number of bits being shifted), the result depends on the
CHECKSHIFTCOUNT compiler directive, as follows:
•
•
If CHECKSHIFTCOUNT is enabled and a dynamic shift count is equal to or greater
than the number of bits in the value being shifted, the system aborts your program
with an instruction trap.
If CHECKSHIFTCOUNT is disabled (you specify NOCHECKSHIFTCOUNT), and a
dynamic shift count is equal to or greater than the number of bits in the value being
shifted, program operation is undefined.
HP pTAL Reference Manual—523746-006
5- 33
Bit Shifts
Expressions
The compiler implements arithmetic left shifts as unsigned left shifts (and warns you
when it does this).
Most programs do not need to perform signed left shifts. If your program does require
an arithmetic left shift, use the functions in Example 5-12 on page 5-34 to perform
signed left-shift operations.
Example 5-12. Arithmetic Left Shift
INT PROC ashift16(a, count);
INT a, count;
BEGIN
STRUCT s = a;
BEGIN
UNSIGNED(1) sign_bit;
UNSIGNED(15) rest;
END;
s.rest := s.rest '<<' count;
RETURN a;
END;
INT(32) PROC ashift32(a, count);
INT(32) a;
INT count;
BEGIN
STRUCT s = a;
BEGIN
UNSIGNED(1) sign_bit;
UNSIGNED(31) rest;
END;
s.rest := s.rest '<<' count;
RETURN a;
END;
Table 5-18. Bit-Shift Operators
Operator
Routine
Result
'<<'
Unsigned left shift
through bit 0
Zeros fill vacated bits from the right
'>>'
Unsigned right shift
Zeros fill vacated bits from the left.
>>
Signed right shift
Sign bit (bit 0) unchanged; sign bit fills vacated bits
from the left
HP pTAL Reference Manual—523746-006
5- 34
Bit Shifts
Expressions
Bit-shift operations include:
Operation
User Action
Multiplication by powers of 2
For each power of 2, shift the field one bit to the left.
(Some data might be lost.)
Unsigned division by powers of 2
For each power of 2, shift the field one bit to the right
(Some data might be lost.)
Word-to-byte address conversion
Shift the word address one bit to the left by using an
unsigned shift operator.
Bit shift examples:
1. This unsigned left shift shows how zeros fill the vacated bits from the right:
Initial value
'<<' 2
=
=
0 010 111 010 101 000
1 011 101 010 100 000
2. This unsigned right shift shows how zeros fill the vacated bits from the left:
Initial value
'>>' 2
=
=
1 111 111 010 101 000
0 011 111 110 101 010
3. This signed right shift shows how the sign bit fills the vacated bits from the left:
Initial value =
>> 3
=
1 111 010 101 000 000
1 111 111 010 101 000
4. These examples show multiplication and division by powers of two:
a
a
a
a
:=
:=
:=
:=
b
b
b
b
<<
<<
>>
>>
1;
2;
3;
4;
!
!
!
!
Multiply by 2
Multiply by 4
Divide by 8
Divide by 16
5. This unsigned bit shift converts the word address of an INT array to a byte
address, which allows byte access to the INT array:
INT a[0:5];
STRING .p := @a[0] '<<' 1;
p[3] := 0;
! INT array
! Initialize STRING simple
! pointer with byte address
! Access fourth byte of A
6. This example shifts the right-byte value into the left byte of the same word and sets
the right byte to a zero:
INT b;
b := b '<<' 8;
! INT variable
! Shift right-byte value into left byte
HP pTAL Reference Manual—523746-006
5- 35
Bit Shifts
Expressions
HP pTAL Reference Manual—523746-006
5- 36
6
LITERALs and DEFINEs
A LITERAL declaration associates identifiers with constant values. A DEFINE
declaration associates identifiers (and parameters if any) with text.
You can declare LITERALs and DEFINEs once in a program, and then refer to them by
identifier many times throughout the program. They allow you to efficiently make
significant changes in the source code. You only need to change the declaration, not
every reference to it in the program.
Topics:
•
•
•
•
•
Declaring Literals on page 6-1
Declaring DEFINEs on page 6-3
Calling DEFINEs on page 6-5
How the Compiler Processes DEFINEs on page 6-6
Passing Actual Parameters to DEFINEs on page 6-7
Declaring Literals
A LITERAL declaration specifies one or more identifiers and associates each with a
constant value. Each identifier in a LITERAL declaration is known as a LITERAL.
LITERAL
identifier
constant
=
,
VST018.vsd
identifier
is the LITERAL identifier. Literal identifiers make the source code more readable.
For example, identifiers such as BUFFER_LENGTH and TABLE_SIZE are more
meaningful than their respective constant values of 80 and 128.
HP pTAL Reference Manual—523746-006
6 -1
Declaring Literals
LITERALs and DEFINEs
constant
is one of the following:
•
•
A character string of 1 to 4 characters.
Any of the following numeric constant expressions whose value is not the
address of a global variable (global variables are relocatable during linking):
°
°
°
°
°
°
FIXED(n)
INT
INT(32)
REAL
REAL(64)
UNSIGNED(n)
If you omit any constants, the compiler supplies the omitted numeric constants. The
compiler uses unsigned arithmetic to compute the constants it supplies:
•
•
If you omit the first constant in the declaration, the compiler supplies a zero.
If you omit a constant that follows an INT constant, the compiler supplies an INT
constant that is one greater than the preceding constant. If you omit a constant that
follows a constant of any data type except INT, an error message results.
You access a LITERAL constant by using its identifier in declarations and statements.
The compiler does not allocate storage for LITERAL constants. It substitutes the
constant at each occurrence of the identifier.
Example 6-1. Literal Declarations (page 1 of 2)
All constants specified:
LITERAL true
false
buffer_length
table_size
table_base
entry_size
timeout
CR
LF
=
=
=
=
=
=
=
=
=
-1,
0,
80,
128,
%1000,
4,
%100000D,
%15,
%12;
All constants supplied by compiler:
LITERAL a,
b,
c;
! Compiler assigns 0
! Compiler assigns 1
! Compiler assigns 2
HP pTAL Reference Manual—523746-006
6 -2
Declaring DEFINEs
LITERALs and DEFINEs
Example 6-1. Literal Declarations (page 2 of 2)
Two constants specified, six supplied by compiler:
LITERAL d,
e,
f,
g = 0,
h,
i = 17,
j,
k;
! Compiler assigns
! Compiler assigns
! Compiler assigns
0
1
2
! Compiler assigns
1
! Compiler assigns 18
! Compiler assigns 19
LITERAL identifier in array declaration:
LITERAL length = 50;
INT buffer[0:length - 1];
! Length of array
! Array declaration
LITERAL identifiers in subsequent LITERAL declarations:
LITERAL number_of_file_extents = 16;
LITERAL file_extent_size_in_pages = 32;
LITERAL file_size_in_bytes = (number_of_file_extents '*'
file_extent_size_in_pages) * 2048D ! bytes per page !;
Declaring DEFINEs
A DEFINE declaration associates an identifier (and optional parameters) with text.
DEFINE
item-list
;
,
VST019.vsd
item-list
=
identifier
define-body
#
param-list
VST995.vsd
identifier
is the identifier of the DEFINE.
HP pTAL Reference Manual—523746-006
6 -3
Declaring DEFINEs
LITERALs and DEFINEs
param-list
(
param-name
)
,
VST994.vsd
param-name
is the identifier of a formal parameter. You can specify up to 31 formal
parameters. An actual parameter can be up to 500 bytes. A formal
parameter cannot be a pTAL reserved word.
define-body
specifies all characters between the = and # delimiters. define-body can
span multiple source lines. Enclose character strings in quotation marks ("). To
use # as part of the define-body rather than as a delimiter, enclose the # in
quotation marks or embed the # in a character string.
DEFINE declaration requirements:
•
•
•
•
•
•
•
If a DEFINE and a formal parameter have the same identifier, the formal parameter
has priority during expansion.
A DEFINE must not reference itself.
A DEFINE declaration must not appear within a DEFINE body; that is, do not nest
a DEFINE within a DEFINE.
To ensure proper grouping and order of evaluation of expressions in the DEFINE
body, use parentheses around each DEFINE parameter used in an expression.
Within the DEFINE body, place any compound statements within a BEGIN-END
block.
Directives appearing within a DEFINE body are evaluated immediately; they are
not part of the DEFINE itself.
Expanded DEFINEs must produce correct pTAL constructs. To list the expanded
DEFINEs in the compiler listing, specify the DEFEXPAND directive before the
DEFINE declarations.
HP pTAL Reference Manual—523746-006
6 -4
Calling DEFINEs
LITERALs and DEFINEs
Example 6-2. DEFINE Declarations
Parentheses direct the DEFINE body evaluation:
DEFINE value = ( (45 + 22) * 8 / 2 ) #;
Incrementing and decrementing utilities included:
DEFINE increment (x) = x := x + 1 #;
DEFINE decrement (y) = y := y - 1 #;
Loads numbers into specified bit positions:
DEFINE word_val (a, b) = ((a) '<<' 12) LOR (b) #;
When a STRUCT item and a DEFINE have the same name, the compiler issues a
warning when the STRUCT item is referenced. In Example 6-3 on page 6-5, DEFINE
myname accesses the structure item1 named in the DEFINE body. The compiler
issues a warning because 2 is assigned to mystruct.yrname, not to
mystruct.myname.
Example 6-3. STRUCT and DEFINE Macro Items With the Same Name
PROC myproc MAIN;
BEGIN
DEFINE myname = item1#,
yrname = item2#;
STRUCT mystruct;
BEGIN
INT item1;
INT item2;
INT yrname;
END;
! Structure item has same
! identifier as a DEFINE
mystruct.myname := 1;
! OK: 1 is assigned to mystruct.item1
mystruct.yrname := 2;
! Compiler issues warning;
! 2 is assigned to mystruct.yrname,
! not to mystruct.item2
! More code
END;
Calling DEFINEs
You call a DEFINE by using its identifier in a statement. The invocation can span
multiple lines.
If you call a DEFINE within an expression, make sure the expression evaluates as you
intend. For instance, if you want the DEFINE body to be evaluated before it becomes
part of the expression, enclose the DEFINE body in parentheses.
HP pTAL Reference Manual—523746-006
6 -5
How the Compiler Processes DEFINEs
LITERALs and DEFINEs
Example 6-4. Parenthesized and Nonparenthesized DEFINE Bodies
DEFINE expr = (5 + 2) #;
j := expr * 4;
DEFINE expr = 5 + 2 #;
j := expr * 4;
! Expands to: (5 + 2) * 4;
! assigns 28 to j
! Expands to: 5 + 2 * 4;
! assigns 13 to j
DEFINE identifiers are not called when specified:
•
•
•
Within a comment
Within a character string constant
On the left side of a declaration
For example, the following declaration can call a DEFINE named y but not a
DEFINE named x:
INT x := y;
How the Compiler Processes DEFINEs
The compiler does not allocate storage for DEFINE declarations. When the compiler
encounters a statement using a DEFINE identifier, the compiler expands the DEFINE
declaration as follows:
•
•
•
•
It replaces the DEFINE identifier with the DEFINE body, replaces formal
parameters with actual parameters, and compiles the resulting declaration.
It expands quoted character strings intact.
It expands actual parameters after instantiation. Depending on the order of
evaluation, the expansion can change the scope of a DEFINE declaration.
Emits machine instructions at the appropriate processing interval.
If the DEFEXPAND directive is active, the compiler lists each expanded DEFINE
declaration in the compiler listing following the invocation of the DEFINE. The
expanded listing includes:
•
•
The DEFINE body, excluding comments
Parameters to the DEFINE declaration
HP pTAL Reference Manual—523746-006
6 -6
Passing Actual Parameters to DEFINEs
LITERALs and DEFINEs
Passing Actual Parameters to DEFINEs
If the DEFINE declaration has formal parameters, supply the actual parameters when
you use the DEFINE identifier in a statement.
The number of actual parameters can be less than the number of formal parameters. If
actual parameters are missing, the corresponding formal parameters expand to empty
text. For each missing actual parameter, you can use a placeholder comma, as in
Example 6-5 on page 6-7.
Example 6-5. Fewer Actual Parameters Than Formal Parameters
INT PROC d (a, b, c) EXTENSIBLE; EXTERNAL;
DEFINE something (a, b, c) = d (a, b, c) #;
nothing := something ( , , c); ! Placeholder commas
If a DEFINE has formal parameters and you pass no actual parameters to the DEFINE,
you must specify an empty actual parameter list. You can include commas between the
list delimiters, but need not, as in Example 6-6 on page 6-7.
Example 6-6. No Actual Parameters
DEFINE something (a, b, c) = anything and everything #;
nothing := something ( ); ! Empty parameter list
If the number of actual parameters exceeds the number of formal parameters, as in
Example 6-7 on page 6-7, the compiler issues an error.
Example 6-7. More Actual Parameters Than Formal Parameters
DEFINE something (a, b, c) = anything and everything #;
nothing := something (a, b, c, d); ! Too many parameters
If an actual parameter in a DEFINE invocation requires commas, enclose each comma
in apostrophes ('). An example is an actual parameter that is a parameter list, as in
Example 6-8 on page 6-7.
Example 6-8. Commas in an Actual Parameter
DEFINE varproc (proc1, param) = CALL proc1 (param) #;
varproc (myproc, i ',' j ',' k); ! Expands to:
! CALL myproc (i, j, k);
An actual parameter in a DEFINE invocation can include parentheses, as in
Example 6-9 on page 6-8.
HP pTAL Reference Manual—523746-006
6 -7
Passing Actual Parameters to DEFINEs
LITERALs and DEFINEs
Example 6-9. Parentheses in an Actual Parameter
DEFINE varproc (proc1, param) = CALL proc1 (param) #;
varproc (myproc, (i + j) * k); ! Expands to:
! CALL myproc ((i+j)*k);
Example 6-10 on page 6-8 shows a DEFINE declaration that has one formal parameter
and an assignment statement that uses the DEFINE identifier, passing a parameter
of 3.
Example 6-10. Assignment Statement Using DEFINE Macro Identifier
DEFINE cube (x) = ( x * x * x ) #;
INT result;
result := cube (3) '>>' 1;
! Expands to: (3 * 3 * 3) '>>' 1 = 27 '>>' 1 = 13
Example 6-11. Incrementing and Decrementing Utilities
DEFINE increment (x) = x := x + 1 #;
DEFINE decrement (y) = y := y - 1 #;
INT index := 0;
increment(index); ! Expands to: index := index + 1;
Example 6-12. Filling an Array With Zeros
DEFINE zero_array (array, length) =
BEGIN
array[0] := 0;
array[1] ':=' array FOR length - 1;
END #;
LITERAL len = 50;
INT buffer[0:len - 1];
zero_array (buffer, len);
! Fill buffer with zeros
Example 6-13 on page 6-9 displays a message, checks the condition code, and
assigns an error if one occurs.
HP pTAL Reference Manual—523746-006
6 -8
Passing Actual Parameters to DEFINEs
LITERALs and DEFINEs
Example 6-13. Checking a Condition Code
INT
INT
INT
INT
INT
error;
file;
.buffer[0:50];
count_written;
i;
DEFINE emit (filenum, text, bytes, count, err) =
BEGIN
CALL WRITE (filenum, text, bytes, count);
IF < THEN
BEGIN
CALL FILEINFO (filenum, err);
! Process errors if any
END;
END #;
! Lots of code
IF i = 1 THEN
emit (file, buffer, 80, count_written, error);
HP pTAL Reference Manual—523746-006
6 -9
LITERALs and DEFINEs
Passing Actual Parameters to DEFINEs
HP pTAL Reference Manual—523746-006
6- 10
7
Simple Variables
A simple variable is a single-element data item of a specified data type that is not an
array, a structure, or a pointer. After you declare a simple variable, you can use its
identifier in statements to access or change the data contained in the variable. You
must declare variables before you use them.
This section defines the syntax for declaring simple variables. The declaration
determines:
•
•
•
•
•
•
•
The kind of values the simple variable can represent
The amount of storage the compiler allocates for the variable
The operations you can perform on the variable
The byte or word addressing mode of the variable
The direct or indirect addressing mode of the variable
How the compiler allocates storage for simple variables
How you access the variables
Topics:
•
•
•
•
•
Declaring Simple Variables on page 7-1
Specifying Simple Variable Address Types on page 7-3
Initializing Simple Variables With Numbers on page 7-4
Initializing Simple Variables With Character Strings on page 7-4
Examples on page 7-4
Declaring Simple Variables
The simple variable declaration associates an identifier with a single-element data item
and optionally initializes it.
type
VOLATILE
identifier
;
:=
initialization
,
VST622.vsd
HP pTAL Reference Manual—523746-006
7 -1
Declaring Simple Variables
Simple Variables
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
type
is one of the following data types:
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
BADDR
CBADDR
CWADDR
EXTADDR
INT
INT(32)
FIXED
FIXED (fpoint )
PROCADDR
REAL
REAL
REAL(64)
SGBADDR
SGWADDR
SGXBADDR
SGXWADDR
STRING
UNSIGNED (width )
WADDR
fpoint
For the FIXED data type, fpoint is the implied fixed-point setting. fpoint is
an integer in the range -19 through 19. If you omit fpoint, the default fpoint is
0 (no decimal places).
A positive fpoint specifies the number of decimals to the right of the decimal
point. A negative fpoint specifies a number of integers to the left of the
decimal point.
fpoint can also be an asterisk (*).
HP pTAL Reference Manual—523746-006
7 -2
Specifying Simple Variable Address Types
Simple Variables
width
For INT, REAL, and UNSIGNED data types, the value in parentheses is a
constant expression specifying the width, in bits of the variable. The constant
expression can include LITERALs and DEFINEs. The result of the constant
expression must be one of the following values:
Data Type Prefix
width in bits
INT
16, 32, or 64
REAL
32 or 64
UNSIGNED
(simple variable, parameter, or function result)
a value in the range 1 through 31
UNSIGNED (array)
1, 2, 4, or 8
identifier
is the identifier of the simple variable, specified in the form described in Section 2,
Language Elements.
initialization
is an expression that represents the value to store in identifier. The default
number base is decimal. The kind of expression you can specify depends on the
scope of the simple variable:
•
•
For a global simple variable, use a constant expression.
For a local or sublocal simple variable, use any arithmetic expression including
variables.
You can initialize simple variables of any data type except UNSIGNED. For more
information about initializing a simple variable, see the following subsections.
Specifying Simple Variable Address Types
The address type of a simple variable is the same as the address type of a pointer to
data of the same object data type as the simple variable, as in the following examples:
INT .j;
INT i;
! A pointer: address type is WADDR
! A simple variable: address type is WADDR
HP pTAL Reference Manual—523746-006
7 -3
Simple Variables
Initializing Simple Variables With Numbers
Initializing Simple Variables With Numbers
When you initialize with a number, it must match the data type specified for the simple
variable. The data type determines what kind of values the simple variable can store:
•
•
•
STRING, INT, and INT(32) simple variables can contain integer constants in binary,
decimal, hexadecimal, or octal base.
REAL and REAL(64) simple variables can contain signed floating-point numbers.
FIXED simple variables can contain signed 64-bit fixed-point numbers in binary,
decimal, hexadecimal, or octal base. For decimal numbers, you can also specify a
fractional part, preceded by a decimal point. If a FIXED number has a different
decimal setting than the specified fpoint, the system scales the number to match
the fpoint. If the number is scaled down, some precision is lost.
Section 3, Data Representation, describes the syntax for specifying numeric constants
in each number base by data type.
Initializing Simple Variables With Character
Strings
STRING, INT, and UNSIGNED simple variables can be initialized with character
strings. The character string can contain the same number of bytes as the simple
variable or fewer. Unspecified bytes are zero bytes. Each character in a character
string requires one byte of storage.
Examples
•
•
•
•
•
•
Example 7-1, Declaring Simple Variables Without Initializing Them, on page 7-5
Example 7-2, Declaring and Initializing Simple Variables, on page 7-5
Example 7-3, Effect of fpoint on FIXED Simple Variables, on page 7-5
Example 7-4, Initializing Simple Variables With Constants and Variables*, on
page 7-6
Example 7-5, Declaring Simple VOLATILE Variables, on page 7-6
Example 7-6, PROCADDR and PROCPTR, on page 7-6
HP pTAL Reference Manual—523746-006
7 -4
Examples
Simple Variables
Example 7-1. Declaring Simple Variables Without Initializing Them
STRING b;
INT(32) dblwd1;
REAL(64) long;
UNSIGNED(5) flavor;
BADDR ba;
WADDR wa;
EXTADDR ea;
Example 7-2. Declaring and Initializing Simple Variables
STRING y := "A";
STRING z := 255;
INT a := "AB";
INT b := 5 * 2;
INT c := %B110;
INT(32) dblwd2 := %B1011101D;
INT(32) dblwd3 := $DBL(%177775);
REAL flt1 := 365335.6E-3;
REAL(64) flt2 := 2718.2818284590452L-3;
!
!
!
!
!
!
!
!
!
Character string
Byte value
Character string
Expression
Word value
Doubleword value
Built-in routine
Doubleword value
Quadrupleword value
WADDR w;
EXTADDR e;
INT t;
STRING s;
INT ro_wd = 'p' := 3;
STRING ro_b = 'p' := "A";
BADDR
WADDR
CWADDR
CBADDR
SGWADDR
SGBADDR
EXTADDR
ba
wa
cwa
cba
sgwa
sgnq
ea
:=
:=
:=
:=
:=
:=
:=
@s;
@t;
@ro_wd;
@ro_b;
0;
1;
$DBL (1);
Example 7-3. Effect of fpoint on FIXED Simple Variables
FIXED(-3) f := 642987F;
FIXED(3) g := 0.642F;
FIXED(2) h := 1.234F;
! Stored as 642; accessed as 642000
! Stored as 642, accessed as 0.642
! Stored as 123; accessed as 1.23
HP pTAL Reference Manual—523746-006
7 -5
Examples
Simple Variables
Example 7-4. Initializing Simple Variables With Constants and Variables*
INT global := 34;
! Only constants allowed
! in global initialization
PROC mymain MAIN;
BEGIN
INT local := global + 10;
INT local2 := global * local;
FIXED local3 := $FIX(local2);
!Lots of code
END;
!Any expression allowed
! in local or sublocal
! initialization
! End of mymain procedure
* Constants can be at any level, but variables must be local or sublocal.
Example 7-5. Declaring Simple VOLATILE Variables
VOLATILE INT
VOLATILE UNSIGNED(3)
VOLATILE STRING
i;
mask;
gs;
Example 7-6. PROCADDR and PROCPTR
PROCADDR pa;
PROCPTR q (j); INT j; END PROCPTR;
STRUCT ABC;
BEGIN
PROCPTR z (i); INT i; END PROCPTR;
END;
HP pTAL Reference Manual—523746-006
7 -6
8
Arrays
An array is a one-dimensional set of elements of the same data type. Each array is
stored as a collective group of elements. You use arrays to store constants, especially
character strings. After you declare an array, you can use its identifier to access the
array elements individually or as a group.
You can declare:
•
•
•
Arrays
Read-only arrays
Address arrays
The declaration includes initializing the array as well as allocating storage for the array.
In addition the declaration determines:
•
•
•
The kind of values the array can represent
The operations you can perform on the array
The byte or word addressing mode of the array
This section defines the syntax for declaring:
•
•
•
Arrays
Read-only arrays
Address arrays
Section 9, Structures, describes the syntax for declaring arrays within structures and
how to declare structures that simulate arrays of arrays, or arrays of structures
(including multidimensional arrays).
Topics:
•
•
•
Declaring Arrays on page 8-2
Declaring Read-Only Arrays on page 8-6
Using Constant Lists in Array Declarations on page 8-8
HP pTAL Reference Manual—523746-006
8 -1
Declaring Arrays
Arrays
Declaring Arrays
An array declaration associates an identifier with a set of elements of the same data
type. The data type of an array can be one of the pTAL address types.
type
identifier
;
range
:=
.
initialization
.EXT
.SG
.SGX
,
VST021.vsd
type
is one of the following:
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
BADDR
CBADDR
CWADDR
EXTADDR
FIXED (fpoint )
INT
INT(32)
FIXED
PROCADDR
REAL
REAL
REAL(64)
SGBADDR
SGWADDR
SGXBADDR
SGXWADDR
STRING
UNSIGNED (width )
WADDR
HP pTAL Reference Manual—523746-006
8 -2
Declaring Arrays
Arrays
The data type determines:
•
•
The kind of values that are appropriate for the array
The storage unit the compiler allocates for each array element as follows:
width
is a constant expression specifying the width, in bits, of the variable.
fpoint
is the implied fixed point of the FIXED variable.
identifier
is the array name.
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
range
[
lower-bound
:
upper-bound
]
VST993.vsd
lower-bound
is an INT or INT(32) constant expression (in the range -32,768 through 32,767)
that specifies the index (relative to the zeroth element) of the first array
element you want allocated.
upper-bound
is an INT or INT(32) constant expression (in the range -32,768 through 32,767)
that specifies the index (relative to the zeroth element) of the last array element
you want allocated.
For arrays declared outside of structures, upper-bound must be equal to or
larger than lower-bound.
Here are some examples of bounds:
STRING a_array [0:2];
INT b_array [0:19];
UNSIGNED(1) flags [0:15];
HP pTAL Reference Manual—523746-006
8 -3
Declaring Arrays
Arrays
initialization
is a constant or a constant list of values to assign to the array elements, beginning
with the lower-bound element. (Constant lists are described in Section 3, Data
Representation.) If you specify fewer initialization values than the number of
elements, the values of uninitialized elements are undefined. You cannot initialize
extended indirect local arrays or UNSIGNED arrays.
Specify initialization values that are appropriate for the data type of the array. For
example, if the decimal setting of an initialization value differs from the fpoint of
a FIXED array, the system scales the initialization value to match the fpoint. If
the initialization value is scaled down, some precision is lost.
Examples:
•
•
•
•
•
•
•
Example 8-1, Declaring Arrays With Various Bounds, on page 8-4
Example 8-2, Declaring Arrays and Initializing Them With Constants, on page 8-4
Example 8-3, Declaring Arrays and Initializing Them With Constant Lists, on
page 8-5
Example 8-4, Initializing Arrays, on page 8-5
Example 8-5, Array With Positive fpoint, on page 8-5
Example 8-6, Array With Negative fpoint, on page 8-5
Example 8-7, Read-Only Array Declaration With Indirection Symbol, on page 8-7
Example 8-1. Declaring Arrays With Various Bounds
FIXED
.array_a[0:3];
INT
.array_b[0:49];
UNSIGNED(1) flags[0:15];
! Four-element array
! Fifty-element array
! Array of 16 one-bit elements
Example 8-2. Declaring Arrays and Initializing Them With Constants
INT a_array[0:3] := -1;
INT b_array[0:1] := "abcd";
! Store -1 in element [0];
! values in elements [1:3] are undefined
! Store one character per byte
HP pTAL Reference Manual—523746-006
8 -4
Declaring Arrays
Arrays
Example 8-3. Declaring Arrays and Initializing Them With Constant Lists
INT c_array[0:5] := [1,2,3,4,5,6];
! Constant list
STRING buffer[0:102] := [ "A constant list can consist ",
"of several character string constants, ",
"one to a line, separated by commas." ];
INT(32) mixed[0:3] := ["abcd", 1D, %B0101011D, %20D];
! Mixed constant list
LITERAL len = 80;
STRING buffer[0:len - 1] := len * [" "];
! Length of array
! Repetition factor
FIXED f[0:35] := 3*[2*[1F,2F], 4*[3F,4F]];
! Repetition factors
LITERAL cr = %15,
lf = %12;
STRING err_msg[0:9] := [cr, lf, "ERROR", cr, lf, 0];
! Constant list
Example 8-4. Initializing Arrays
INT(32) a[0:1] := [5D, 7D];
PROC my_procedure;
BEGIN
STRING b[0:1] := ["A","B"];
FIXED EXT c[0:3];
SUBPROC my_subproc;
BEGIN
INT d[0:2] := ["Hello!"];
! Lots of code
END;
END;
! Initialize global array
! Initialize local standard array
! Cannot initialize local
! extended indirect array
! Initialize sublocal array
Example 8-5. Array With Positive fpoint
FIXED(2) x[0:1] := [ 0.64F, 2.348F ];
! Stored as 64 and 234; accessed as 0.64 and 2.34
Example 8-6. Array With Negative fpoint
FIXED(-3) y[0:1] := [ 642913F, 1234F ];
! Stored as 642 and 1; accessed as 642000 and 1000
HP pTAL Reference Manual—523746-006
8 -5
Declaring Read-Only Arrays
Arrays
Declaring Read-Only Arrays
A read-only array declaration allocates storage for a nonmodifiable array in a user
code segment. Read-only arrays are sometimes referred to as p-relative arrays,
because they are addressed using the program counter (the p register).
type
identifier
=
range
'p'
initialization
:=
;
,
VST022.vsd
type
is any data type described in Declaring Arrays on page 8-2 except UNSIGNED.
The data type of a read-only array cannot be an address type.
identifier
is the identifier of the read-only array.
range
[
lower-bound
:
upper-bound
]
VST993.vsd
lower-bound
is an INT or INT(32) constant expression (in the range -32,768 through 32,767)
that specifies the index (relative to the zeroth element) of the first array
element you want allocated. The default value is 0.
upper-bound
is an INT or INT(32) constant expression (in the range -32,768 through 32,767)
that specifies the index (relative to the zeroth element) of the last array element
you want allocated. The default value is the number of elements initialized
minus one.
'p'
specifies a read-only array.
HP pTAL Reference Manual—523746-006
8 -6
Declaring Read-Only Arrays
Arrays
initialization
is a constant list to assign to the array elements. You must initialize read-only
arrays when you declare them. (Constant lists are described in Section 3, Data
Representation.)
Specify initialization values that are appropriate for the data type of the array. For
example, if the decimal setting of an initialization value differs from the fpoint of
a FIXED array, the system scales the initialization value to match the fpoint. If
the initialization value is scaled down, some precision is lost.
The compiler reports a warning if a read-only array declaration specifies an indirection
symbol (see Table 2-7, Indirection Symbols, on page 2-7).
Example 8-7. Read-Only Array Declaration With Indirection Symbol
PROC p;
BEGIN
INT
i = 'P'
INT
.j = 'P'
STRING k = 'P'
STRING .l = 'P'
END;
:=
:=
:=
:=
[2,3,4];
[5,6,7];
["abc"];
["ccc"];
!
!
!
!
OK
Compiler reports a warning
OK
Compiler reports a warning
You must initialize read-only arrays.
UNSIGNED read-only arrays are not allowed, because they cannot be initialized.
If you declare a read-only array in a RESIDENT procedure, the array is also resident in
main memory.
The linker links each global read-only array into any code segment containing a
procedure that references the array.
You can access read-only arrays as you access any other array, except that:
•
•
•
You cannot modify a read-only array; that is, you cannot specify a read-only array
on the left side of an assignment or move operator.
You cannot specify a read-only array on the left side of a group comparison
expression.
In a SCAN or RSCAN statement, you cannot use next-addr to read the last
character of a string. You can use next-addr to compute the length of the string.
Example 8-8. Declaring and Initializing a Read-Only Array
STRING prompt = 'P' := ["Enter Character: ", 0];
INT
error = 'P' := ["INCORRECT INPUT"];
HP pTAL Reference Manual—523746-006
8 -7
Using Constant Lists in Array Declarations
Arrays
Using Constant Lists in Array Declarations
pTAL requirements for array declarations are:
•
•
If an array declaration includes an initialization string, the size of a constant list
must be less than or equal to the size of the array. If the constant list is larger than
the array, an error occurs.
If the alignment of the elements of the initialization string under SHARED2 rules
and SHARED8 rules is different, you must specify a FIELDALIGN clause in the
initialization string.
The number of bits in a constant list that you assign to a read-write array must be the
same as the number of bits in the array. The number of bits in a constant list that you
assign to a read-only array must be the less than or equal to the number of bits in the
array.
Topics:
•
•
Read-Only Arrays on page 8-8
Nonstring Arrays on page 8-9
Read-Only Arrays
The number of bits in the initialization string must equal the number of bits in the readonly array.
If the read-only-array declaration does not specify array bounds, the number of bits in
the initialization string must be an integral multiple of the number of bits in the array’s
base type.
Example 8-9. Declaring Read-Only Arrays With Constant Lists
INT p
INT q[0:3]
STRING r
STRING s[0:3]
STRING t
=
=
=
=
=
'P'
'P'
'P'
'P'
'P'
:=
:=
:=
:=
:=
"abcd";
"abcdabcd";
"abcd";
"abcd";
[1,2,3];
!
!
!
!
!
OK
OK
OK
OK
OK
STRING u[0:3] = 'P' := [1,2,3];
! ERROR: Initialization size
! (24 bits) must equal the
! array's size (32 bits)
STRING v
= 'P' := [1,2,3,4];
STRING w[0:3] = 'P' := [1,2,3,4];
! OK
! OK
INT
! ERROR: Initialization size
! must be an integral
! multiple of array's base
! type size
x
= 'P' := "abc";
HP pTAL Reference Manual—523746-006
8 -8
Nonstring Arrays
Arrays
Nonstring Arrays
You can specify an initialization string when you declare an array:
INT .a[0:3] := [0,1,2,3];
The length of the initialization string must be less than or equal to the length of the
array.
Example 8-10. Declaring Nonstring Arrays With Constant Lists
INT
INT
INT
INT
.a[0:3]
.a[0:3]
.a[0:3]
.a[0:3]
:=
:=
:=
:=
[0,1,2];
! OK: Init string is
[0,1,2,3];
! OK: Init string is
[0,1,2,3,4]; ! ERROR: Init string
[%H1234567812345678%F]; !OK: Init
shorter than array
right length
is too long
string is right length
HP pTAL Reference Manual—523746-006
8 -9
Nonstring Arrays
Arrays
HP pTAL Reference Manual—523746-006
8- 10
9
Structures
A structure is a collectively stored set of data items that you can access individually or
as a group. Structures contain structure items (fields) such as simple variables, arrays,
simple pointers, structure pointers, and nested structures (called substructures). The
structure items can be of different data types.
Structures usually contain related data items such as the fields of a file record. For
example, in an inventory control application, a structure might contain an item number,
the unit price, and the quantity on hand.
A structure declaration associates an identifier with one of the kinds of structures listed
in Table 9-1 on page 9-1.
Table 9-1. Kinds of Structures
Structure
Description
Definition
Describes a structure layout and allocates storage for it
Template
Describes a structure layout but allocates no storage for it
Referral
Allocates storage for a structure whose layout is the same as the layout of a
previously declared structure
The TNS/E instructions setjmp() and longjmp() require data to be aligned on 16byte boundaries. To ensure that this data is aligned on 16-byte boundaries, you must
declare it in a template structure using STRUCTALIGN (MAXALIGN).
Topics:
•
•
•
•
•
•
•
•
•
•
•
•
•
Structure Layout on page 9-3
Overview of Field Alignment on page 9-5
Field and Base Alignment on page 9-8
Array Alignment in Structures on page 9-13
Structure Alignment on page 9-15
Substructure Alignment on page 9-16
Alignment Considerations for Substructures on page 9-19
FIELDALIGN Clause on page 9-20
FIELDALIGN Compiler Directive on page 9-20
SHARED2 Parameter on page 9-20
SHARED8 Parameter on page 9-22
Reference Alignment With Structure Pointers on page 9-27
STRUCTALIGN (MAXALIGN) Attribute on page 9-32
HP pTAL Reference Manual—523746-006
9 -1
Structures
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
VOLATILE Attribute on page 9-33
Declaring Definition Structures on page 9-33
Declaring Template Structures on page 9-35
Declaring Referral Structures on page 9-38
Declaring Simple Variables in Structures on page 9-40
Declaring Arrays in Structures on page 9-40
Declaring Substructures on page 9-42
Declaring Filler on page 9-46
Declaring Simple Pointers in Structures on page 9-48
Declaring Structure Pointers in Structures on page 9-51
Declaring Redefinitions on page 9-53
Simple Variable on page 9-54
Array on page 9-55
Definition Substructure on page 9-56
Referral Substructure on page 9-59
Simple Pointer on page 9-61
Structure Pointer on page 9-63
Equivalenced structures are discussed in Section 11, Equivalenced Variables.
HP pTAL Reference Manual—523746-006
9 -2
Structure Layout
Structures
Structure Layout
The structure layout (or body) is a BEGIN-END block that contains declarations of
structure items.
Table 9-2. Structure Items
Structure Item
Description
Simple variable
A single-element variable
Array
A variable that contains multiple elements of the same data type
Substructure
A structure nested within a structure (to a maximum of 64 levels)
Filler byte
A place-holding byte
Filler bit
A place-holding bit
Simple pointer
A variable that contains a memory address, usually of a simple variable
or array, which you can access with this simple pointer
Structure pointer
A variable that contains the memory address of a structure, which you
can access with this structure pointer
Redefinition
A new identifier and sometimes a new description for a substructure,
simple variable, array, or pointer declared in the same structure
You can nest substructures within structures (that is, you can declare a substructure
within a substructure within a substructure, and so on) as deeply as the pTAL stack
allows (approximately 60 levels). The structure and each substructure has a BEGINEND level depending on the level of nesting.
The syntax for declaring each structure item is described after the syntax for declaring
structures. The following rules apply to all structure items:
•
•
•
You can declare the same identifier in different structures and substructures, but
you cannot repeat an identifier at the same BEGIN-END level.
You cannot initialize a structure item when you declare it. After you have declared
it, however, you can assign a value to it by using an assignment statement or move
statement.
You can control how the compiler aligns a structure in memory and the fields of a
structure within a structure by using the FIELDALIGN clause or FIELDALIGN
compiler directive.
Definition structure and template structure declarations can optionally include a
FIELDALIGN clause. You cannot specify a FIELDALIGN clause on a referral
structure declaration.
•
If you declare a structure pointer and assign the address of a structure to it or use
a reference parameter to address structure data you can specify a REFALIGNED
clause to ensure that the structure is well-aligned.
HP pTAL Reference Manual—523746-006
9 -3
Overview of Structure Alignment
Structures
Topics:
•
•
Overview of Structure Alignment on page 9-4
Structures Aligned at Odd-Byte Boundaries on page 9-5
Overview of Structure Alignment
The memory alignment of the fields of a structure is important to pTAL. A field that is
aligned for fastest access is said to be well-aligned. A field that is not aligned for
fastest access is said to be misaligned.
A structure is well-aligned if the address of the base of the structure in memory is a
multiple of its base alignment; otherwise, the structure is misaligned. If a structure is
misaligned, some or all of its fields will also be misaligned.
The layout of structures and the alignment options you specify affect the object code
generated by pTAL. If you specify that the fields of a structure are not well-aligned (by
specifying the FIELDALIGN clause with the SHARED2 parameter) pTAL generates
conservative code for each reference. Conservative code might require more
instructions to reference structure fields than references to well aligned fields.
Each structure declaration specifies whether pTAL generates fast code or conservative
code when your program references a field of the structure.
Fast code takes full advantage of the RISC and Itanium architectures and produces the
best performance, provided that the field being referenced is well-aligned. If the field is
misaligned, an exception occurs. Access to the misaligned field is handled by a
millicode exception handler that completes the access but at a significant performance
cost.
Conservative code is somewhat slower than fast code but does not cause exceptions
when it accesses misaligned data.
pTAL ensures that definition structures and referral structures are well-aligned;
however, if you declare a structure pointer and assign the address of a structure to it or
use a reference parameter to address structure data, the compiler cannot ensure that
the structure is well-aligned; therefore, when you declare a structure pointer, you can
specify what assumptions you want pTAL to make when it generates code to access
your data. You can specify a REFALIGNED clause (see REFALIGNED Clause on
page 9-28).
The overall guidelines for alignment for a native process are:
•
Accessing data in memory takes the least amount of time if the data is well-aligned
and either the compiler has allocated the data or you reference the data with a
pointer that specifies REFALIGNED(8). A data item is well-aligned if its byte
address is an integral multiple of its length. For example, an INT is well-aligned if it
begins at an even-byte address, an INT(32) at an address that is a multiple of four,
and so forth.
HP pTAL Reference Manual—523746-006
9 -4
Structures Aligned at Odd-Byte Boundaries
Structures
•
•
Accessing data is somewhat slower if the data is not well-aligned and you
reference the data using a pointer that specifies REFALIGNED(2).
Accessing data is significantly slower if the data is not well-aligned, but pTAL
generates code that functions as if the data is well-aligned. In this case, your
program traps to the millicode exception handler, which completes the data access
and returns to your program.
To comply with these guidelines, some structures require that you explicitly add filler to
ensure that:
•
•
Each field begins at an address that is a multiple of its length.
The total length of a structure is a multiple of the widest field in the structure.
Structures Aligned at Odd-Byte Boundaries
If you attempt to access data at an odd-byte address, the results are undefined,
whether the data is a simple variable or a field of a structure. Your program might or
might not trap.
Overview of Field Alignment
This subsection gives you an overview of the FIELDALIGN clause and the
FIELDALIGN compiler directive, and the field alignment parameters SHARED2,
SHARED8, PLATFORM, and AUTO.
The FIELDALIGN clause specifies the alignment of a structure and of all substructures
that do not specify a FIELDALIGN clause. For details, see FIELDALIGN Clause on
page 9-20.
The FIELDALIGN compiler directive specifies the default alignment for all structures. It
includes the SHARED2, SHARED8, PLATFORM, and AUTO parameters as well as a
NODEFAULT parameter. For more information, see Section 17, Compiler Directives.
When you declare a definition or template structure, you specify (either explicitly using
a FIELDALIGN clause or implicitly according to the current setting of the FIELDALIGN
compiler directive) how you want the compiler to allocate memory for the structure. The
field alignment for each such structure is specified by one of the following parameters
to a FIELDALIGN clause or directive:
You use SHARED2 and SHARED8 field alignment for structure data used by
processes running in either pTAL or TAL. You can share data by interprocess
communication or by accessing it on a shared storage medium such as disk or tape.
Your program might use library routines that require that structure data be in a
SHARED2 or SHARED8 format. If you use library routines that include structures that
specify SHARED2 or SHARED8, you might need to declare your structures with the
same field alignment as the structures in the library.
HP pTAL Reference Manual—523746-006
9 -5
SHARED2
Structures
If more than one program uses the same source file, you might want to include a
FIELDALIGN clause on every structure declaration in the source file. This ensures that
the field alignment of every structure is consistent across all programs that compile the
source file.
If you do not specify a FIELDALIGN clause, each structure will use the current setting
of the FIELDALIGN compiler directive, which might be different for different
compilations.
Topics:
•
•
•
•
•
SHARED2 on page 9-6
SHARED8 on page 9-6
PLATFORM on page 9-7
AUTO on page 9-7
Differences Between PLATFORM and AUTO on page 9-8
SHARED2
FIELDALIGN(SHARED2) directs the compiler to allocate the structure’s fields. Specify
FIELDALIGN(SHARED2) when:
•
•
Your process is limited by the available stack space in TAL programs.
You want the structure to hold data (for example, interprocess messages, memory,
or files) that is shared by processes or applications running on a combination of
TAL-compiled processes and RISC and Itanium architectures.
For more information, see FIELDALIGN Clause on page 9-20 and SHARED2
Parameter on page 9-20.
SHARED8
FIELDALIGN(SHARED8) directs the compiler to allocate the structure’s fields for
optimal performance in pTAL. Specify FIELDALIGN(SHARED8) when:
•
•
•
•
You want optimal performance in pTAL.
The fields you reference in the structure are well-aligned.
All processes that share the data can use SHARED8 alignment.
You want the structure to hold data (for example, interprocess messages, memory,
or files) that is shared by processes or applications that are composed of both
pTAL and TAL code.
In TAL, access to SHARED8 components is as efficient as access to SHARED2
components, but SHARED8 components usually require more space than
SHARED2 components.
HP pTAL Reference Manual—523746-006
9 -6
PLATFORM
Structures
For more information, see FIELDALIGN Clause on page 9-20 and SHARED8
Parameter on page 9-22.
PLATFORM
FIELDALIGN(PLATFORM) directs the compiler to allocate the structure’s fields
according to a layout that is consistent across different programming languages
running on a given architecture. (PLATFORM field alignment is not consistent across
different architectures.) The data might be shared among modules written in different
programming languages, in one of these ways:
•
•
Running within a single process
Running in separate processes, all of which are either pTAL, TAL, or C/C++, but
not a combination of these
pTAL allocates the fields of a PLATFORM structure according to the rules used by the
native mode HP C compiler for PLATFORM layouts; that is:
•
•
•
•
Each field begins at an address that is an integral multiple of the length of the field.
That is, pTAL allocates 1-byte, 2-byte, 4-byte, and 8-byte fields at addresses that
are integral multiples of one, two, four, and eight, respectively.
UNSIGNED fields are not necessarily aligned to byte boundaries. They can share
1-byte, 2-byte, and 4-byte containers with other items. An UNSIGNED field,
however, cannot span an address that is an integral multiple of four. If an
UNSIGNED item would span a 4-byte address boundary, the compiler allocates the
UNSIGNED field beginning at the next 4-byte boundary.
The alignment of a structure or substructure is the alignment of its widest field,
unless the structure or substructure contains an UNSIGNED field, in which case,
the alignment of the structure or substructure is at least four.
The compiler adds bytes, as needed, to the end of a PLATFORM structure or
substructure such that the length of the structure or substructure is an integral
multiple of its widest field.
AUTO
FIELDALIGN(AUTO) directs the compiler to align structure fields for optimal access on
the architecture on which the object file will be run. Specify AUTO only for structures
whose data exists solely within a process. Use PLATFORM to share data across
processes.
Use AUTO field alignment for a structure that you use only locally—that is, only within
a process—not between processes that run on different architectures. (AUTO field
alignment is not consistent across different architectures and compilers.)
A structure’s layout can be different in pTAL, TAL, and C/C++ if the structure describes
data that is used only within a process and only for the duration of the process. In this
case, you can specify AUTO as the FIELDALIGN parameter.
HP pTAL Reference Manual—523746-006
9 -7
Differences Between PLATFORM and AUTO
Structures
Specify FIELDALIGN(AUTO) for structures that are not used to exchange data
between processes.
Do not assume that fields of an AUTO structure are contiguous in memory. The
compilers insert filler where required for optimal alignment.
Pointer fields and nonpointer fields in structures declared with AUTO field alignment
can be any address type or data type, respectively.
TAL, pTAL, and C lay out AUTO structures differently.
Differences Between PLATFORM and AUTO
PLATFORM structures and substructures can contain UNSIGNED and STRING items
within a 2-byte word. In AUTO structures and substructures, STRING items and
UNSIGNED items are not allocated within a 2-byte word.
PLATFORM structures and substructures can contain an odd number of bytes. AUTO
(and SHARED8) structures must contain an even number of bytes. pTAL adds an extra
byte at the end of AUTO structures if, without the byte, the structure would contain an
odd number of bytes.
The length of PLATFORM structures or substructures that contains an UNSIGNED
item must be an integral multiple of four bytes. pTAL adds extra bytes, as needed, to
the end of such structures and substructures.
Field and Base Alignment
The field alignment of a structure specifies the offsets at which fields of the structure
must begin relative to the base of the structure. A scalar field is well-aligned when its
byte offset is an integral multiple of its width. A substructure is well-aligned when the
offset of its base, relative to its encompassing structure, is an integral multiple of its
widest field.
Use the FIELDALIGN clause to specify how you want pTAL to align the fields in the
structure. For more information, see FIELDALIGN Clause on page 9-20.
Topics:
•
•
Base Alignment on page 9-9
Structure Alignment Examples on page 9-9
HP pTAL Reference Manual—523746-006
9 -8
Base Alignment
Structures
Base Alignment
The base alignment of a structure is the alignment of the widest field in the structure.
The base alignment determines where the structure can be located in memory and be
well-aligned. A structure is well-aligned when the memory address at which it is located
is an integral multiple of its base alignment.
Table 9-3. Base Alignment and Field Alignment Relationships
Width of Widest Field in Structure
FIELDALIGN(SHARED2)
FIELDALIGN(SHARED8)
1
1 or 2*
1 or 2*
2
2
2
4
2
4
8
2
8
*Definition (inline) substructures have a base alignment of one. All other structures—definition structures,
referral structures, and referral substructures—have a base alignment of two.
A structure is well-aligned if the address of the base of the structure in memory is a
multiple of its base alignment; otherwise, the structure is misaligned. If a structure is
misaligned, some or all of its fields will also be misaligned.
Structure Alignment Examples
The following examples illustrate how your structure data layout is affected by structure
alignment. Only SHARED8 structures are shown because SHARED2 structures are
not well-aligned. pTAL always generates conservative code for references to fields of a
SHARED2 structure that are more than 16 bits long.
Figure 9-1 on page 9-10 shows a structure, s1, that specifies
FIELDALIGN(SHARED8). Because the widest field in the structure, f, is a FIXED field,
the base alignment of s1 is 8. To be well-aligned, s1 must be allocated at a memory
address that is an integral multiple of eight. Filler is added as follows:
•
•
•
Before i32 so that i32 begins at an offset that is a multiple of four relative to the
beginning of the structure.
Before f so that f begins at an offset that is a multiple of eight relative to the
beginning of the structure.
At the end of the structure so that the total length of the structure is an integral
multiple of the widest field in the structure.
HP pTAL Reference Manual—523746-006
9 -9
Structure Alignment Examples
Structures
Figure 9-1. Alignment of SHARED8 Structure With Base Alignment of 8
STRUCT s FIELDALIGN(SHARED8); ! Base alignment of s1 is 8
BEGIN
INT
i;
! Begins at offset 0
FILLER 2;
! 2 bytes of filler required
INT(32) i32; ! Begins at offset 4
STRING s1;
! Begins at offset 8
STRING s2;
! Begins at offset 9
FILLER 6;
! 6 bytes of filler required
FIXED
f;
! Begins at offset 16
INT
k;
! Begins at offset 24
FILLER 6;
! Must pad to multiple of widest field, f
END;
! Total length of s1: 32 bytes
i
0
i32
filler
2
4
6
s1 s2
8
10
f
filler
12
14
16
18
k
20
22
24
filler
26
28
30
Filler required to align next field,
i32, on a 4-byte boundary.
Filler required to align next field,
f, on an 8-byte boundary.
Filler required to make length of
the structure an integral multiple
of its widest field, f.
VST007.vsd
Figure 9-2 on page 9-11 shows which fields of s1 are misaligned if the base of the
structure in memory is not at an integral multiple of its base alignment. Only structures
whose base is at an even-byte address are shown. Accessing structures whose base
is at an odd-byte offset produces undefined results. For more information, see
Overview of Structure Alignment on page 9-4.
HP pTAL Reference Manual—523746-006
9- 10
Structure Alignment Examples
Structures
Figure 9-2. Well-Aligned and Misaligned SHARED8 Structures With Base
Alignment of 8
i
0
filler
2
i32
4
s1 s2
8
6
filler
10
f
12
14
16
18
k
20
22
24
filler
26
28
30
Misaligned fields: none
i
0
2
filler
4
i32
s1 s2
8
6
10
filler
12
f
14
16
14
16
18
20
22
18
20
22
k
24
filler
26
28
26
28
30
Misaligned fields: i32, f
i
0
2
4
filler
i32
8
6
10
s1 s2
12
filler
f
24
k
filler
30
Misaligned fields: f
i
0
2
4
6
filler
8
i32
10
12
s1 s2
14
filler
16
18
k
f
20
22
24
26
28
30
28
30
Misaligned fields: i32, f
i
0
2
4
6
8
filler
10
i32
12
14
s1 s2
16
filler
18
20
f
22
24
26
Misaligned fields: none
VST009.vsd
HP pTAL Reference Manual—523746-006
9- 11
Structure Alignment Examples
Structures
Figure 9-3 on page 9-12 shows a structure that is declared FIELDALIGN(SHARED8).
The widest fields in s2, i32a and i32b, are each four bytes; therefore, although the
field alignment of s2 is SHARED8, the base alignment of s2 is four, not eight. s2 is
well-aligned in memory if the base of the structure begins at any address that is a
multiple of four.
Figure 9-3. Alignment of a SHARED8 Structure With Base Alignment of 4
STRUCT s2
BEGIN
STRING
FILLER
INT(32)
STRING
STRING
FILLER
INT(32)
INT
FILLER
END;
s1
filler
0
2
FIELDALIGN(SHARED8);
s1
3;
i32a;
s2
s3
2;
i32b;
k;
2;
i32a
4
6
!
!
!
!
!
!
!
!
!
!
Begins at offset 0
3 bytes of filler required
Begins at offest 4
Begins at offset 8
Begins at offset 9
2 bytes of filler required
Begins at offest 12
Begins at offest 16
Must pad to multiple of base alignment
Total length of s2: 20 bytes
s2 s3 filler
8
! Base alignment is 4
10
i32b
12
14
k
16
filler
18
20
Filler required to align next field,
i32a, on a 4-byte boundary.
Filler required to align next field,
i32b, on a 4-byte boundary.
Filler required to make length of
the structure an integral multiple
of its widest field, i32a and i32b.
VST997.vsd
HP pTAL Reference Manual—523746-006
9- 12
Array Alignment in Structures
Structures
Figure 9-4 on page 9-13 shows which fields are misaligned if s2 is allocated at an
address other than a 4-byte address.
Figure 9-4. Well-Aligned and Misaligned SHARED8 Structures With Base
Alignment of 4
s1
0
filler
2
i32a
4
s2 s3 filler
8
6
10
i32b
12
k
14
16
filler
18
20
22
24
26
28
30
filler
20
22
24
26
28
30
24
26
28
30
Misaligned fields: none
s1
0
2
filler
4
i32a
6
8
s2 s3 filler
10
12
i32b
14
16
k
18
Misaligned fields: i32a, i32b
s1
0
2
4
filler
6
i32a
8
10
s2 s3 filler
12
14
i32b
16
18
k
20
filler
22
Misaligned fields: none
VST114.vsd
Array Alignment in Structures
When you declare an array in a structure, the alignment of the beginning of the array is
the alignment of the base type of the array. Thus, for example, the field alignment of an
array of INTs is the same as the field alignment of a single INT, which is 2. Declaring an
array in a structure is the same as explicitly declaring individual fields, each with the
same data type as the array’s base type.
In Example 9-1 on page 9-13, the layouts and base alignments of s1 and s2 are
identical:
Example 9-1. Arrays Within Structures (page 1 of 2)
STRUCT s1 FIELDALIGN(SHARED8);
BEGIN
INT i;
INT a[0:2];
STRUCT s1[0:1];
BEGIN
INT(32)w;
INT y;
INT x;
END;
END;
HP pTAL Reference Manual—523746-006
9- 13
Array Alignment in Structures
Structures
Example 9-1. Arrays Within Structures (page 2 of 2)
STRUCT s2 FIELDALIGN(SHARED8);
BEGIN
INT i;
INT a;
INT b;
INT c;
STRUCT s1a;
BEGIN
INT(32)w;
INT y;
INT x;
END;
STRUCT s1b;
BEGIN
INT(32)w;
INT y;
INT x;
END;
END;
An array of structures or substructures is the same as an array of a pTAL data type.
The width of the widest field of an element of such an array, combined with the
FIELDALIGN parameter you specify, determines the required alignment of the
structure or substructure and of its fields.
Example 9-2. SHARED2: 2-Byte Alignment
STRUCT s1[0:9] FIELDALIGN(SHARED2);
BEGIN
INT
i;
FILLER 2;
INT(32)
j;
END;
! s1 is SHARED2
! Alignment is 2
Example 9-3. SHARED8: 4-Byte Alignment
STRUCT s2[0:9] FIELDALIGN(SHARED8);
BEGIN
INT
i;
FILLER 2;
INT(32)
j;
END;
! s2 is SHARED8
! Alignment is 4
HP pTAL Reference Manual—523746-006
9- 14
Structure Alignment
Structures
Example 9-4. 8-Byte Alignment and 4-Byte Alignment
STRUCT s3[0:9] FIELDALIGN(SHARED8);
BEGIN
STRUCT s4[0:4];
BEGIN
INT
i;
FILLER 2;
INT(32)
j;
END;
REAL(64)
END;
!
!
!
!
s3 is SHARED8
Alignment is 8
s4 is SHARED8
Alignment is 4
k;
Structure Alignment
A structure’s alignment is the alignment of the widest field declared in the structure and
is always less than or equal to the alignment specified in a FIELDALIGN clause or
FIELDALIGN compiler directive. For alignment values of structure fields, see Table 9-3
on page 9-9. The alignment of a field that is a substructure is the alignment of the
widest field contained in the substructure.
If the alignment of the widest field in a SHARED8 structure is 2, the structure must
begin at a 2-byte address, and the structure’s base alignment is 2. If the alignment of
the widest field in the structure is four bytes, for example an INT(32), the structure
must begin at a 4-byte address. If the alignment of the widest field in the structure is
eight bytes, for example an FIXED field, the structure must begin at an 8-byte address.
Example 9-5. SHARED8 Structures With Different Base Alignments
STRUCT s1 FIELDALIGN(SHARED8);
BEGIN
STRING a;
STRING b;
INT
c;
END;
! Base alignment of structure is
! 2 because of INT c
STRUCT s2
BEGIN
STRING
STRING
FILLER
INT(32)
END;
! Base alignment of structure is
! 4 because of INT(32) c
FIELDALIGN(SHARED8);
a;
b;
2;
c;
! c is field with widest
! alignment: 2
! c is field with widest
! alignment: 4
STRUCT s3 FIELDALIGN(SHARED8);
BEGIN
STRING a;
STRING b;
FILLER 6;
FIXED c;
END;
! Base alignment of structure is
! 8 because of FIXED c
! c is field with widest
! alignment: 8
HP pTAL Reference Manual—523746-006
9- 15
Substructure Alignment
Structures
Substructure Alignment
The rules for field alignment of substructures are the same as the rules for structures.
You can specify the field alignment of a substructure explicitly using a FIELDALIGN
clause or implicitly by allowing the field alignment of the substructure to default to the
field alignment of the containing structure or substructure. In either case, the alignment
of fields must conform to the rules described previously, under “Using Field Alignment.”
For SHARED8 structures, you must ensure that every field begins at an appropriate
address and that the end of the structure includes filler, if necessary, so that the total
length of the substructure is an integral multiple of its widest field.
The following rules apply to substructures:
•
•
•
A definition substructure that does not specify a FIELDALIGN clause inherits the
field alignment of its containing structure or substructure.
The base alignment of a substructure is the alignment of the widest field of the
substructure.
Begin the base of a substructure at an offset that is an integral multiple of the
substructure’s alignment, relative to the start of its containing structure or
substructure. If the substructure is a definition substructure and both the structure
and substructure have SHARED8 field alignment, the substructure must be well
aligned.
Example 9-6. Well-Aligned Structure With Well-Aligned Substructure
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2;
! ss is 4-byte aligned. Use FILLER 2 to
! force ss to a 4-byte address
STRUCT ss;
BEGIN
INT(32) m;
INT n;
FILLER 2;
END;
INT j;
STRING t[0:2];
FILLER 3;
END;
! Specified alignment of ss is SHARED8,
! inherited from s
! Alignment of substructure ss is 4
! FILLER 2 makes total length of ss 8
! Alignment of structure s is 4: declare
! FILLER 3 to make length of s an integral
! multiple of its widest field
For further information about substructures, see Alignment Considerations for
Substructures on page 9-19.
HP pTAL Reference Manual—523746-006
9- 16
Substructure Alignment
Structures
Example 9-7. SHARED8 Structures With SHARED2 Substructures
STRUCT t_s2(*) FIELDALIGN(SHARED2);
BEGIN
INT(32) j;
END;
! Base alignment of t_s2
! is 2
STRUCT t_s8(*) FIELDALIGN(SHARED8);
BEGIN
INT(32) j;
END;
! Base alignment of t_s8
! is 4
Example 9-8. SHARED2 Structures With SHARED8 Substructure
STRUCT s1 FIELDALIGN(SHARED2);
BEGIN
INT i;
STRUCT s2(t_s8);
! s2 has SHARED8 alignment
END;
! Base alignment of s2 is 2
INT .p2(t_s8) REFALIGNED(2);
INT .p3(t_s8);
! Reference alignment is 2
! Reference alignment defaults
! to 8
PROC p;
BEGIN
INT i;
@p2 := @s1.s2 '>>' 1;
@p3 := @s1.s2 '>>' 1;
i := p2.j;
i := p3.j;
...
END;
In Example 9-8 on page 9-17:
•
•
•
Because s1 specifies SHARED2 field alignment, pTAL generates conservative
code that ensures that an exception does not occur when you reference s1.s2.j.
p2 refers to t_s8, a SHARED8 substructure. p2 specifies a reference alignment of
2, which ensures that pTAL generates conservative code that will not cause
exceptions for misaligned memory references.
p3 does not have a REFALIGNED clause. Its reference alignment, therefore,
defaults to the field alignment of its referent, which is t_s8, which has SHARED8
field alignment. pTAL generates fast code for each reference to p3.j.
In the formal parameter specification for a structure pointer, declare reference
alignment 2 unless you are certain that all pointers passed to the parameter reference
SHARED8 structures that you know are well-aligned. If you are not certain that all
references are well-aligned, use the same approach as that shown earlier to ensure
that references to structures passed as actual parameters do not cause a trap.
HP pTAL Reference Manual—523746-006
9- 17
Substructure Alignment
Structures
When you design routines that return addresses to their callers, return addresses that
are well-aligned whenever possible.
Example 9-9. SHARED8 Structure With SHARED2 Substructure
STRUCT s3 FIELDALIGN(SHARED8);
BEGIN
! Base alignment of s3 is 4
INT i;
STRUCT s4(t_s2); ! s2 has SHARED8 alignment
END;
! Base alignment of s2 is 4
INT .p4(t_s2);
! Uses default alignment: 2
The compiler always generates conservative code. In Example 9-9 on page 9-18,
references to s3.s4.j do not cause traps because, although s3 is SHARED8, the
offset of s3.s4.j is not a multiple of 4. For each reference pTAL determines whether
the referenced field is well-aligned. References to fields in s4 using the pointer p4—for
example, p4.j—do not cause traps because the field alignment of s4 is SHARED2
and the compiler generates conservative code for such references.
Example 9-10. Combining SHARED2 and SHARED8 Structures
PROC p;
BEGIN
STRUCT s1 FIELDALIGN(SHARED8);
BEGIN
FIXED i;
END;
STRUCT s2 FIELDALIGN(SHARED2);
BEGININT(32) i;
STRUCT sub (s1);
END;
! OK
! OK
! OK
! WARNING: SHARED8
! substructure in SHARED2
! structure can cause
! significant loss of
! performance
STRUCT s3 (s1) = s2;
STRUCT s4 FIELDALIGN(SHARED8);
BEGIN
INT i;
STRUCT sub1 (s2);
! OK: SHARED2
STRUCT sub2 (s1) = sub1; ! WARNING: SHARED8 substructure
FILLER 2;
! redefines SHARED2 substructure
END;
! can cause significant loss of
END;
! performance
HP pTAL Reference Manual—523746-006
9- 18
Alignment Considerations for Substructures
Structures
Alignment Considerations for Substructures
When you declare a substructure, you must be aware of how the base alignment of the
substructure and its containing structure affect references to the fields of the structure
and substructure.
Table 9-4. Field Alignment of Substructures
Structure Field Alignment
Substructure
Field Alignment
AUTO
PLATFORM
SHARED8
SHARED2
AUTO
AUTO
PLATFORM
Invalid
Invalid
PLATFORM
invalid
PLATFORM
invalid
invalid
SHARED8
SHARED8
SHARED8
SHARED8
SHARED8
SHARED2
SHARED2
SHARED2
SHARED2
SHARED2
Default
AUTO
PLATFORM
SHARED8
SHARED2
If a SHARED8 substructure is contained in a SHARED2 structure (or in an AUTO
structure), fields in the SHARED8 substructure will be well-aligned with respect to the
base of the SHARED8 substructure but might not be well-aligned with respect to the
base of the SHARED2 structure. Performance will be somewhat degraded when fields
in the substructure are referenced.
If a SHARED2 substructure is contained in a SHARED8 structure (or in an AUTO
structure), fields in the SHARED2 substructure will be well-aligned with respect to the
base of the SHARED2 substructure but might not be well-aligned with respect to the
base of the SHARED8 structure. Performance will be significantly degraded when
fields in the substructure are not well-aligned for SHARED8 access. Each such
reference will cause a trap to the millicode exception handler to resolve the reference.
Your program will behave correctly but will be significantly slower than it would without
the trap.
Example 9-11. AUTO Field Alignment in Structure (Error)
STRUCT s FIELDALIGN(SHARED8);
BEGIN
STRUCT s1 FIELDALIGN(AUTO);
BEGIN
...
END;
END;
! ERROR: Substructure cannot be
! FIELDALIGN(AUTO)
The compiler pads SHARED2 structures and substructures with an extra byte if the
end of the last field in the structure or substructure ends at an odd-byte address,
unless the structure has 1-byte alignment—that is, all fields in the structure or
substructure are STRINGs or UNSIGNED(1-8).
STRING fields in structures can begin at any byte offset.
HP pTAL Reference Manual—523746-006
9- 19
FIELDALIGN Clause
Structures
FIELDALIGN Clause
You use a FIELDALIGN clause in a structure declaration to specify how you want pTAL
to align the fields in the structure. Fields can be aligned for:
Access
FIELDALIGN Clause
Exclusive, optimized for best resource utilization on each
architecture
FIELDALIGN(AUTO)
Shared between pTAL and TAL programs
FIELDALIGN(SHARED2)
Shared by program modules written in different programming
languages and running on the same architecture
FIELDALIGN(PLATFORM)
Shared between TNS, TNS/R, and TNS/E architecture with
optimal performance on TNS/R and TNS/E architecture
FIELDALIGN(SHARED8)
FIELDALIGN Compiler Directive
As with the FIELDALIGN clause, the parameters to the FIELDALIGN compiler directive
include SHARED2, SHARED8, PLATFORM, and AUTO. In addition, you can specify
NODEFAULT as the parameter to the FIELDALIGN compiler directive.
You can specify only one FIELDALIGN directive within a compilation, and it must
precede all data, block, and procedure declarations. Only comments, blank lines, and
other directives can precede a FIELDALIGN directive.
The default value of the FIELDALIGN directive is AUTO.
If you specify the FIELDALIGN (NODEFAULT) compiler directive, pTAL requires you to
specify a FIELDALIGN clause on every structure declaration. You might use the
FIELDALIGN (NODEFAULT) directive to ensure that you do not inadvertently omit a
FIELDALIGN clause on any structure.
If you do not specify a FIELDALIGN (NODEFAULT) directive, pTAL does not require
you to specify a FIELDALIGN clause on each structure declaration.
SHARED2 Parameter
Since the SHARED2 parameter is included with both the FIELDALIGN clause and the
FIELDALIGN compiler directive, the following information relates to both usages:
•
In a SHARED2 structure, all fields must begin at an even-byte address except
STRING fields, which can begin at any byte address, and UNSIGNED fields, which
can begin at any bit address except as follows:
°
°
°
An UNSIGNED(1-16) field cannot cross an even-byte address boundary.
An UNSIGNED(17-31) field can cross only one even-byte address boundary.
An UNSIGNED field that is not preceded by an UNSIGNED field must begin at
an even-byte address.
HP pTAL Reference Manual—523746-006
9- 20
SHARED2 Parameter
Structures
•
The address type of pointers in a SHARED2 structure must be EXTADDR,
SGBADDR, or SGWADDR; for example:
STRUCT s FIELDALIGN(SHARED2);
BEGIN
INT .EXT i; ! OK: EXTADDR pointer
INT .SG j;
! OK: SGWADDR pointer
STRING .s;
! ERROR: BADDR pointer is not valid
END;
•
If the data type of a field in a SHARED2 structure is an address type, the type must
be EXTADDR, SGBADDR, or SGWADDR; for example:
STRUCT s FIELDALIGN(SHARED2);
BEGIN
EXTADDR x; ! OK: EXTADDR field
WADDR
w; ! ERROR: WADDR field is not valid
END;
•
If you include a FIELDALIGN(SHARED2) compiler directive, include a
REFALIGNED(2) compiler directive as well. The default for the REFALIGNED
compiler directive is 8. With field alignment SHARED2, pTAL can allocate a 32-bit
or 64-bit field at any even-byte address. pTAL generates optimal code for data
references that use a pointer whose reference alignment is 8. If the pointer is used
to reference 32-bit or 64-bit data that is not well-aligned, each reference to the data
will be slow. By default, pTAL generates conservative code when you reference
data using a pointer that specifies REFALIGNED(2). The REFALIGNED(2)
directive ensures that pTAL generates conservative code for pointers that do not
specify a REFALIGNED clause.
Example 9-12. FIELDALIGN(SHARED2) and REFALIGNED(2) Directives
?FIELDALIGN(SHARED2)
?REFALIGNED(2)
INT(32).ptr;
PROC p;
BEGIN
@ptr :=
...
END;
:=
@str.F32;
ptr
+
3D;
! Global pointer
! str.F32 might or might not be aligned
! at a 32-bit address. REFALIGNED
! directive ensures that pTAL
! generates conservative code for
! references to ptr.
HP pTAL Reference Manual—523746-006
9- 21
SHARED8 Parameter
Structures
Example 9-13. Byte Offsets (Decimal) of Fields of a SHARED2 Structure
STRUCT s1 FIELDALIGN(SHARED2);
BEGIN
INT
i;
! i begins at byte offset:
INT(32)
j;
! j begins at byte offset:
STRING
s1; ! s1 begins at byte offset:
UNSIGNED(3) u1; ! u1 begins at byte offset:
UNSIGNED(2) u2; ! u2 begins at byte offset:
STRING
s2; ! s2 begins at byte offset:
FIXED
f;
! f begins at byte offset:
INT
k;
! k begins at byte offset:
END;
0
2
6
8
8 + 3 bits
10
12
20
SHARED8 Parameter
Since the SHARED8 parameter is included with both the FIELDALIGN clause and the
FIELDALIGN compiler directive, the following information relates to both usages:
•
•
The structure must begin at an address that is an integral multiple of the width of
the widest field in the structure. Thus:
°
°
A 1-byte field (STRING) can begin at any byte address.
°
The byte offset of a 4-byte field [INT(32), REAL, UNSIGNED(17-31)] must be
an integral multiple of four, except that contiguous UNSIGNED fields can be
packed.
°
The byte offset of an 8-byte field [FIXED or REAL(64] must be an integral
multiple of eight.
°
The byte offset of a substructure field must be an integral multiple of the widest
field in the substructure.
°
The byte offset of an array must be an integral multiple of an element of the
array—that is, one of the previous items in this list.
The byte offset of a 2-byte field [INT or UNSIGNED(1-16)] must be an even
number, except that contiguous UNSIGNED fields can be packed.
In a SHARED8 structure or substructure, you must explicitly declare filler items as
needed to ensure that fields are aligned according to the preceding rules.
Table 9-5. Variable Alignment (page 1 of 2)
Data Type
Alignment
STRING
1
INT
2
Notes
* In pTAL, the alignment of all address types is 4, except SGBADDR and SGWADDR addresses for which the
alignment is 2. In TAL, the alignment of all address types is 2.
** The alignment of an array is the alignment of its element type.
HP pTAL Reference Manual—523746-006
9- 22
SHARED8 Parameter
Structures
Table 9-5. Variable Alignment (page 2 of 2)
Data Type
Alignment
Notes
UNSIGNED(1-16)
2
Multiple UNSIGNED fields can be packed in a word
or doubleword.
.SG pointers
2
.SG pointers are 16 bits in both pTAL and TAL.*
.SGX pointers
4
Allowed in structures only with AUTO field
alignment.**
Other 16-bit pointers
4
Allowed in structures only with AUTO field
alignment.**
32-bit Pointer
4
INT(32)
4
REAL
4
UNSIGNED(17-31)
4
FIXED
8
REAL(64)
8
Multiple UNSIGNED fields can be packed into a
doubleword.
* In pTAL, the alignment of all address types is 4, except SGBADDR and SGWADDR addresses for which the
alignment is 2. In TAL, the alignment of all address types is 2.
** The alignment of an array is the alignment of its element type.
•
•
For compatibility with TAL, pTAL requires you to explicitly declare filler items to
optimally align a SHARED8 structure’s fields for RISC and Itanium architecture.
pTAL does not add filler automatically to SHARED8 structures and reports a syntax
error if you do not declare filler where a structure requires it. The compiler listing
shows where each structure requires filler. You must add filler:
°
Before a field if the field’s offset from the beginning of the structure is not an
integral multiple of the field’s width (see Table 9-3 on page 9-9)
°
If the total length of the structure or substructure would not be an integral
multiple of the structure or substructure’s widest field
°
°
If an UNSIGNED(1-16) field would otherwise cross an even byte address
If an UNSIGNED(17-31) field would otherwise cross a four byte address
The address type of pointers in a SHARED8 structure must be EXTADDR,
SGBADDR, or SGWADDR.
HP pTAL Reference Manual—523746-006
9- 23
Alignment of Fields
Structures
•
If the data type of a field in a SHARED8 structure is an address type, the type must
be EXTADDR, SGBADDR, or SGWADDR, as shown in the following example:
STRUCT s FIELDALIGN(SHARED8);
BEGIN
EXTADDR x; ! OK: EXTADDR field
INT.EXT i; ! OK: EXTADDR pointer
INT.SG j;
! OK: SGWADDR pointer
STRING.s;
! ERROR: BADDR pointer is not valid
END;
Topics:
•
•
•
•
Alignment of Fields on page 9-24
Optimizing Structure Layouts on page 9-24
Structure Length on page 9-26
Alignment of UNSIGNED(17-31) Fields on page 9-27
Alignment of Fields
If a field in a SHARED8 structure is not well-aligned, you must explicitly declare filler to
force the field to be well-aligned.
Example 9-14. Filler Forcing Alignment in a SHARED8 Structure
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT
a;
! 0 a uses 2 bytes
FILLER 2;
! 2 Force b to a 4-byte offset
INT(32)
b;
! 4 b uses 4 bytes
STRING
c [0:2]; ! 8 c uses 3 bytes
FILLER 5;
! 11 Force d to an 8-byte offset
FIXED
d;
! 16 d uses 8 bytes
INT(32)
e[0:1];
! 24 e uses 8 bytes
INT
f;
! 32 f uses 2 bytes
UNSIGNED(5) g;
! 34 g uses 5 bits
BIT_FILLER 11;
! Force h to a 4-byte offset
UNSIGNED(17) h;
! 36 h uses 2 bytes plus 1 bit
UNSIGNED(15) i;
! 38 i uses 15 bits
END;
! Total structure length: 40 bytes
The first filler item (FILLER 2) forces b to begin at a 4-byte address. The second filler
item (FILLER 5) forces d to begin at an 8-byte address. The third filler item
(BIT_FILLER 11) forces h to begin at a 4-byte address.
Optimizing Structure Layouts
You do not need to declare filler items in a SHARED2 structure to align its fields. If filler
is needed—for example to align bit fields, string fields, or fields that follow bit fields and
string fields—the compiler inserts the needed filler.
HP pTAL Reference Manual—523746-006
9- 24
Optimizing Structure Layouts
Structures
Example 9-15. Structure With SHARED2 Field Alignment
STRUCT s1 FIELDALIGN(SHARED2);
BEGIN
INT
i; ! i begins at offset: 0
INT(32) j; ! j begins at offset: 2
STRING s1; ! s1 begins at offset: 6
STRING s2; ! s1 begins at offset: 7
FIXED
f; ! f begins at offset: 8
INT
k; ! k begins at offset: 16
END;
! Total length of s1: 18 bytes
Structures that specify SHARED8 field alignment, however, require you to explicitly
declare filler items to force fields to be well-aligned, as previously described. You might
be able to reduce the size of a structure if you can arrange its fields to minimize the
number of filler items required.
In Example 9-16 on page 9-25, the structure s2 has the same fields as s1 in
Example 9-15 on page 9-25, but s2 has SHARED8 field alignment and includes filler
items where required. Offsets are shown in bytes. s2 is 32 bytes.
Example 9-16. Structure With SHARED8 Field Alignment
STRUCT s2 FIELDALIGN(SHARED8);
BEGIN
INT
i; ! i begins at offset 0
FILLER 2; ! 2 bytes of filler
INT(32) j; ! j begins at offset 4
STRING s1; ! s1 begins at offset 8
STRING s2; ! s2 begins at offset 9
FILLER 6; ! 6 bytes of filler
FIXED
f; ! f begins at offset 16
INT
k; ! k begins at offset 24
FILLER 6; ! Pad to a multiple of the widest field (f)
END;
! Total length of s2: 2 bytes
s2 has SHARED8 field alignment, and uses 14 more bytes than s1. If the order of the
fields within the structure is not important; however, you can rearrange the fields so
that the structure contains fewer bytes, as shown in Example 9-17 on page 9-25.
Example 9-17. Optimized Structure With SHARED8 Field Alignment
STRUCT s3 FIELDALIGN(SHARED8);
BEGIN
INT
i; ! i begins at offset 0
STRING s1; ! s1 begins at offset 2
STRING s2; ! s2 begins at offset 3
INT(32) j; ! j begins at offset 4
FIXED
f; ! f begins at offset 8
INT
k; ! k begins at offset 16
FILLER 6; ! Pad to a multiple of the widest field (f)
END;
! Total length of s3: 24 bytes
HP pTAL Reference Manual—523746-006
9- 25
Structure Length
Structures
By rearranging the order of the fields, s3 requires 24 bytes, rather than the 32 bytes
required by s2, even though the information in s3 and s2 is the same. s3 uses only
six more bytes than s1.
Structure Length
The total number of bytes in a SHARED8 structure must be an integral multiple of the
widest field in the structure. If needed, you must explicitly declare filler at the end of a
SHARED8 structure to ensure this condition.
Example 9-18. Structures That Need Filler
STRUCT s1
BEGIN
FIXED
INT(32)
FILLER
END;
FIELDALIGN(SHARED8);
STRUCT s2
BEGIN
INT(32)
INT
FILLER
END;
FIELDALIGN(SHARED8);
i;
j;
4;
i;
j;
2;
! Structure's widest field is 8 bytes
! j is 4 bytes FILLER 4
! Pad with 4 bytes
! Structure's widest field is 4 bytes
! j is 2 bytes
! Pad with 2 bytes
UNSIGNED(1-16) fields cannot cross an even-byte address.
Example 9-19. Structure Field Crossing an Even-Byte Address (Error)
STRUCT s FIELDALIGN(SHARED8);
BEGIN
UNSIGNED(10) u1;
UNSIGNED(16) u2; ! Invalid field -- crosses even-byte address
END;
In Example 9-20 on page 9-26, u1 starts at the beginning of the structure. u2,
therefore, would begin at a 10-bit offset from the beginning of s. Because u2 is 16 bits,
the last ten bits of u2 would be allocated in a second word, which would cause u2 to
cross an even-byte address; therefore, you must explicitly declare filler to force u2 to
begin at the next even-byte offset from the beginning of s.
Example 9-20. Structure That Needs Filler
STRUCT s FIELDALIGN(SHARED8);
BEGIN
UNSIGNED(10) u1;
BIT_FILLER 6;
! Forces u2 to begin at next even-byte
! address
UNSIGNED(16) u2;
END;
HP pTAL Reference Manual—523746-006
9- 26
Alignment of UNSIGNED(17-31) Fields
Structures
Alignment of UNSIGNED(17-31) Fields
In a SHARED8 structure, UNSIGNED(17-31) fields cannot cross a 4-byte address.
Because an UNSIGNED(17-31) field is longer than 16 bits, its base alignment is 4
bytes.
In Example 9-21 on page 9-27, i starts at the beginning of the structure. u, therefore,
begins at an even-byte offset from the beginning of s. Because u is 28 bits, the last 12
bits of u would be allocated in the next word, which would cause u to cross a 4-byte
address.
Example 9-21. SHARED8 Structure With Misaligned UNSIGNED Fields
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT i;
UNSIGNED(28) u; ! Invalid field
END;
You must explicitly declare filler to force u to begin at the next 4-byte offset from the
beginning of s.
Example 9-22. SHARED8 Structure With Correctly Aligned UNSIGNED Fields
STRUCT s FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2;
! Forces u to begin at a 4-byte address
UNSIGNED(28) u;
BIT_FILLER 4;
! Makes length of s an integral multiple of
END;
! 4 bytes
Reference Alignment With Structure Pointers
When you declare a structure pointer, you can specify a REFALIGNED clause as part
of the declaration. (For the syntax of a structure pointer, see Section 11, Equivalenced
Variables.) You can use a REFALIGNED clause to override the base alignment of an
instance of a structure, even though the field alignment for the structure does not
change. For example, if you specify a REFALIGNED(2) clause on a structure pointer,
pTAL generates conservative code each time you use the pointer to reference fields of
the structure.
A REFALIGNED clause specifies the base alignment of the structures that the
structure pointer will reference. The distinction between FIELDALIGN and
REFALIGNED is required because structures referenced by a structure pointer can be
located anywhere in memory, and might not be well-aligned. A structure might not be
well-aligned if it is located in a dynamic memory area such as a heap, or was read from
a file as part of a larger record.
HP pTAL Reference Manual—523746-006
9- 27
REFALIGNED Clause
Structures
The alignment of a structure pointer is the alignment specified in a REFALIGNED
clause if present, or if not present, by the field alignment of the structure it references.
The REFALIGNED compiler directive does not affect the reference alignment of
structure pointers. It is used only for pointers to nonstructure data.
You can specify the REFALIGNED clause on any pointer field. In Example 9-23 on
page 9-28, field d is a 32-bit pointer in pTAL and is valid only if the field alignment of
structure s is AUTO or PLATFORM.
Example 9-23. REFALIGNED Clause With Structure Pointers
STRUCT s;
BEGIN
INT .d REFALIGNED(2);
INT. EXT e REFALIGNED(8);
END;
! Standard pointer with REFALIGNED
! clause
! An extended pointer
The same syntax and semantics of fields and pointer fields declared with a
REFALIGNED clause is the same as that of variables and pointers declared with a
REFALIGNED clause, respectively.
Topics:
•
•
•
•
•
REFALIGNED Clause on page 9-28
Default Reference Alignment on page 9-29
REFALIGNED(2) on page 9-29
REFALIGNED(8) on page 9-31
Code Generation for Structure References on page 9-32
REFALIGNED Clause
In a SHARED2 or SHARED8 structure, you can include only pointers whose address
type is SGBADDR, SGWADDR, or EXTADDR. Pointers whose address type is any
other type are 16 bits in TAL, but 32 bits in pTAL.
Similarly, if the data type of a nonpointer field in a SHARED2 and SHARED8 structure
is an address type, its type must be SGBADDR, SGWADDR, or EXTADDR.
Example 9-24. REFALIGNED Clause
STRUCT s FIELDALIGN(SHARED2);
BEGIN
INT
i; ! OK: i is a simple variable
INT .j; ! ERROR: j's address type is WADDR
BADDR b; ! ERROR: b's data type is BADDR
END;
HP pTAL Reference Manual—523746-006
9- 28
Default Reference Alignment
Structures
Default Reference Alignment
If you do not specify a REFALIGNED clause in a structure pointer declaration, the
reference alignment for the pointer is the alignment of the structure that the pointer
references in its declaration. In Example 9-25 on page 9-29, none of the pointers p1,
p2, or p3 specifies an alignment. Their alignment, therefore, is the field alignment of
the structures s1, s2, and s3 that they reference.
Example 9-25. Default Reference Alignment
STRUCT s1 FIELDALIGN(SHARED2);
BEGIN
INT i;
INT(32) j;
END;
STRUCT s2 FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2;
INT(32) j;
END;
STRUCT s3 FIELDALIGN(AUTO);
BEGIN
INT i;
INT(32) j;
END;
INT .p1(s1);
INT .p2(s2);
INT .p3(s3);
! Reference alignment is 2
! Reference alignment is 8
! Reference alignment is 8
REFALIGNED(2)
When a structure pointer specifies REFALIGNED(2), the base of the structure might or
might not be well-aligned for RISC and Itanium access. When you reference the
pointer in an expression, pTAL generates conservative code that might not be as
optimal as the code it generates when you specify REFALIGNED(8).
When you use a structure pointer in an executable statement, the field to which the
pointer refers might not be well-aligned. For example, if you are accessing a structure
whose address was passed as a parameter to a procedure, you might not know
whether the field is well-aligned. Although the fields of the structure are well-aligned
from the base of the structure, the base of the structure might not be well-aligned in
memory.
Similarly, if you reference a field in a structure that is stored at an arbitrary address on
a heap, you might not know in advance whether the fields in the structure are well
aligned.
HP pTAL Reference Manual—523746-006
9- 29
REFALIGNED(2)
Structures
To ensure good performance, use REFALIGNED(2) to access the field, even if it
happens to be well-aligned. Always use REFALIGNED(2) unless you are certain that
nearly all fields referenced by the pointer are well-aligned.
Example 9-26. REFALIGNED(2)
WADDR a_str;
STRUCT s_templ(*) FIELDALIGN(SHARED8);
BEGIN
INT i;
FILLER 2;
INT(32) j;
END;
STRUCT s(s_templ);
PROC p(struct_addr, p1);
WADDR
struct_addr;
INT
.p1(s_templ); ! Use template for structure definition
BEGIN
INT .p2(s);
! Reference compiler-allocated structure with
! SHARED8 alignment
INT .p3(s_templ) REFALIGNED(2) = p2;
! Equivalence p3 to p2
INT .p4(s_templ) REFALIGNED(2) := struct_addr;
! Use template but use address passed as parameter
INT .p5(s_templ) REFALIGNED(2) := a_str;
! Use template but address stored in globals
@p2 := @s;
! Ensure p2 is well-aligned
a := p1.i;
! Might incur significant overhead if p1.i is not
! well-aligned. See REFALIGNED(8) on page 9-31
a := p2.i;
! Optimal code: p2 references s which is known to
! be well-aligned
a := p3.i;
a := p4.i;
a := p5.i;
END;
! Suboptimal access
! Suboptimal access
! Suboptimal access
The field alignment of s_templ is SHARED8. Pointers p1, p3, p4, and p5 use
s_templ to define the layout of the structures they reference. p2 uses the global
definition structure s to define its layout.
HP pTAL Reference Manual—523746-006
9- 30
REFALIGNED(8)
Structures
The field alignment of s and s_templ is SHARED8. Because the declaration of p1
does not specify a REFALIGNED clause, the statement a := p1.i might cause
performance degradation. See REFALIGNED(8) on page 9-31. The pointers p3, p4,
and p5 specify REFALIGNED(2). Compared to p1, references to p3, p4, and p5 will
have somewhat degraded performance when the fields they reference are wellaligned. When the fields they reference are not well-aligned, references to p1 will have
significantly degraded performance compared p3, p4, or p5.
REFALIGNED(8)
When the reference alignment specified for a structure pointer is 8, the code generated
by pTAL for each reference to the pointer assumes that the base of the structure and
the fields in the structure are well-aligned in memory. If the field alignment of a
structure is SHARED8—or is declared AUTO and the program is compiled by pTAL to
run on RISC and Itanium architecture—and the base of the structure is well-aligned,
references to the pointer will execute with optimal performance in both pTAL and TAL.
If a structure pointer specifies REFALIGNED(8) or inherits its reference alignment from
a SHARED8 structure, but the base of the structure is not well-aligned, your program
might run significantly slower than you anticipate. You will observe significantly
degraded performance if your REFALIGNED(8) pointer references a structure field that
is not, in fact, well-aligned. Each such reference in your program will cause a trap to
the millicode exception handler, which accesses the field your program is referencing
and then returns to your program. Your program’s behavior is not affected by having to
access the field from the exception handler except that its performance for each such
trap is significantly degraded.
pTAL generates conservative code for references to a pointer that specifies
REFALIGNED(8) if it detects that a trap would occur if it generated optimal code.
Example 9-27. REFALIGNED(8)
STRUCT t1 (*) FIELDALIGN(SHARED2);
BEGIN
INT(32) i;
END;
STRUCT t2 (*) FIELDALIGN(SHARED8);
BEGIN
STRUCT s (t1);
INT(32) i;
END;
INT .EXT p1 (t1) REFALIGNED (8) := extended-address;
INT .EXT p2 (t2) REFALIGNED (2) := extended-address;
INT .EXT p3 (t2)
:= extended-address;
INT(32) i32;
i32 := p1.i;
i32 := p2.i;
i32 := p3.s.i;
HP pTAL Reference Manual—523746-006
9- 31
Code Generation for Structure References
Structures
For the assignment i32 := p1.i, pTAL generates fast code to access the field
described by t1 because the declaration of pointer p1 specifies REFALIGNED(8). If
the field is not well-aligned, your program will run significantly slower because each
reference to elements of p1 will trap to the millicode exception handler to resolve each
memory access.
For the assignment i32 := p2.i, pTAL generates conservative code to access the
field described by t2 because the field might not be well-aligned. The compiler might
generate extra instructions to access the field.
For the assignment i32 := p3.s.i, pTAL generates fast code to access the field
because the declaration of p3 does not include a REFALIGNED clause. The reference
alignment therefore defaults to the field alignment of t2, which is SHARED8. Even
though the layout of is based on t2 (which, in turn, incorporates t1, which is
SHARED2), the reference alignment of p3 is 8 because t2 is SHARED8. The access
uses optimal code because, even though substructure s has SHARED2 alignment, its
containing structure has SHARED8 alignment, and pTAL can determine that the offset
of p3.s.i is well-aligned.
Code Generation for Structure References
When pTAL generates code for references to the fields of structures and substructures,
it generates two kinds of code. These are referred to as:
•
•
Fast code
Conservative code
pTAL generates fast code if you reference fields in a structure compiled with
FIELDALIGN(SHARED8). It generates conservative code if you reference fields in a
structure compiled with FIELDALIGN(SHARED2).
STRUCTALIGN (MAXALIGN) Attribute
Note. Use this clause only with the EpTAL compiler. The pTAL compiler reports a syntax error.
The STRUCTALIGN (MAXALIGN) attribute applies only to template structures. If a
template structure has this attribute:
•
•
•
Each definition structure that uses the template structure is aligned on a 16-byte
boundary.
If this template is used within a SHARED8 or PLATFORM structure, the enclosing
structures are also aligned on 16-byte boundaries.
If this template is used within a SHARED8 structure, the EpTAL compiler warns
you that this structure is not compatible with the same SHARED8 structure on the
TNS/R architecture.
Do not use STRUCT(MAXALIGN) within a SHARED2 structure.
HP pTAL Reference Manual—523746-006
9- 32
VOLATILE Attribute
Structures
VOLATILE Attribute
The VOLATILE attribute specifies that the value of this variable must be maintained in
memory, not in a register. Each reference to a VOLATILE data item causes the data
item to be read or written to memory even when code is optimized. Based on the order
of reads and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
You can specify the VOLATILE attribute on any field except a substructure.
The syntax and semantics of VOLATILE fields and VOLATILE pointer fields is the
same as those of VOLATILE variables and pointers, respectively.
Example 9-28. VOLATILE Attribute
STRUCT s;
BEGIN
VOLATILE INT a;
VOLATILE INT .EXT b;
VOLATILE INT .c REFALIGNED(2);
END;
! A simple VOLATILE field
! A VOLATILE extended pointer
! A VOLATILE standard pointer
! with a REFALIGNED clause
Declaring Definition Structures
identifier
STRUCT
.
.EXT
.SG
.SGX
structure-layout
range
;
field-alignment
VST624.vsd
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of the new referral structure.
HP pTAL Reference Manual—523746-006
9- 33
Declaring Definition Structures
Structures
range
lower-bound
[
:
upper-bound
]
VST993.vsd
lower-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth structure occurrence) of the first
structure occurrence you want to allocate. Each occurrence is one copy of the
structure.
upper-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth structure occurrence) of the last
structure occurrence you want to allocate. For a single-occurrence structure,
omit both bounds or specify the same value for both bounds.
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
FIELDALIGN
specifies how you want the compiler to align the base of the structure and
fields in the structure. The offsets of fields in a structure are aligned relative to
the base of the structure.
If a definition substructure does not specify a FIELDALIGN clause, the
contained substructure’s field alignment is the field alignment of its
encompassing structure or substructure.
If you do not specify a FIELDALIGN clause on a structure declaration, pTAL
uses the current value of the FIELDALIGN compiler directive. The default value
of the FIELDALIGN directive is AUTO.
If you specify a FIELDALIGN (NODEFAULT) compiler directive, you must
specify a FIELDALIGN clause on every definition structure and template
structure.
HP pTAL Reference Manual—523746-006
9- 34
Declaring Template Structures
Structures
SHARED2
specifies that the base of the structure and each field in the structure must
begin at an even-byte address except STRING fields.
SHARED8
specifies that the offset of each field in the structure from the base of the
structure must be begin at an address that is an integral multiple of the width of
the field.
AUTO
specifies that the structure and the fields of the structure be aligned according
to the optimal alignment for the architecture on which the program will run (this
is not the same behavior as the AUTO attribute has in the native mode HP C
compiler).
PLATFORM
specifies that the structure and the fields of the structure must begin at
addresses that are consistent across all languages on the same architecture.
structure-layout
is the identifier of a previously declared structure or structure pointer that provides
the structure layout for this structure.
Declaring Template Structures
A template structure declaration describes a structure layout but allocates no space for
it. You use the template layout in subsequent structure, substructure, or structure
pointer declarations.
STRUCT
STRUCTALIGN
identifier
(
(
MAXALIGN
structure-layout
*
)
)
;
field-alignment
VST625.vsd
identifier
is the identifier of the template structure.
HP pTAL Reference Manual—523746-006
9- 35
Declaring Template Structures
Structures
(*)
is the symbol for a template structure.
STRUCTALIGN (MAXALIGN)
causes each definition structure that uses this template to be aligned on a 16-byte
boundary (for more information, see STRUCTALIGN (MAXALIGN) Attribute on
page 9-32).
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
FIELDALIGN
specifies how you want the compiler to align the base of the structure and
fields in the structure. The offsets of fields in a structure are aligned relative to
the base of the structure.
If a definition substructure does not specify a FIELDALIGN clause, the
contained substructure’s field alignment is the field alignment of its
encompassing structure or substructure.
If you do not specify a FIELDALIGN clause on a structure declaration, pTAL
uses the current value of the FIELDALIGN compiler directive. The default value
of the FIELDALIGN directive is AUTO.
If you specify a FIELDALIGN (NODEFAULT) compiler directive, you must
specify a FIELDALIGN clause on every definition structure and template
structure.
SHARED2
specifies that the base of the structure and each field in the structure, except
STRING fields, must begin at an even-byte address.
SHARED8
specifies that the offset of each field in the structure from the base of the
structure must begin at an address that is an integral multiple of the width of
the field.
HP pTAL Reference Manual—523746-006
9- 36
Declaring Template Structures
Structures
AUTO
specifies that the structure and the fields of the structure be aligned according
to the optimal alignment for the architecture on which the program will run (this
is not the same behavior as the AUTO attribute has in the native mode HP C
compiler).
PLATFORM
specifies that the structure and the fields of the structure must begin at
addresses that are consistent across all languages on the same architecture.
A template structure has meaning only when you refer to it in the subsequent
declaration of a referral structure, referral substructure, or structure pointer. The
subsequent declaration allocates space for a structure whose layout is the same as the
template layout.
The declaration in Example 9-29 on page 9-37 associates an identifier with a template
structure layout but allocates no space for it.
Example 9-29. Template Structure Declaration
STRUCT inventory (*);
BEGIN
INT item;
FIXED(2) price;
INT quantity;
END;
! Template structure
! Structure layout
In Example 9-30 on page 9-37:
•
•
•
a and b are template structures. The compiler does not allocate space for them.
a1 and b1 are definition structures, defined using the layouts of template
structures a and b, respectively. The compiler allocates space for a1 and b1.
STRUCTALIGN(MAXALIGN) in template structure a affects the alignment of
definition structures a1 and b1 and causes a warning (see the comments in the
code).
Example 9-30. Template Structure With STRUCTALIGN(MAXALIGN) (page 1 of 2)
STRUCT A (*) STRUCTALIGN (MAXALIGN) FIELDALIGN (SHARED8);
BEGIN
INT
I;
! Located at byte-offset 0 as defined by SHARED8
FILLER 2;
INT(32) J;
! Located at byte-offset 3 as defined by SHARED8
END;
STRUCT A1 (A);
! Base of A1 is guaranteed to be aligned on a
! 16-byte boundary
HP pTAL Reference Manual—523746-006
9- 37
Declaring Referral Structures
Structures
Example 9-30. Template Structure With STRUCTALIGN(MAXALIGN) (page 2 of 2)
STRUCT B (*) FIELDALIGN (SHARED8);
BEGIN
INT
K;
FILLER
14;
STRUCT A2 (A); ! Base of A2 is guaranteed to be aligned on
! 16-byte boundary. Compiler issues warning
! here because A is declared with STRUCTALIGN
! (MAXALIGN) and B is a SHARED8 structure.
END;
STRUCT B1 (B);
! Base of B1 is guaranteed to be aligned on
! 16-byte boundary because the largest
! alignment of the components of B1 (A2) is
! 16 bytes.
Declaring Referral Structures
A referral structure declaration allocates storage for a structure whose layout is the
same as the layout of a previously declared structure or structure pointer.
identifier
STRUCT
(
referral
)
.
.EXT
.SG
.SGX
;
range
VST025.vsd
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of the new referral structure.
referral
is the identifier of a previously declared structure or structure pointer that provides
the structure layout for this structure.
HP pTAL Reference Manual—523746-006
9- 38
Declaring Referral Structures
Structures
range
[
lower-bound
:
upper-bound
]
VST993.vsd
lower-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth structure occurrence) of the first
structure occurrence you want to allocate. Each occurrence is one copy of the
structure.
upper-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth structure occurrence) of the last
structure occurrence you want to allocate. For a single-occurrence structure,
omit both bounds or specify the same value for both bounds.
The compiler allocates storage for the referral structure based on the following
characteristics:
•
•
The addressing mode and number of occurrences specified in the new declaration
The layout of the previous declaration
Structures declared in subprocedures must be directly addressed.
Structures always start on a word boundary.
Example 9-31 on page 9-39 declares a template structure and a referral structure that
references the template structure. The referral structure imposes its addressing mode
and number of occurrences on the layout of the template structure.
Example 9-31. Referral Structure That References a Template Structure
STRUCT record (*);
BEGIN
STRING name[0:19];
STRING addr[0:29];
INT acct;
END;
! Declare template structure
STRUCT .customer (record) [1:50];
! Declare referral structure
HP pTAL Reference Manual—523746-006
9- 39
Declaring Simple Variables in Structures
Structures
Declaring Simple Variables in Structures
The simple variable declaration associates a name with a single-element data item.
When you declare a simple variable inside a structure, the form is:
identifier
type
;
,
VOLATILE
VST705.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
type
is any data type described in Section 3, Data Representation.
identifier
is the identifier of the simple variable.
You cannot initialize a simple variable when you declare it inside a structure. You can
subsequently assign a value to the simple variable by using an assignment statement.
Example 9-32. Simple Variables Within a Structure
STRUCT .inventory[0:49];
BEGIN
INT
item;
FIXED(2) price;
INT
quantity;
END;
! Declare definition structure
! Declare three simple variables
! within structure layout
Declaring Arrays in Structures
An array declaration associates an identifier with a collectively stored set of elements
of the same data type. When you declare an array inside a structure, the form is:
type
identifier
range
;
,
VST201.vsd
HP pTAL Reference Manual—523746-006
9- 40
Declaring Arrays in Structures
Structures
type
is any data type described in Section 3, Data Representation.
identifier
is the identifier of the array.
range
[
lower-bound
:
upper-bound
]
VST993.vsd
lower-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth array element) of the first array
element you want allocated. Both lower and upper bounds are required.
upper-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth array element) of the last array
element you want allocated. Both lower and upper bounds are required.
When you declare arrays inside a structure, the following guidelines apply:
•
•
•
You cannot initialize arrays declared in structures. You can assign values to such
arrays only by using assignment statements.
You cannot declare indirect arrays or read-only arrays in structures.
You can specify array bounds of [n : n-1] in structures (for example, [6:5]).
Such an array is called a zero-length array. It is often used to initialize a structure,
as in Example 9-34 on page 9-42. This method of initialization allows you to name
something with the same address as the next “thing” in the list without allocating
data for it, similar to a union or equivalence.
Example 9-33. Arrays Within a Structure
STRUCT record;
BEGIN
STRING name[0:19];
STRING addr[0:29];
INT acct;
END;
! Declare definition structure
! Declare arrays within the structure
! layout
HP pTAL Reference Manual—523746-006
9- 41
Declaring Substructures
Structures
Example 9-34. Using a Zero-Length Array to Initialize a Structure
STRUCT s;
BEGIN
STRING a[0:-1];
INT b;
! @a[0] is the same as @b
STRUCT t;
BEGIN
...
END;
...
END;
s.a[0] := 0;
s.a[1] := s.a[0] for $LEN(s);
...
! Very efficient
Declaring Substructures
A substructure is a structure embedded within another structure or substructure. You
can declare substructures that have the following characteristics:
•
•
•
•
Substructures must be directly addressed.
Substructures have byte addresses, not word addresses.
Substructures can be nested to a maximum of 64 levels.
Substructures can have bounds of [n : n-1] (for example, [6:5]).
Topics:
•
•
Definition Substructures on page 9-42
Referral Substructures on page 9-45
Definition Substructures
A definition substructure describes a layout and allocates storage for it.
STRUCT
identifier
structure-layout
field-alignment
;
range
VST626.vsd
identifier
is the identifier of the definition substructure.
HP pTAL Reference Manual—523746-006
9- 42
Definition Substructures
Structures
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
FIELDALIGN
specifies how you want the compiler to align the base of the structure and
fields in the structure. The offsets of fields in a structure are aligned relative to
the base of the structure.
If a definition substructure does not specify a FIELDALIGN clause, the
contained substructure’s field alignment is the field alignment of its
encompassing structure or substructure.
If you do not specify a FIELDALIGN clause on a structure declaration, pTAL
uses the current value of the FIELDALIGN compiler directive. The default value
of the FIELDALIGN directive is AUTO.
If you specify a FIELDALIGN (NODEFAULT) compiler directive, you must
specify a FIELDALIGN clause on every definition structure and template
structure.
SHARED2
specifies that the base of the structure and each field in the structure must
begin at an even-byte address except STRING fields.
SHARED8
specifies that the offset of each field in the structure from the base of the
structure must be begin at an address that is an integral multiple of the width of
the field.
AUTO
specifies that the structure and the fields of the structure be aligned according
to the optimal alignment for the architecture on which the program will run (this
is not the same behavior as the AUTO attribute has in the native mode HP C
compiler).
PLATFORM
specifies that the structure and the fields of the structure must begin at
addresses that are consistent across all languages on the same architecture.
HP pTAL Reference Manual—523746-006
9- 43
Definition Substructures
Structures
range
[
lower-bound
:
upper-bound
]
VST993.vsd
lower-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth substructure occurrence) of the first
substructure occurrence you want allocated. Each occurrence is one copy of
the substructure.
upper-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth substructure occurrence) of the last
substructure occurrence you want allocated. For a single-occurrence
substructure, omit both bounds or specify the same value for both bounds.
structure-layout
is the same BEGIN-END block as for structures. It can contain declarations for
simple variables, arrays, substructures, filler bits, filler bytes, redefinitions, simple
pointers, and structure pointers. The size of one substructure occurrence is the
size of the layout, either in odd or even bytes. The total layout for one occurrence
of the encompassing structure must not exceed 32,767 bytes.
Example 9-35. Declaring Definition Substructures
STRUCT .warehouse[0:1];
BEGIN
STRUCT inventory [0:49];
BEGIN
INT item_number;
FIXED(2) price;
INT on_hand;
END;
END;
! Two warehouses
! Definition substructure
! 50 items in each warehouse
HP pTAL Reference Manual—523746-006
9- 44
Referral Substructures
Structures
Referral Substructures
A referral substructure allocates storage for a substructure whose layout is the same
as the layout of a previously declared structure or structure pointer.
identifier
STRUCT
referral
(
)
;
range
VST203.vsd
identifier
is the identifier of the referral substructure.
referral
is the identifier of a structure that provides the structure layout. You can specify any
previously declared structure (except the encompassing structure) or structure
pointer. If the previous structure has an odd-byte size, the compiler rounds the size
of the new substructure up so that it has an even-byte size.
range
[
lower-bound
:
upper-bound
]
VST993.vsd
lower-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth occurrence) of the first substructure
occurrence you want allocated. Each occurrence is one copy of the
substructure.
upper-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth occurrence) of the last substructure
occurrence you want allocated. For a single-occurrence substructure, omit both
bounds or specify the same value for both bounds.
HP pTAL Reference Manual—523746-006
9- 45
Declaring Filler
Structures
Example 9-36. Declaring a Referral Substructure
STRUCT temp(*);
BEGIN
STRING a[0:2];
INT
b;
STRING c;
END;
! Template structure -! no space allocated
STRUCT .ind_struct;
BEGIN
INT
header[0:1];
STRING abyte;
STRUCT abc (temp) [0:1];
END;
! Definition structure -! space allocated
! Declare referral substructure
! Size of ind_struct.abc[0] is
! 8 bytes
Declaring Filler
A filler declaration allocates a byte or bit place holder in a structure.
FILLER
constant-expression
;
BIT_FILLER
VST026.vsd
FILLER
allocates the specified number of byte place holders.
BIT_FILLER
allocates the specified number of bit place holders.
constant-expression
is a positive integer constant value that specifies a number of filler units in one of
the following ranges:
FILLER
0 through 32,767 bytes
BIT_FILLER
0 through 255 bits
You can declare filler bits and filler bytes, but you cannot access such filler locations.
If the structure layout must match a structure layout defined in another program, your
structure declaration need only include data items used by your program and can use
filler bits or bytes for the unused space.
HP pTAL Reference Manual—523746-006
9- 46
Declaring Filler
Structures
The compiler allocates space for each byte or bit you specify in a filler declaration. If
the alignment of the next data item requires additional pad bytes or bits, the compiler
allocates those also.
Example 9-37. Filler Byte Declarations
LITERAL last = 11;
STRUCT .x[1:last];
BEGIN
STRING byte[0:2];
FILLER 1;
INT word1;
INT word2;
INT(32) integer32;
FILLER 30;
END;
! Last occurrence
! Document word-alignment pad byte
! Place holder for unused space
See also the filler byte example in Definition Substructure on page 9-56.
Example 9-38. Filler Bit Declaration
STRUCT .flags;
BEGIN
UNSIGNED(1) flag1;
UNSIGNED(1) flag2;
UNSIGNED(2) state;
BIT_FILLER 12;
END;
! State = 0, 1, 2, or 3
! Place holder for unused space
HP pTAL Reference Manual—523746-006
9- 47
Declaring Simple Pointers in Structures
Structures
Declaring Simple Pointers in Structures
A simple pointer is a variable that contains the memory address of a simple variable or
an array. When you declare a simple pointer inside a structure, the form is:
type
VOLATILE
identifier
.
.EXT
.SG
.SGX
;
REFALIGNED
(
2
)
8
,
VST627.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
type
is any data type except UNSIGNED. The data type determines how much data the
simple pointer can access at a time—a byte, word, doubleword, or quadrupleword.
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of the simple pointer.
HP pTAL Reference Manual—523746-006
9- 48
Using Simple Pointers
Structures
REFALIGNED
specifies the base alignment of the structures that the structure pointer will
reference.
2
references a structure that might not be well-aligned.
8
indicates that the base of the structure and the fields in the structure are well
aligned in memory
Example 9-39. Simple Pointers Within a Structure
STRUCT my_struct;
BEGIN
FIXED .std_pointer;
STRING .EXT ext_pointer;
END;
! Standard simple pointer
! Extended simple pointer
Topics:
•
•
Using Simple Pointers on page 9-49
Assigning Addresses to Pointers in Structures on page 9-50
Using Simple Pointers
The data type determines the size of data a simple pointer can access at a time.
Table 9-6. Data Accessed by Simple Pointers
Data Type
Accessed Data
STRING
Byte
INT
Word
INT(32)
Doubleword
REAL
Doubleword
REAL(64)
Quadrupleword
FIXED
Quadrupleword
The addressing mode and data type determine the kind of address the simple pointer
can contain.
HP pTAL Reference Manual—523746-006
9- 49
Assigning Addresses to Pointers in Structures
Structures
Table 9-7. Addresses in Simple Pointers
Addressing
Mode
Data Type
Kind of Address
Standard
STRING
16-bit byte address
Standard
Any except STRING
16-bit word address
Extended
STRING
32-bit byte address, normally in the automatic
extended data segment
Extended
Any except STRING
32-bit even-byte address, normally in the
automatic extended data segment (if you specify
an odd-byte address, results are undefined)
Assigning Addresses to Pointers in Structures
You can assign to pointers the kinds of addresses listed in Table 9-4 on page 9-19 and
Table 9-5 on page 9-22. To assign an address to a pointer within a structure, specify
the fully qualified pointer identifier in an assignment statement. Prefix the structure
identifier with @. For example, the assignment statement to assign an address to
ptr_x declared in substruct_a in struct_b is:
@struct_b.substruct_a.ptr_x := arith_expression;
In the preceding example, @ applies to ptr_x, the most qualified item. On the left side
of the assignment operator, @ changes the address contained in the pointer, not the
value of the item to which the pointer points.
You can also prefix @ to a variable on the right side of the assignment operator. If the
variable is a pointer, @ returns the address contained in the pointer. If the variable is
not a pointer, @ returns the address of the variable itself.
Example 9-40. Assigning Addresses to Pointers in Structures
INT .array[0:99];
STRUCT .st;
BEGIN
INT .std_ptr;
INT .EXT ext_ptr;
END;
PROC e MAIN;
BEGIN
@st.std_ptr := @array[0];
@st.ext_ptr := $XADR(array[0]);
END;
Example 9-41 on page 9-51 assigns the address of a structure to structure pointers
declared in another structure.
HP pTAL Reference Manual—523746-006
9- 50
Declaring Structure Pointers in Structures
Structures
Example 9-41. Assigning Addresses to Pointers in Structures
STRUCT .s1;
BEGIN
INT var1;
INT var2;
END;
STRUCT .s2;
BEGIN
INT .std_ptr (s1);
INT .EXT ext_ptr (s1);
END;
PROC g MAIN;
BEGIN
@s2.std_ptr := @s1[0];
@s2.ext_ptr := $XADR(s1);
END;
Declaring Structure Pointers in Structures
A structure pointer is a variable that contains the address of a structure. When you
declare a structure pointer inside a structure, the form is:
STRING
VOLATILE
INT
identifier
referral
(
)
.
.EXT
.SG
.SGX
;
REFALIGNED
(
2
)
8
,
VST628.vsd
HP pTAL Reference Manual—523746-006
9- 51
Declaring Structure Pointers in Structures
Structures
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
STRING
is the STRING attribute.
INT
is the INT attribute
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of the structure pointer.
referral
is the identifier of a structure that provides the structure layout. You can specify any
previously declared structure (including the encompassing structure) or structure
pointer.
REFALIGNED
specifies the base alignment of the structures that the structure pointer will
reference.
2
references a structure that might not be well-aligned.
8
indicates that the base of the structure and the fields in the structure are well
aligned in memory
The addressing mode and STRING or INT attribute determine the kind of addresses a
structure pointer can contain, as described in Table 9-8 on page 9-53.
HP pTAL Reference Manual—523746-006
9- 52
Declaring Redefinitions
Structures
Table 9-8. Addresses in Structure Pointers
Addressing
Mode
STRING or
INT Attribute
Standard
STRING*
16-bit byte address of a substructure, STRING simple
variable, or STRING array declared in a structure
Standard
INT**
16-bit word address of any structure data item
Extended
STRING*
32-bit byte address of any structure item located in any
segment, normally the automatic extended data segment
Extended
INT**
32-bit byte address of any structure item located in any
segment, normally the automatic extended data segment
Kind of Address
* If the pointer is the source in a move statement or group comparison expression that omits a count-unit,
the count-unit is BYTES.
** If the pointer is the source in a move statement or group comparison expression that omits a count-unit,
the count-unit is WORDS.
Example 9-42. Declaring a Structure Pointer Within a Structure
STRUCT struct_a;
BEGIN
INT a;
INT b;
END;
STRUCT struct_b;
BEGIN
INT .EXT struct_pointer (struct_a);
STRING a;
END;
Declaring Redefinitions
A redefinition declares a new identifier and sometimes a new description for a previous
item in the same structure.
The following rules apply to all redefinitions in structures:
•
•
The new item must be of the same length or shorter than the previous item.
The new item and the previous item must be at the same BEGIN-END level of a
structure.
HP pTAL Reference Manual—523746-006
9- 53
Simple Variable
Structures
Additional rules are given in subsections that describe each kind of redefinition in the
following topics:
•
•
•
•
•
•
Simple Variable on page 9-54
Array on page 9-55
Definition Substructure on page 9-56
Referral Substructure on page 9-59
Simple Pointer on page 9-61
Structure Pointer on page 9-63
For information about redefinitions outside structures, see Section 11, Equivalenced
Variables.
Simple Variable
A simple variable redefinition associates a new simple variable with a previous item at
the same BEGIN-END level of a structure.
type
identifier
=
previous-identifier
VOLATILE
;
VST706.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
type
is any data type except UNSIGNED.
identifier
is the identifier of the new simple variable.
previous-identifier
is the identifier of a simple variable, array, substructure, or pointer previously
declared in the same structure. You cannot specify an index with this identifier.
HP pTAL Reference Manual—523746-006
9- 54
Array
Structures
In a redefinition, the new item and the previous (nonpointer) item both must have a
byte address or both must have a word address. If the previous item is a pointer, the
data it points to must be word addressed or byte addressed to match the new item.
Example 9-43 on page 9-55 redefines the left byte of int_var as string_var.
Example 9-43. Simple Variable Redefinition
STRUCT .mystruct;
BEGIN
INT int_var;
STRING string_var = int_var;
END;
! Redefinition
Array
An array redefinition associates a new array with a previous item at the same BEGINEND level of a structure.
type
identifier
=
previous-identifier
;
range
VST030.vsd
type
is any data type except UNSIGNED.
identifier
is the identifier of the new array.
range
[
lower-bound
:
upper-bound
]
VST993.vsd
lower-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth element) of the first array element you
want allocated.
HP pTAL Reference Manual—523746-006
9- 55
Definition Substructure
Structures
upper-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth element) of the last array element you
want allocated.
previous-identifier
is the identifier of a simple variable, array, substructure, or pointer previously
declared in the same structure. You cannot specify an index with this identifier.
In a redefinition, the new item and the previous (nonpointer) item both must have a
byte address or both must have a word address. If the previous item is a pointer, the
data it points to must be word addressed or byte addressed to match the new item.
Example 9-44. Array Redefinition
STRUCT .s;
BEGIN
INT
a[0:3];
INT(32) b[0:1] = a;
END;
! Redefine INT array as INT(32) array
Definition Substructure
A definition substructure redefinition associates a new definition substructure with a
previous item at the same BEGIN-END level of a structure.
STRUCT
identifier
range
=
previous-identifier
field-alignment
structure-layout
;
;
VST707.vsd
identifier
is the identifier of the new substructure.
range
[
lower-bound
:
upper-bound
]
VST993.vsd
HP pTAL Reference Manual—523746-006
9- 56
Definition Substructure
Structures
lower-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth substructure occurrence) of the first
substructure occurrence you want allocated. Each occurrence is one copy of
the substructure.
upper-bound
is an INT constant expression (in the range −32,768 through 32,767) that
specifies the index (relative to the zeroth substructure occurrence) of the last
substructure occurrence you want allocated.
To declare a single-occurrence substructure, omit both bounds or specify the
same value for both bounds.
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
FIELDALIGN
specifies how you want the compiler to align the base of the structure and
fields in the structure. The offsets of fields in a structure are aligned relative to
the base of the structure.
If a definition substructure does not specify a FIELDALIGN clause, the
contained substructure’s field alignment is the field alignment of its
encompassing structure or substructure.
If you do not specify a FIELDALIGN clause on a structure declaration, pTAL
uses the current value of the FIELDALIGN compiler directive. The default value
of the FIELDALIGN directive is AUTO.
If you specify a FIELDALIGN (NODEFAULT) compiler directive, you must
specify a FIELDALIGN clause on every definition structure and template
structure.
SHARED2
specifies that the base of the structure and each field in the structure must
begin at an even byte address except STRING fields.
HP pTAL Reference Manual—523746-006
9- 57
Definition Substructure
Structures
SHARED8
specifies that the offset of each field in the structure from the base of the
structure must be begin at an address that is an integral multiple of the width of
the field.
AUTO
specifies that the structure and the fields of the structure be aligned according
to the optimal alignment for the architecture on which the program will run (this
is not the same behavior as the AUTO attribute has in the native mode HP C
compiler).
PLATFORM
specifies that the structure and the fields of the structure must begin at
addresses that are consistent across all languages on the same architecture.
previous-identifier
is the identifier of a simple variable, array, substructure, or pointer previously
declared in the same structure. No index is allowed with this identifier.
structure-layout
is the same BEGIN-END block as for structures. It can contain declarations for
simple variables, arrays, substructures, filler bits, filler bytes, redefinitions, simple
pointers, and structure pointers. The size of one substructure occurrence is the
size of the layout, either in odd or even bytes. The total layout for one occurrence
of the encompassing structure must not exceed 32,767 bytes.
If the previous item is a substructure and you omit the bounds or if either bound is 0,
the new substructure and the previous substructure occupy the same space and have
the same offset from the beginning of the structure.
Example 9-45. Definition Substructure Redefinition
STRUCT a;
BEGIN
STRING x;
STRUCT b;
BEGIN
STRING y;
END;
STRUCT c = b;
BEGIN
STRING z;
END;
END;
! b starts on odd byte
! Redefine b as c, also on odd byte
HP pTAL Reference Manual—523746-006
9- 58
Referral Substructure
Structures
Example 9-46. Definition Substructure Redefinition
STRUCT mystruct;
BEGIN
STRUCT mysub1;
BEGIN
INT int_var;
END;
STRUCT mysub2 = mysub1;
BEGIN
STRING string_var;
END;
END;
! Redefine mysub1 as mysub2
Referral Substructure
A referral substructure redefinition associates a new referral substructure with a
previous item at the same BEGIN-END level of a structure.
identifier
STRUCT
=
referral
(
previous-identifier
)
;
range
VST208.vsd
identifier
is the identifier of the new substructure.
referral
is the identifier of a structure that provides the structure layout. You can specify any
previously declared structure (except the encompassing structure) or structure
pointer. If the previous structure has an odd-byte size, the compiler rounds the size
of the new substructure up so it has an even-byte size.
range
[
lower-bound
:
upper-bound
]
VST993.vsd
HP pTAL Reference Manual—523746-006
9- 59
Referral Substructure
Structures
lower-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth substructure occurrence) of the first
substructure occurrence you want allocated. Each occurrence is one copy of
the substructure.
upper-bound
is an INT constant expression (in the range -32,768 through 32,767) that
specifies the index (relative to the zeroth substructure occurrence) of the last
substructure occurrence you want allocated.
To declare a single-occurrence substructure, omit both bounds or specify the
same value for both bounds.
previous-identifier
is the identifier of a simple variable, array, substructure, or pointer previously
declared in the same structure. No index is allowed with this identifier.
If the previous item is a substructure and you omit the bounds or if either bound is 0,
the new substructure and the previous substructure occupy the same space and have
the same offset from the beginning of the structure.
Example 9-47. Referral Substructure Redefinition
STRUCT temp(*);
BEGIN
STRING a[0:2];
INT
b;
STRING c;
END;
! Template structure
STRUCT .ind_struct;
BEGIN
INT
header[0:1];
STRING abyte;
STRUCT abc (temp) [0:1];
STRUCT xyz (temp) [0:1] = abc;
END;
! Definition structure
! Redefine abc as xyz
HP pTAL Reference Manual—523746-006
9- 60
Simple Pointer
Structures
Simple Pointer
A simple pointer redefinition associates a new simple pointer with a previous item at
the same BEGIN-END level of a structure.
type
identifier
VOLATILE
.
.EXT
.SG
.SGX
REFALIGNED
(
2
)
8
=
previous-identifier
;
VST708.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
type
is any data type except UNSIGNED. The data type determines how much data the
simple pointer can access at a time—a byte, word, doubleword, or quadrupleword.
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of the new simple pointer.
HP pTAL Reference Manual—523746-006
9- 61
Simple Pointer
Structures
REFALIGNED
specifies the base alignment of the structures that the structure pointer will
reference.
2
references a structure that might not be well-aligned.
8
indicates that the base of the structure and the fields in the structure are well
aligned in memory
previous-identifier
is the identifier of a simple variable, array, substructure, or pointer previously
declared in the same structure. No index is allowed with this identifier.
Example 9-48. Simple Pointer Redefinition
STRUCT my_struct;
BEGIN
STRING var[0:5];
STRING .EXT ext_pointer = var;
! Simple variable
! Redefine var as simple
! pointer, ext_pointer
END;
HP pTAL Reference Manual—523746-006
9- 62
Structure Pointer
Structures
Structure Pointer
A structure pointer redefinition associates a new structure pointer with a previous item
at the same BEGIN-END level of a structure.
STRING
VOLATILE
identifier
.
INT
.EXT
.SG
.SGX
referral
(
)
(
REFALIGNED
2
)
8
=
previous-identifier
;
VST709.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
STRING
is the STRING attribute.
INT
is the INT attribute.
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
HP pTAL Reference Manual—523746-006
9- 63
Structure Pointer
Structures
identifier
is the identifier of the new structure pointer.
referral
is the identifier of a structure that provides the structure layout. You can specify any
previously declared structure (including the encompassing structure) or structure
pointer.
REFALIGNED
specifies the base alignment of the structures that the structure pointer will
reference.
2
references a structure that might not be well-aligned.
8
indicates that the base of the structure and the fields in the structure are well
aligned in memory
previous-identifier
is the identifier of a simple variable, array, substructure, or pointer previously
declared in the same structure. No index is allowed with this identifier.
The addressing mode and STRING or INT attribute determine the kind of addresses a
structure pointer can contain, as described in Table 9-7 on page 9-50.
Example 9-49. Structure Pointer Redefinition
STRUCT record;
BEGIN
FIXED data;
INT std_link_addr;
INT .std_link (record) = std_link_addr;
INT(32) ext_link_addr;
INT .EXT ext_link (record) = ext_link_addr;
END;
HP pTAL Reference Manual—523746-006
9- 64
! Redefinition
! Redefinition
10
Pointers
This section describes the syntax for declaring and initializing pointers you manage
yourself. You can declare the following kinds of pointers:
•
•
Simple pointer—a variable into which you store a memory address, usually of a
simple variable or array, which you can access with this simple pointer.
Structure pointer—a variable into which you store the memory address of a
structure which you can access with this structure pointer.
The compiler allocates 32 bits for all pointers except .SG. In expressions involving
addresses, however, the compiler treats all operands as if they were word addresses
except extended addresses the and addresses of strings. The pointer’s object data
type determines the pointer’s address type and identifies the addressing type and
location of data that your pointers will reference. For information about working with
addresses, see Section 5, Expressions.
Some portions of this section describe how you reference data in system globals.
System globals can be accessed only by programs running as privileged procedures.
Topics:
•
•
•
•
•
•
•
•
Overview of Pointer Declaration on page 10-2
Declaring VOLATILE Pointers on page 10-4
Address Types on page 10-5
Declaring Simple Pointers on page 10-12
Initializing Simple Pointers on page 10-14
Declaring Structure Pointers on page 10-16
Initializing Structure Pointers on page 10-17
Declaring System Global Pointers on page 10-20
HP pTAL Reference Manual—523746-006
10- 1
Overview of Pointer Declaration
Pointers
Overview of Pointer Declaration
This subsection gives you the general pointer syntax and explains the syntax
elements.
type
VOLATILE
identifier
.
.EXT
.SG
.SGX
REFALIGNED
2
(
)
8
;
:=
initialization
,
VST676.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
type
Is one of the following data types depending on whether the pointer is a simple
pointer or a structure pointer:
•
•
•
•
•
•
•
BADDR
CBADDR
CWADDR
EXTADDR
FIXED [(fpoint )]
INT
INT (16)
HP pTAL Reference Manual—523746-006
10- 2
Overview of Pointer Declaration
Pointers
•
•
•
•
•
•
•
•
•
•
•
•
•
INT (32)
INT (64)
PROCADDR
REAL
REAL (32)
REAL (64)
SGBADDR
SGWADDR
SGXBADDR
SGXWADDR
STRING
UNSIGNED (width)
WADDR
fpoint
is the implied fixed point of the FIXED variable. fpoint can also be an
asterisk (*) as in:
FIXED(*) .f;
width
is a constant expression specifying the width, in bits, of the variable.
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of the pointer.
REFALIGNED
Specifies the alignment of the variables or structures that identifier
references.
2
specifies that the variables and structures identifier references are aligned as
they would be aligned in TAL (and might not be well aligned in pTAL).
8
specifies that the variables and structures are well aligned for use in pTAL.
For nonstructure pointers, the default for REFALIGNED is the value you specify in
the REFALIGNED on page 17-53.
HP pTAL Reference Manual—523746-006
10- 3
Declaring VOLATILE Pointers
Pointers
initialization
is an expression representing a memory address. For more information about
operations on addresses, see Section 5, Expressions.
Declaring VOLATILE Pointers
Declare pointers VOLATILE if they can be accessed asynchronously by other
processes such as another process in your application or an I/O driver.
Topics:
•
•
Simple on page 10-4
Structure on page 10-5
Simple
When you declare a VOLATILE simple pointer, the value of the pointer and the data
referenced by the pointer are treated as VOLATILE and are maintained in memory, not
in a register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads and
writes in the source code, VOLATILE also causes that precise order of memory
references to be preserved, again, when code is optimized.
Example 10-1. Declaring VOLATILE Simple Pointers
INT i;
INT a;
INT b[0:9];
VOLATILE INT .p1 := @a;
VOLATILE INT .p2 := @b;
i := p1;
! pTAL treats pointer p1 and data p1 references,
! a, as volatile. Program reads value of pointer
! p1 each time statement executes
i := a;
! pTAL does not treat direct reference to a as
! volatile even though p1 still points to it,
! because a is not declared volatile
i := p2[a];
! For each reference to p2[a], program:
! * Reads value of pointer p2 from memory
! * Adds value of a, which can be kept in a
!
register because a is not volatile
! * Reads from memory the value referenced by
!
p2[a]
i := p2[p1];
! Data referenced by p2[p1] is the same as p2[a]
! in the preceding example, but both p1 and p2
! are volatile. Program reads from memory p1,
! p2, a, and element of array b referenced by p1
HP pTAL Reference Manual—523746-006
10- 4
Structure
Pointers
Structure
When you declare a VOLATILE structure pointer, the compiler generates code that
maintains the value of the pointer in memory, not in a register. Each reference to a
VOLATILE data item causes the data item to be read or written to memory even when
code is optimized. Based on the order of reads and writes in the source code,
VOLATILE also causes that precise order of memory references to be preserved,
again, when code is optimized.
You must specify the VOLATILE attribute on each field that you want to be volatile.
Example 10-2. Declaring VOLATILE Structure Pointers
INT i;
STRUCT s;
BEGIN
INT m;
VOLATILE INT n;
END;
! Field m is never treated as volatile
! Field n is always treated as volatile
VOLATILE INT .s1(s) := @s;
INT .s2(s) := @s;
i := s1.m;
! Value of pointer s1 is read from memory on
! every reference, but value of field s1.m
! might be maintained in a register
i := s1.n;
! Value of pointer s1 is read from memory on
! every reference, as is value of s1.n
! because field n specifies VOLATILE
i := s2.n;
! Value of pointer s2 might or might not be
! from memory, but having read the pointer,
! the field s2.n is always read from memory
Address Types
pTAL address types control the addresses you store into pointers. A 32-bit address can
reference data anywhere in memory with optimal performance. The hardware does not
require programs to specify an addressing type or memory storage area.
The compiler determines the address type of a pointer from the pointer declaration.
You cannot explicitly declare a pointer’s address type.
Address types are used primarily to describe the addresses that you assign to a
pointer, not the data your program is processing.
Only operations that are meaningful for addresses are valid on address types.
HP pTAL Reference Manual—523746-006
10- 5
Address Types
Pointers
A pointer is associated with two data types:
Data Type
Description
Object data type
Data type of the objects that the pointer can reference
Address data type
Data type of the addresses that you can store in the pointer
Table 10-1. Address Types
Pointer
Size
Example
16-bit address to 1-bytealigned data
32
STRING .s;
Word
16-bit address to 2-bytealigned data
32
INT .i;
CBADDR
Byte
16-bit address to 1-bytealigned, read-only data
32
STRING s ='P':="A";
CWADDR
Word
16-bit address to 2-bytealigned, read-only data
32
INT i = 'P' := 123;
SGBADDR
Byte
16-bit address to 1-bytealigned, 'SG'-relative
data
16
STRING .SG s;
SGWADDR
Word
16-bit address to 2-bytealigned, 'SG'-relative
data
16
INT .SG i;
SGXBADDR
Byte
32-bit address to 1-bytealigned, 'SG'-relative
data
32
STRING .SGX s;
SGXWADDR
Word
32-bit address to 2-bytealigned, 'SG'-relative
data
32
INT .SGX i;
EXTADDR
Byte
32-bit address to data
32
INT .EXT x;
PROCADDR
N.A.
First address of
procedure code
32
PROC x;
BEGIN
END;
Data Type
Address
Type
BADDR
Byte
WADDR
Target Data
You cannot explicitly declare or change the address type of a pointer. pTAL determines
the address type based on the pointer declaration.
Every identifier you declare in a pTAL program has an object data type and an address
type. Table 10-2 on page 10-7 lists the address type for all pTAL constructs except
simple variables. The address type of a simple variable is the same as the address
type of a pointer to data of the same object data type as the simple variable.
HP pTAL Reference Manual—523746-006
10- 6
Address Types
Pointers
Example 10-3. Determining Address Types
INT .j;
INT i;
! Pointer: address type is WADDR
! Simple variable: address type is WADDR
Table 10-2. Object Data Types and Their Addresses (page 1 of 2)
Declaration
Address Type
Object Data Type
STRING
.s;
BADDR
STRING
INT
.i;
WADDR
INT
INT(32)
.j;
WADDR
INT(32)
REAL
.r;
WADDR
REAL
REAL(64)
.s;
WADDR
REAL(64)
FIXED
.f;
WADDR
FIXED
UNSIGNED(n)
.u;
WADDR
UNSIGNED
STRUCT
.t;
WADDR
none
SUBSTRUCT
.v;
BADDR
none
addr-type 1
.a;
WADDR
address_type 2
STRING
.EXT s;
EXTADDR
STRING
INT
.EXT i;
EXTADDR
INT
INT(32)
.EXT j;
EXTADDR
INT(32)
REAL
.EXT r;
EXTADDR
REAL
REAL(64)
.EXT s;
EXTADDR
REAL(64)
FIXED
.EXT f;
EXTADDR
FIXED
UNSIGNED(n)
.EXT u;
EXTADDR
UNSIGNED
STRUCT
.EXT t;
EXTADDR
none
SUBSTRUCT
.EXT v;
EXTADDR
none
addr-type 1
.EXT a;
EXTADDR
address_type 2
STRING
.SG s;
SGBADDR
STRING
INT
.SG i;
SGWADDR
INT
INT(32)
.SG j;
SGWADDR
INT(32)
REAL
.SG r;
SGWADDR
REAL
REAL(64)
.SG s;
SGWADDR
REAL(64)
FIXED
.SG f;
SGWADDR
FIXED
UNSIGNED(n)
.SG u;
SGWADDR
UNSIGNED
addr-type 1
.SG a;
SGWADDR
address_type 2
1. addr-type is any of the ten address types.
2. address_type is the same address type as specified in the declaration.
HP pTAL Reference Manual—523746-006
10- 7
Address Types
Pointers
Table 10-2. Object Data Types and Their Addresses (page 2 of 2)
Declaration
Address Type
Object Data Type
STRING
.SGX s;
SGXBADDR
STRING
INT1
.SGX i;
SGXWADDR
INT
INT(32)
.SGX j;
SGXWADDR
INT(32
REAL
.SGX r;
SGXWADDR
REAL
REAL(64)
.SGX s;
SGXWADDR
REAL(64)
FIXED
.SGX f;
SGXWADDR
FIXED
UNSIGNED(n)
.SGX u;
SGXWADDR
UNSIGNED
addr-type 1
.SGX a;
SGXWADDR
address_type 2
PROC p:
PROCADDR
PROC
PROCPTR p(); END PROCPTR;
PROCADDR
PROCPTR
Procedure ENTRY e;
PROCADDR
PROC
STRING v = 'P' := "ab";
CBADDR
STRING
INT v = 'P' := "ab";
CWADDR
INT
SUBPROC
CWADDR
SUBPROC
Subprocedure ENTRY e;
CWADDR
LABEL l;
CWADDR
LABEL
1. addr-type is any of the ten address types.
2. address_type is the same address type as specified in the declaration.
Topics:
•
•
•
•
•
BADDR and WADDR on page 10-9
SGBADDR, SGWADDR, SGXBADDR, and SGXWADDR (System Globals) on
page 10-9
PROCADDR (Procedures, Procedure Pointers, and Procedure Entry Points) on
page 10-10
Subprocedures, Subprocedure Entry Points, Labels, and Read-Only Arrays
(CBADDR and CWADDR Address Types) on page 10-10
EXTADDR on page 10-11
HP pTAL Reference Manual—523746-006
10- 8
BADDR and WADDR
Pointers
BADDR and WADDR
The address type of pointers is WADDR, except for STRING pointers, for which the
address type is BADDR.
Example 10-4. BADDR and WADDR
INT
a;
INT
.b;
STRING .c;
INT(32) d[0:9];
INT
.e[0:9];
!
!
!
!
!
Variable:
Pointer:
Pointer:
Direct array:
Indirect array:
address
address
address
address
address
type
type
type
type
type
is
is
is
is
is
WADDR
WADDR
BADDR
WADDR
WADDR
SGBADDR, SGWADDR, SGXBADDR, and SGXWADDR
(System Globals)
The address type of a pointer to system global data is one of SGBADDR, SGWADDR,
SGXBADDR, or SGXWADDR. You can declare pointers to system global data by using
either .SG notation or .SGX notation. In either case, the pointer is not in system
globals, but the data is. pTAL allocates 16 bits for pointers you declare with .SG and 32
bits pointers declared with .SGX.
Example 10-5. SGBADDR, SGWADDR, SGXBADDR, and SGXWADDR
STRING
INT
STRING
INT
.SG
.SG
.SGX
.SGX
s;
i;
t;
j;
!
!
!
!
s
i
t
j
is
is
is
is
16
16
32
32
bits
bits
bits
bits
HP pTAL Reference Manual—523746-006
10- 9
PROCADDR (Procedures, Procedure Pointers, and
Procedure Entry Points)
Pointers
PROCADDR (Procedures, Procedure Pointers, and Procedure
Entry Points)
The address type of procedures, procedure pointers (PROCPTRs), and procedure
entry points is PROCADDR.
Example 10-6. PROCADDR
PROCADDR pa;
PROCPTR q( j );
INT j;
END PROCPTR;
PROC p( j );
INT j;
BEGIN
ENTRY p1;
...
p1:
pa := @q;
pa := @p;
pa := @p1;
END;
! Address type of q is PROCADDR
! Address type of p is PROCADDR
! Address type of p1 is PROCADDR
Subprocedures, Subprocedure Entry Points, Labels, and Read-Only Arrays (CBADDR
and CWADDR Address Types)
The address type of a pointer to code in a user code segment—that is, a read-only
array—is CWADDR if the pointer is type INT and is CBADDR if the pointer is type
STRING. The address type of subprocedures, subprocedure entry points, and all
labels—in both procedures and subprocedures—is CWADDR.
HP pTAL Reference Manual—523746-006
10 -10
EXTADDR
Pointers
Example 10-7. CBADDR and CWADDR
INT
sa = 'P' :=
STRING sb = 'P' :=
PROC p;
BEGIN
LABEL lab1;
SUBPROC subp1;
BEGIN
CWADDR cw;
CBADDR cb;
ENTRY ent1;
ent1:
lab2:
cw := @subp1;
cw := @lab1;
cw := @lab2;
cw := @ent1;
cw := @sa;
cb := @sb;
END;
lab1:
END;
[1,2,3,4];
["ABCD"];
!
!
!
!
!
!
Address
Address
Address
Address
Address
Address
! Address type of sa is CWADDR
! Address type of sb is CBADDR
type
type
type
type
type
type
of
of
of
of
of
of
@subp1
@lab1
@lab2
@ent1
@sa
@sb
is
is
is
is
is
is
CWADDR
CWADDR
CWADDR
CWADDR
CWADDR
CBADDR
EXTADDR
An EXTADDR is 32 bits. You can store the address of any of your processes’ data in
an EXTADDR pointer.
Example 10-8. EXTADDR Declarations
INT
STRING
INT
REAL
.EXT
.EXT
.EXT
.EXT
i;
s;
g = 'SG' + 0;
r;
HP pTAL Reference Manual—523746-006
10 -11
Declaring Simple Pointers
Pointers
Declaring Simple Pointers
A simple pointer declaration associates an identifier with a memory location that
contains the user-initialized address of a simple variable or array.
type
VOLATILE
identifier
.
.EXT
.SG
.SGX
REFALIGNED
2
(
)
8
;
:=
initialization
,
VST676.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
type
is one of the following data types:
•
•
•
•
•
•
•
•
BADDR
CBADDR
CWADDR
EXTADDR
FIXED [ (fpoint ) ]
INT
INT (16)
INT (32)
HP pTAL Reference Manual—523746-006
10 -12
Declaring Simple Pointers
Pointers
•
•
•
•
•
•
•
•
•
•
•
•
•
INT (64)
PROCADDR
REAL
REAL (32)
REAL
REAL (32)
REAL (64)
SGBADDR
SGWADDR
SGXBADDR
SGXWADDR
STRING
WADDR
fpoint
The implied fixed point of the FIXED variable. fpoint can also be an asterisk (*)
as in:
FIXED(*) .f;
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of the pointer.
REFALIGNED
For simple pointers, the default for REFALIGNED is the value you specify in the
REFALIGNED on page 17-53.
2
specifies that the variables and structures that identifier references are aligned as
they would be aligned in TAL (and might not be well-aligned in pTAL).
8
specifies that the variables and structures are well-aligned for use in pTAL (and in
TAL, that they have more space).
For nonstructure pointers, the default for REFALIGNED is the value you specify in
the REFALIGNED on page 17-53.
HP pTAL Reference Manual—523746-006
10 -13
Initializing Simple Pointers
Pointers
initialization
An expression representing a memory address. For more information about
operations on addresses, see Section 5, Expressions.
The data type determines the size of data a simple pointer can access at a time.
The addressing mode and data type of the simple pointer determines the kind of
address the pointer can contain.
For information about data types and addresses, see Table 10-1 on page 10-6 and
Table 10-2 on page 10-7.
Furthermore, the kind of expression you can specify for the address depends on the
level at which you declare the pointer:
•
•
At the global level, use a constant expression.
At the local or sublocal level, you can use any arithmetic expression.
Initializing Simple Pointers
You can initialize global standard pointers by using constant expressions such as:
Expression
Meaning
@identifier
Accesses address of variable
@identifier '<<' 1
If @identifier is a WADDR address, ‘<<‘ converts it to a
BADDR address.
If @identifier is a SGWADDR address, ‘<<‘ converts it to a
SGBADDR address.
@identifier '>>' 1
If @identifier is a BADDR address, ‘>>‘ converts it to a
WADDR address.
If @identifier is a SGBADDR address, ‘>>‘ converts it to a
SGWADDR address.
@identifier [index ]
Accesses address of variable indicated by index
Built-in routine
Any that return a constant value, such as $OFFSET
Expressions other than those in the preceding list can perform valid type conversions,
but the compiler recognizes only those in the preceding list and might diagnose others
as errors.
HP pTAL Reference Manual—523746-006
10 -14
Initializing Simple Pointers
Pointers
You can apply the @ operator to these global variables:
Variable
@identifier?
Direct array
Yes
Standard indirect array
Yes
Extended indirect array
No
Direct structure
Yes
Standard indirect structure
Yes
Extended indirect structure
No
Simple pointer
No
Structure pointer
No
Simple pointers receive their initial values when you compile the source code. Local or
sublocal simple pointers receive their initial values at each activation of the
encompassing procedure or subprocedure.
Example 10-9. Declaring But Not Initializing a Simple Pointer
INT(32) .ptr;
Example 10-10. Declaring and Initializing a Simple Pointer
STRING .bytes[0:3];
! Indirect array
STRING .s_ptr := @bytes[3];
! Simple pointer initialized with
! address of bytes[3]
Example 10-11. Declaring and Initializing a STRING Simple Pointer
INT .a[0:39];
! INT array
STRING .ptr := @a[0] '<<' 1;
! STRING simple pointer
! initialized with byte address
! of a[0]
Example 10-12. Declaring and Initializing Simple Pointers
INT a[0:1] := [%100000, %110000];
! Array
INT .int_ptr1 := a[0];
! Simple pointer
! initialized with %100000
INT .int_ptr2 := a[1];
! Simple pointer
! initialized with %110000
HP pTAL Reference Manual—523746-006
10 -15
Declaring Structure Pointers
Pointers
Example 10-13. Declaring and Initializing a Simple Pointer, Using $XADR
INT a[0:1];
! 16-bit word-addressed array
STRING .EXT s := $XADR (a[0]);
! Extended simple pointer
! initialized with
! 32-bit byte address of a[0]
Example 10-14. Declaring and Initializing an Extended Simple Pointer
INT .EXT x[-100:100];
! Array
INT .EXT x_ptr := @x[-5];
! Extended simple pointer
! initialized with
! 32-bit byte address of x[-5]
Declaring Structure Pointers
The structure pointer declaration associates a previously declared structure with the
memory location to which the structure pointer points. You access data in the
associated structure by referencing the qualified structure pointer identifier.
STRING
VOLATILE
INT
identifier
(
referral
)
.
.EXT
.SG
.SGX
;
:=
initialization
,
VST677.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
HP pTAL Reference Manual—523746-006
10 -16
Initializing Structure Pointers
Pointers
STRING
is the STRING attribute.
INT
is the INT attribute, as INT, INT(32), or FIXED.
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of the pointer.
referral
is the identifier of a previously-declared structure, structure template, or structure
pointer.
Specify referral only for pointers to structures.
initialization
is an expression representing a memory address. For more information about
operations on addresses, see Section 5, Expressions.
Initializing Structure Pointers
The addressing mode and data type of the simple pointer determines the kind of
address the pointer can contain.
For information about data types and addresses, see Table 10-1 on page 10-6 and
Table 10-2 on page 10-7.
Furthermore, the kind of expression you can specify for the address depends on the
level at which you declare the pointer:
•
•
Use a constant expression at the global level. See also Initializing Simple Pointers
on page 10-14.
At the local or sublocal level, you can use any arithmetic expression.
If the expression is the address of a structure with an index, the structure pointer points
to a particular occurrence of the structure. If the expression is the address of an array,
with or without an index, you impose the structure on top of the array.
Global structure pointers receive their initial values when you compile the source code.
Local and sublocal structure pointers receive their initial values each time the
procedure or subprocedure is activated.
HP pTAL Reference Manual—523746-006
10 -17
Initializing Structure Pointers
Pointers
Example 10-15. Declaring and Initializing a Structure Pointer, Using $OFFSET
STRUCT t (*);
BEGIN
INT k;
END;
! Template structure
STRUCT .st;
! Definition structure
BEGIN
INT j;
STRUCT ss (t);
END;
INT .ip := @st '+' $OFFSET (st.j) '>>' 1;
! Simple pointer
INT .stp (t) := @st '+' $OFFSET (st.ss) '>>' 1;
! INT structure pointer
STRING .sstp (t) := @st '<<' 1 '+' $OFFSET (st.ss);
! STRING structure pointer
A standard STRING structure pointer can access only these structure items:
•
•
•
Substructure
STRING simple variable
STRING array
The last declaration in Example 10-15 on page 10-18 shows a STRING structure
pointer initialized with the converted byte address of a substructure.
Example 10-16 on page 10-18 shows another way to access a STRING item in a
structure. You can convert the word address of the structure to a byte address when
you initialize the STRING structure pointer and then access the STRING item in a
statement.
Example 10-16. Declaring and Initializing a STRING Structure Pointer
STRUCT .astruct[0:1];
BEGIN
STRING s1;
STRING s2;
STRING s3;
END;
STRING .ptr (astruct) := @astruct[1] '<<' 1;
ptr.s2 := %4;
! Access STRING structure item
HP pTAL Reference Manual—523746-006
10 -18
! STRING ptr
! initialized
! with converted
! byte address of
! astruct[1]
Initializing Structure Pointers
Pointers
Example 10-17. Declaring and Initializing a Local Structure Pointer
PROC my_proc MAIN;
BEGIN
STRUCT my_struct[0:2];
BEGIN
INT array[0:7];
END;
INT .struct_ptr (my_struct) := @my_struct[1];
! Structure pointer contains address of my_struct[1]
END;
Example 10-18. Declaring and Initializing a Local STRING Structure Pointer
STRUCT name_def(*);
BEGIN
STRING first[0:3];
STRING last[0:3];
END;
STRUCT .record;
BEGIN
STRUCT name (name_def);
INT age;
END;
! Declare substructure
STRING .my_name (name_def) := @record.name;
! Structure pointer
! contains address
! of substructure
my_name ':=' ["Sue Law"];
Example 10-19. Declaring and Initializing a Local STRING Structure Pointer
BEGIN
INT array[0:7];
STRUCT a_struct (*);
BEGIN
INT
var;
INT
buffer1[0:3];
STRING buffer2[0:4];
END;
INT .struct_ptr (a_struct) := @array;
END;
! Structure pointer
! contains address of
! array
HP pTAL Reference Manual—523746-006
10 -19
Declaring System Global Pointers
Pointers
Declaring System Global Pointers
Note. Only procedures that operate in privileged mode can access system global data.
The system global pointer declaration associates an identifier with a memory location
at which you store the address of a variable located in the system global data area.
type
.SG
;
identifier
preset-address
:=
,
VST020.vsd
type
is any data type except UNSIGNED; specifies the data type of the value to which
the pointer points.
.SG
is an indirection symbol (see Table 2-7 on page 2-7).
identifier
is the identifier of the pointer.
preset-address
is the address of a variable in the system global data area. The address is
determined by you or the system during system generation.
Example 10-20. System Global Pointer Declaration
INT .SG newname;
HP pTAL Reference Manual—523746-006
10 -20
11
Equivalenced Variables
Equivalencing lets you declare more than one identifier and description for a location in
a storage area. Equivalenced variables that represent the same location can have
different data types and byte-addressing and word-addressing attributes. For example,
you can refer to an INT(32) variable as two separate words or four separate bytes.
You can equivalence any variable in the first column of Table 11-1 on page 11-1 to any
variable in the second column.
Table 11-1. Equivalenced Variables
Equivalenced (New) Variable
Previous Variable
Simple variable
Simple pointer
Structure
Structure pointer
Simple variable
Simple pointer
Structure
Structure pointer
Array
Equivalenced variable
You can use an equivalenced variable in an expression anywhere an operand is valid.
Table 11-2. Equivalenced Variable Terminology (page 1 of 2)
Term
Definition
Equivalenced variable
The identifier that appears on the left side of an equivalenced
declaration; for example:
INT previous;
INT equivalenced = previous;
Previous variable
The identifier that appears on the right side of the equivalenced
declaration. The previous variable can, itself, be an equivalenced
variable; for example:
INT base_previous;
INT equivalenced1 = base_previous;
INT equivalenced2 = equivalenced1;
Direct equivalent
declaration
The equivalenced variable is a simple variable, direct array, direct
structure, standard pointer (including a standard structure
pointer), or extended pointer (including an extended structure
pointer). Direct items can be equivalenced only to other direct
items (with two exceptions).
Indirect equivalent
declaration
The equivalenced variable is a standard indirect array or standard
indirect structure. Standard indirect items can be equivalenced
only to other standard indirect items.
HP pTAL Reference Manual—523746-006
11- 1
Declaring Equivalenced Variables
Equivalenced Variables
Table 11-2. Equivalenced Variable Terminology (page 2 of 2)
Term
Definition
Extended
equivalent declaration
The equivalenced variable is an extended indirect array or
extended indirect structure. Extended indirect items can be
equivalenced only to other extended indirect items.
Standard pointer
equivalent declaration
The equivalenced variable is a pointer to data.
Extended pointer
equivalent declaration
The equivalenced variable is a pointer to data in an EXTADDR.
Topics:
•
•
•
•
•
•
Declaring Equivalenced Variables on page 11-2
Memory Allocation on page 11-4
Declaring Nonstructure Equivalenced Variables on page 11-5
Equivalencing PROCADDR Variables and PROCPTR Variables on page 11-15
Declaring Equivalenced Definition Structures on page 11-16
System Global Equivalenced Variable Declarations on page 11-22
Declaring Equivalenced Variables
Table 11-3. Valid Equivalenced Variable Declarations (page 1 of 2)
Equivalenced
Variable Category
Equivalenced
Variable
Variable Example
Previous Variable
Category
Direct
Simple Variable
INT i;
Direct or Pointer
Direct array
INT i[0:3];
Direct structure
STRUCT s;
BEGIN
INT i;
END;
Indirect array
INT .a[0:3];
Indirect structure
STRUCT .s;
BEGIN
INT i;
END;
Extended array
INT .EXT a[0:3];
Extended structure
STRUCT .EXT s;
BEGIN
INT i;
END;
Indirect
Extended
HP pTAL Reference Manual—523746-006
11- 2
Indirect
Extended
Declaring Equivalenced Variables
Equivalenced Variables
Table 11-3. Valid Equivalenced Variable Declarations (page 2 of 2)
Equivalenced
Variable Category
Equivalenced
Variable
Variable Example
Standard Pointer
Standard pointer
INT .p;
Standard structure
pointer
INT .s(t);
Extended pointer
INT .EXT e;
Extended structure
pointer
INT .EXT s(t);
Extended Pointer
Previous Variable
Category
A pointer, simple
variable, indirect
array, or indirect
structure
Direct or Extended
with the same
address type
(EXTADDR)
You can index a variable that participates in an equivalenced declaration either as the
equivalenced variable or as the previous variable even if none of the variables in the
equivalenced group specify array bounds.
Example 11-1. Declaring Equivalenced Variables
INT
INT
INT
INT
a;
b;
c = b;
d = c;
!
!
!
!
a is a simple variable, and cannot be indexed
"Previous variable" for the next decl
b and c can be indexed
c and d can be indexed
! Variables b, c, and d can be indexed because each appears in
! an equivalenced declaration:
c[2] := b[1];
d[2] := c[1];
d[2] := a;
a[1] := d;
!
!
!
!
!
OK: b and c appear in equivalenced declaration
OK: c and d appear in equivalenced declaration
OK: d appears in equivalenced declaration
and can be indexed.
ERROR: a cannot be indexed
HP pTAL Reference Manual—523746-006
11- 3
Memory Allocation
Equivalenced Variables
Memory Allocation
pTAL does not allocate memory for equivalenced variables. In the following example,
pTAL allocates memory only for base_previous:
INT base_previous;
INT equivalenced1 = base_previous;
INT equivalenced2 = equivalenced1;
An equivalenced variable is an alias for memory allocated for a previously declared
variable. The equivalenced declaration can specify different attributes; for example, a
different data type than those of the previous variable. In the following example, pTAL
allocates 32 bits for i. The equivalenced declaration for j references the memory
allocated for i, but specifies that the bits be treated as a REAL number:
INT(32) i;
REAL
j = i;
If an equivalenced variable is a standard or extended pointer and the previous variable
is the implicit pointer of an indirect array or indirect structure, the equivalenced variable
is a read-only pointer. You can use the value of the pointer in an expression, but you
cannot store an address or other value into the pointer because doing so would be the
same as storing an address into the implicit pointer of the array or structure. You can,
however, use a pointer to read or write the data to which the pointer points.
Example 11-2. Equivalenced Pointers
INT .a[0:3];
INT .p = a;
WADDR w;
PROC p1;
BEGIN
a[1] := a[1] + 1;
p[1] := p[1] + 1;
w := @a;
w := @p;
!
!
!
!
!
Increment second word of a
Increment second word of p (= a)
Assign address of first word of a to w
Assign address of first word of p (= a)
to w
END;
PROC p2;
BEGIN
@p := w;
! ERROR: Cannot assign to an equivalenced pointer
! when it is equivalenced to an indirect or
! standard indirect variable
END;
HP pTAL Reference Manual—523746-006
11- 4
Declaring Nonstructure Equivalenced Variables
Equivalenced Variables
Declaring Nonstructure Equivalenced
Variables
Nonstructure equivalenced declarations include simple variables, pointers, and arrays.
VOLATILE
type
identifier
=
referral
(
)
previous-identifier
;
[
index
+
offset
]
,
VST629.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
type
If referral is present, must be STRING or INT; otherwise, type is any data
type except UNSIGNED.
identifier
is the identifier of the equivalenced variable to be made equivalent to previousidentifier.
referral
is the identifier of a previously declared structure, structure layout, or structure
pointer.
HP pTAL Reference Manual—523746-006
11- 5
Declaring Nonstructure Equivalenced Variables
Equivalenced Variables
previous-identifier
the identifier of a previously-declared variable, direct array element, pointer,
structure, structure pointer, or equivalenced variable.
index
is an INT constant that specifies an element offset from previous-identifier
to which the equivalenced pointer or variable refers. Specify index only with
direct variables. index must end on a word boundary.
+
is the word or byte offset, relative to the base of previous-identifier, where
the equivalenced variable is placed. For example, if a and b are declared:
INT a[0:9];
INT b = a+5
then b is placed at a[5].
offset
is an INT constant that specifies a word offset from previous-identifier,
which can be a direct or indirect variable. If previous-identifier is indirect,
the offset is from the location of the pointer, not from the location of the data
pointed to.
The following are valid equivalenced declarations:
INT a;
INT b = a;
INT(32) c[0:3];
INT d[0:7] = c;
Topics:
•
•
•
•
•
Memory Usage for Nonstructured Equivalenced Variables on page 11-7
Equivalenced Arrays on page 11-7
Indirect Arrays on page 11-8
Equivalenced Simple Variables on page 11-8
Equivalenced Simple Pointers on page 11-10
HP pTAL Reference Manual—523746-006
11- 6
Memory Usage for Nonstructured Equivalenced
Variables
Equivalenced Variables
Memory Usage for Nonstructured Equivalenced Variables
The memory referenced by an equivalenced variable including all fields of an
equivalenced structure and all elements of an equivalenced array must be contained
entirely within the memory allocated for the previous variable. You can index the
previous variable, but the memory referenced after applying the index must be
contained within the memory allocated for the previous variable.
An equivalenced variable, including all elements of an equivalenced array or
equivalenced structure, must be the same size or smaller than the lowest-level
previous variable, even if an intermediate previous variable is not as the equivalenced
variable you are declaring:
INT
FIXED
INT
INT(32)
FIXED
h;
i;
j = i;
k = j;
l = h;
! OK: j is smaller than i
! OK: k is 32 bits, i is 64 bits
! ERROR: l > h
The number of bits in an equivalenced variable (including all elements of an array or
structure) must be less than or equal to the number of bits in the previous variable.
Equivalenced variables for which the previous variable is itself an equivalenced
variable, must be contained entirely within the memory allocated for the previous
variable for which the compiler allocates memory.
Example 11-3. Memory Usage for Nonstructured Equivalenced Variables
FIXED
INT(32)
INT
INT
i;
j[0:1] = i;
k[0:1] = i;
m[0:3] = k;
INT
FIXED
x[0:15];
y = x[10];
!
!
!
!
!
!
i is 64 bits
OK: j is 64 bits and coincident with i
OK: k is 32 bits and contained within i
OK: Although m is 64 bits and k is
32 bits, pTAL requires only that
m be contained within i, not k.
! ERROR: y does not fit entirely within x
Equivalenced Arrays
Use the lower-bnd1 and upper-bnd2 parameters as shown in the nonstructure
declaration syntax.
HP pTAL Reference Manual—523746-006
11- 7
Indirect Arrays
Equivalenced Variables
Indirect Arrays
Figure 11-1 on page 11-8 shows how pTAL implements indirect arrays. The compiler
allocates storage for the four elements of the array a, but not for a pointer to a.
References to a access the data directly not indirectly through a pointer.
Figure 11-1. Indirect Array
pTAL Indirect Array
INT .A[0:3] := [10,20,30,40];
! Object date type: INT
! Address type: WADDR
A: 1000
1001
1002
1003
10
20
30
40
VST121.vsd
Equivalenced Simple Variables
An equivalenced simple variable declaration associates a new simple variable with a
previously declared variable.
type
VOLATILE
identifier
=
referral
(
)
previous-identifier
;
[
index
+
offset
]
,
VST004.vsd
HP pTAL Reference Manual—523746-006
11- 8
Equivalenced Simple Variables
Equivalenced Variables
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
type
If referral is present, type must be STRING or INT; otherwise, type is any
data type except UNSIGNED.
identifier
is the identifier of the simple equivalenced variable to be made equivalent to
previous-identifier.
previous-identifier
is the identifier of a previously declared simple variable.
index
is an INT constant that specifies an element offset from previous-identifier,
which must be a direct variable. The data type of previous-identifier
dictates the element size. The location represented by index must begin on a
word boundary.
+
is the word or byte offset, relative to the base of previous-ident, where the
equivalenced variable is placed. For example, if a and b are declared:
INT(32) a[0:9];
INT b = a+6
then b is placed in the first six bits of a.
offset
is an INT constant that specifies an element offset from previous-identifier,
which must be a direct variable. The data type of previous-identifier
dictates the element size. The location represented by index must begin on a
word boundary.
Equivalencing a simple variable to an indirect array or structure is not recommended. If
you do so, the simple variable is made equivalent to the location of the implicit pointer,
not the location of the data pointed to.
In Figure 11-2 on page 11-10, a STRING variable and an INT(32) variable are
equivalenced to an INT array.
HP pTAL Reference Manual—523746-006
11- 9
Equivalenced Simple Pointers
Equivalenced Variables
Figure 11-2. Equivalenced Simple Variables
INT w[0:1];
STRING b = w[0];
INT(32) d = b;
w[0]
B[0]
B[1]
w[1]
B[2]
B[3]
D
VST302.vsd
Equivalenced Simple Pointers
An equivalenced simple pointer declaration associates a new simple pointer with a
previously declared variable.
type
VOLATILE
identifier
referral
(
)
.
.EXT
=
previous-identifier
.SG
.SGX
;
[
index
+
offset
]
,
VST630.vsd
VOLATILE
specifies that the value of this variable must be maintained in memory, not in a
register. Each reference to a VOLATILE data item causes the data item to be read
or written to memory even when code is optimized. Based on the order of reads
and writes in the source code, VOLATILE also causes that precise order of
memory references to be preserved, again, when code is optimized.
HP pTAL Reference Manual—523746-006
11 -10
Equivalenced Simple Pointers
Equivalenced Variables
type
is any data type except UNSIGNED. The data type determines how much data the
simple pointer can access at a time (byte, word, doubleword, or quadrupleword).
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of a simple pointer to be made equivalent to previousidentifier.
previous-identifier
is the identifier of a previously-declared variable, direct array element, pointer,
structure, structure pointer, or equivalenced variable.
index
is an INT constant that specifies an element offset from previous-identifier,
which must be a direct variable. The data type of previous-identifier
dictates the element size. The location represented by index must begin on a
word boundary.
+
is the word or byte offset, relative to the base of previous-ident, where the
equivalenced variable is placed. For example, if a and b are declared:
INT(32) a[0:9];
INT b = a+6
then b is placed in the first six bits of a.
offset
is an INT constant that specifies an element offset from previous-identifier,
which must be a direct variable. The data type of previous-identifier
dictates the element size. The location represented by index must begin on a
word boundary.
Topics:
•
•
Using Equivalenced Simple Pointers on page 11-12
REFALIGNED Clause for Equivalenced Simple Pointers on page 11-15
HP pTAL Reference Manual—523746-006
11 -11
Equivalenced Simple Pointers
Equivalenced Variables
Using Equivalenced Simple Pointers
If the previous variable is a pointer, an indirect array, or an indirect structure, the
previous pointer and the new pointer must both contain either:
•
•
•
A standard byte address
A standard word address
An extended address
Otherwise, the pointers will point to different locations, even if they both contain the
same value. That is, a standard STRING or extended pointer normally points to a byte
address, and a standard pointer of any other data type normally points to a word
address.
You can equivalence standard pointers to indirect arrays and indirect structures, but
you can only read the value of the pointer. You cannot store an address into the
pointer. You can, however, read or write the data to which the pointer points.
You can equivalence extended pointers to extended arrays and extended structures,
but you can only read the value of the pointer. You cannot store an address into the
pointer. You can, however, read or write the data to which the pointer points.
You can equivalence a standard pointer to an indirect array or indirect structure but you
cannot equivalence an indirect array or indirect structure to a standard pointer. A
pointer equivalenced to an indirect item is a read-only pointer—you can read the
address in the pointer, but you cannot store an address into the pointer.
Example 11-4. Read-Only Pointer
INT .a[0:3];
INT .b;
INT .c = a;
INT .d[0:3] = b;
@c := @c + 1;
!
!
!
!
!
!
!
!
Indirect array
Standard pointer
OK: Equivalence a pointer to an indirect
array (c is read-only)
ERROR: Cannot equivalence an indirect item
to a pointer
ERROR: Cannot modify a pointer that is
equivalenced to an indirect item
When you declare indirect and extended pointers in equivalenced declarations:
•
•
The address type of a STRING standard pointer is BADDR. The address type of all
other standard pointers is WADDR.
The address type of extended pointers is always EXTADDR, regardless of the data
type of the objects to which the pointer will refer.
Figure 11-3 on page 11-13 shows two examples of the data types associated with
pointers. Figure 11-3 on page 11-13 shows the object data type and address type. Use
Table 11-4 on page 11-13 to determine valid equivalenced declarations.
HP pTAL Reference Manual—523746-006
11 -12
Equivalenced Simple Pointers
Equivalenced Variables
Figure 11-3. The Object and Address Types of a Pointer
INT .EXT a;
12345
Object Data Type: INT
Address Type: EXTADDR
STRING .b;
"ABCDEFGHIJ"
Object Data Type: STRING
Address Type: BADDR
VST124.vsd
Table 11-4. Data Types for Equivalenced Variables
Example
Object Data Type
Address Type
INT
a;
INT
WADDR
INT
.b;
INT
WADDR
INT
.EXT c;
INT
EXTADDR
BADDR
d;
BADDR
WADDR
BADDR
.e;
BADDR
WADDR
BADDR
.EXT f;
BADDR
EXTADDR
EXTADDR
g;
EXTADDR
WADDR
EXTADDR
.h;
EXTADDR
WADDR
EXTADDR
.EXT i;
EXTADDR
EXTADDR
STRING
j;
STRING
BADDR
STRING
.k;
STRING
BADDR
STRINGs
.EXT l;
STRING
EXTADDR
HP pTAL Reference Manual—523746-006
11 -13
Equivalenced Simple Pointers
Equivalenced Variables
The code in Figure 11-4 on page 11-14 declares an INT(32) simple pointer equivalent
to an INT simple pointer. Both contain a word address.
Figure 11-4. Equivalenced Simple Pointer Declaration
INT
.ptr1 := 200;
INT(32) .ptr2 := ptr1;
ptr1 = 200
ptr2 = 200
.
.
.
G[200]
VST307.vsd
pTAL does not verify that the lengths of the objects to which an equivalenced pointer
refers are equal. pTAL accepts the declaration in Example 11-5 on page 11-14
because the address types of both pointers are WADDR.
Example 11-5. Equivalenced Objects of Unequal Length
INT
.a;
FIXED .b = a;
! a is a pointer to an INT
! OK: a and b are pointers; pTAL does not require
! that the data referenced by b be contained
! inside the data referenced by a
HP pTAL Reference Manual—523746-006
11 -14
Equivalencing PROCADDR Variables and
PROCPTR Variables
Equivalenced Variables
REFALIGNED Clause for Equivalenced Simple Pointers
The REFALIGNED clause assigns a REFALIGNED attribute (2 or 8) to a simple
equivalenced pointer when you declare the pointer. Equivalenced pointers do not
inherit the reference alignment of the previous variable.
Example 11-6. REFALIGNED Clause for Equivalenced Simple Pointers
?REFALIGNED(8)
INT .p REFALIGNED(2);
INT .q REFALIGNED(8) = p;
INT .r REFALIGNED(2) = p;
INT .s
= p;
INT .t;
!
!
!
!
!
!
Default reference alignment
Reference alignment of p is
Reference alignment of q is
Reference alignment of r is
Reference alignment of s is
Reference alignment of t is
is 8
2
8
2
8
8
Equivalencing PROCADDR Variables and
PROCPTR Variables
You can equivalence PROCPTR variables to PROCADDR and other PROCPTR, and
you can equivalence PROCADDR to PROCPTR and other PROCADDR.
Example 11-7. Equivalencing PROCADDR and PROCPTR Variables
PROCPTR a;
END PROCPTR;
! a is a procedure pointer
PROCADDR b;
! b is a procedure address
PROCADDR c = a;
! c is a procedure address equivalenced to a
! procedure pointer
PROCADDR d = b;
! d is a procedure address equivalenced to
! another procedure address
PROCPTR e;
END PROCPTR = a;
! e is a procedure pointer equivalenced to
! another procedure pointer
PROCPTR f;
END PROCPTR = b;
! f is a procedure pointer equivalenced to a
! procedure address
HP pTAL Reference Manual—523746-006
11 -15
Declaring Equivalenced Definition Structures
Equivalenced Variables
Declaring Equivalenced Definition Structures
An equivalenced definition structure declaration associates a new structure with a
previously declared variable.
identifier
STRUCT
referral
(
)
.
.EXT
.SG
.SGX
previous-identifier
=
field-alignment
;
[
index
+
offset
]
structure-layout
VST632.vsd
-
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
structure
is the identifier that the declaration creates.
referral
is the identifier of a previously declared structure, structure layout, or structure
pointer.
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
HP pTAL Reference Manual—523746-006
11 -16
Declaring Equivalenced Definition Structures
Equivalenced Variables
FIELDALIGN
specifies the memory alignment for the base of the structure and for fields
within the structure. For details about the FIELDALIGN clause, see Section 9,
Structures.
SHARED2
specifies that the base of the structure and each field in the structure must
begin at an even byte address except STRING fields.
SHARED8
specifies that the offset of each field in the structure from the base of the
structure must be begin at an address that is an integral multiple of the width of
the field.
AUTO
specifies that the structure and the fields of the structure be aligned according
to the optimal alignment for the architecture on which the program will run (this
is not the same behavior as the AUTO attribute has in the native mode HP C
compiler).
PLATFORM
specifies that the structure and the fields of the structure must begin at
addresses that are consistent across all languages on the same architecture.
previous-identifier
is the name of a previously declared simple variable, direct array element,
structure, structure layout, structure pointer, or equivalenced variable.
index
is an INT constant that specifies the offset of the element in previous-ident to
which the equivalenced pointer or variable refers. Specify index only with direct
variables. index must end on a word boundary.
+
is the word or byte offset, relative to the base of previous-ident, where the
equivalenced variable is placed. For example, if a and b are declared:
INT(32) a[0:9];
INT b = a+6
then b is placed in bytes 12 and 13 of a.
HP pTAL Reference Manual—523746-006
11 -17
Declaring Equivalenced Definition Structures
Equivalenced Variables
offset
is an INT constant that specifies a word offset. Specify offset only with indirect
variables. The offset is from the location of the pointer, not from the location of the
data pointed to.
structure-layout
is a BEGIN-END block that contains declarations. For more information about the
structure layout, See Section 9, Structures.
You must specify either referral or structure-layout but not both in an
equivalenced structure declaration.
You can specify a FIELDALIGN clause only if you specify structure-layout. You
cannot specify a FIELDALIGN clause for a referral structure.
Example 11-8. Declaring Equivalenced Structures
STRUCT a;
BEGIN
INT i;
INT j;
END;
STRUCT b = a;
BEGIN
INT(32) z;
END;
STRUCT c[0:3];
BEGIN
INT i;
INT j;
END;
STRUCT d[0:3] = c;
BEGIN
INT(32) z;
END;
HP pTAL Reference Manual—523746-006
11 -18
Declaring Equivalenced Definition Structures
Equivalenced Variables
The code in Figure 11-5 on page 11-19 declares an extended indirect definition
structure equivalent to a previously declared extended indirect structure.
Figure 11-5. Equivalenced Definition Structure for CISC Architecture
STRUCT .EXT xstrl;
BEGIN
STRING old_name[0:20];
STRING old_addr[0:50];
END;
STRUCT .EXT xstr2;
BEGIN
STRING new_name[0:30];
STRING new_addr[0:40];
END;
Primary area of user data segment
ptr to xstr1
ptr to xstr1
xstr1
.
.
.
xstr1
.
.
.
VST315.vsd
If the new structure is to occupy the same location as the previous variable, their
addressing modes must match. You can declare a direct or indirect structure
equivalent to the following previous variables:
New Structure
Previous Variable
Direct structure
Simple variable
Direct structure
Direct array
Standard indirect structure
Standard indirect structure
Standard indirect array
Standard structure pointer
Extended indirect structure
Extended indirect structure
Extended indirect array
Extended structure pointer
If the previous variable is a structure pointer, the new structure is really a pointer.
HP pTAL Reference Manual—523746-006
11 -19
Structure Variants
Equivalenced Variables
Topics:
•
•
•
Structure Variants on page 11-20
Memory Usage for Structured Equivalenced Variables on page 11-21
FIELDALIGN Clause on page 11-22
Structure Variants
You use substructures to declare variant records in structures. pTAL does not detect
addresses that are redefined by equivalenced variant structures.
Example 11-9. Structure Variants
STRUCT s FIELDALIGN(AUTO);
BEGIN
STRUCT v1;
BEGIN
INT .p;
! .p is 4 bytes
INT q;
END;
STRUCT v2 = v1;
BEGIN
INT .EXT e;
END;
END;
! v2 is equivalenced to v1
! v2 is 4 bytes
When you compile Example 11-9 on page 11-20, the compiler allocates 8 bytes, the
length of v1. Although v1 and v2 are different lengths and their fields have different
data types, the compiler does not report an error or a warning. You must ensure that
the variants are meaningful for your algorithms.
The structure in Example 11-10 on page 11-20 contains the same variants as the
structure in Example 11-9 on page 11-20, but the variants are in reverse order.
Example 11-10. Structure Variants
STRUCT s FIELDALIGN(AUTO);
BEGIN
STRUCT v1;
BEGIN
INT .EXT e; ! e is 4 bytes
END;
STRUCT v2 FIELDALIGN(SHARED8) = v1;
BEGIN
INT .p; ! p is 4 bytes
INT q; ! Compiler reports a warning
END;
END;
HP pTAL Reference Manual—523746-006
11 -20
Memory Usage for Structured Equivalenced
Variables
Equivalenced Variables
In Example 11-10 on page 11-20, v1 is 4 bytes, but v2 is 8 bytes. The compiler reports
a warning. Data that your program stores into s.v2.q overwrites the data in the
memory locations that follow s.
v2 is 8 bytes to maintain the alignment of variables in memory. For more information
about lengths of pTAL structures, see Section 9, Structures.
Memory Usage for Structured Equivalenced Variables
The memory referenced in an equivalenced declaration must fit within the memory
allocated for the previous variable. When you determine the length of a structure, you
must account for filler that pTAL adds to the structure. In Example 11-11 on
page 11-21, the equivalenced declaration is not valid because b is 4 bytes, but a is
only 3 bytes. pTAL adds an extra byte at the end of b so that its total length is an
integral multiple of its longest component, i.
Example 11-11. Memory Usage for Structured Equivalenced Variables (Incorrect)
STRUCT a
BEGIN
STRING
STRING
STRING
END;
FIELDALIGN(SHARED2);
! Structure a is 3 bytes
i;
j;
k;
STRUCT b FIELDALIGN(AUTO) = a; ! Structure b is 4 bytes
BEGIN
INT i;
STRING j; ! pTAL adds a byte after field j
END;
If you declare b and then declare a, pTAL does not report an error because a fits within
the four bytes already allocated for b, as in Example 11-12 on page 11-21.
Example 11-12. Memory Usage for Structured Equivalenced Variables (Correct)
STRUCT b FIELDALIGN(AUTO);
BEGIN
INT i;
STRING j; ! pTAL adds a byte after the declaration of j
END;
STRUCT a
BEGIN
STRING
STRING
STRING
END;
FIELDALIGN(SHARED2) = b;
i;
j;
k;
HP pTAL Reference Manual—523746-006
11 -21
FIELDALIGN Clause
Equivalenced Variables
FIELDALIGN Clause
The FIELDALIGN clause specifies the alignment of the fields of a structure and the
alignment of the structure itself in memory. You can use an equivalenced declaration to
create two layouts for the same area, one optimized for TAL programs on TNS
architecture and the other optimized for pTAL programs on TNS/R or TNS/E
architecture. Declare the pTAL structure first.
Example 11-13. FIELDALIGN Clause in Structured Equivalenced Variables
STRUCT a FIELDALIGN(SHARED8);
BEGIN
INT i;
INT j;
END;
STRUCT b FIELDALIGN(SHARED2) = a;
BEGIN
INT i;
INT j;
END;
In Example 11-13 on page 11-22, structures a and b declare the same fields, but a
specifies FIELDALIGN(SHARED8), the optimal alignment for pTAL, whereas b
specifies FIELDALIGN(SHARED2), the alignment for TAL. pTAL generates fast code
for references to a.i, but conservative code for references to b.i
For more information about using the FIELDALIGN clause, see Section 9, “Structures.”
System Global Equivalenced Variable
Declarations
Note. Only procedures that operate in privileged mode can access system global data.
System global equivalencing associates a global, local, or sublocal identifier with a
location that is relative to the base address. You can declare the following
equivalenced variables for either system global ('SG') or extended system global
('SGX') addresses:
•
•
•
•
•
Equivalenced Simple Variable on page 11-23
Equivalenced Definition Structure on page 11-24
Equivalenced Referral Structure on page 11-25
Equivalenced Simple Pointer on page 11-27
Equivalenced Structure Pointer on page 11-28
HP pTAL Reference Manual—523746-006
11 -22
Equivalenced Simple Variable
Equivalenced Variables
Equivalenced Simple Variable
An equivalenced simple variable declaration associates a simple variable with a
location that is relative to the 'SG' base address.
type
identifier
=
'SG'
;
[
index
+
offset
]
,
VST068.vsd
type
is any data type except UNSIGNED; specifies the data type of identifier.
identifier
is the identifier of a simple variable to be made equivalent to 'SG'.
'SG'
a symbol that denotes a 16-bit system global address.
index
is an INT constant that specifies the offset of the element in previous-ident to
which the equivalenced pointer or variable refers. Specify index only with direct
variables. index must end on a word boundary.
+
is the word or byte offset, relative to the base of previous-ident, where the
equivalenced variable is placed. For example, if a and b are declared:
INT a[0:9];
INT b = a+5
then b is placed at a[5].
offset
an equivalent INT values in the range 0 through 63.
HP pTAL Reference Manual—523746-006
11 -23
Equivalenced Definition Structure
Equivalenced Variables
Example 11-14. Equivalenced Simple Variable Declaration
INT item = 'SG' + 15;
Equivalenced Definition Structure
An equivalenced definition structure declaration associates a definition structure with a
location relative to a system global ('SG') or extended system global ('SGX') base
address.
identifier
STRUCT
=
'SG'
.EXT
.SG
.SGX
;
[
index
+
offset
structure-layout
;
]
VST710.vsd
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of a definition structure to be made equivalent to 'SG'.
'SG'
denotes a 16-bit system global address.
index
is an INT constant that specifies the offset of the element in previous-ident to
which the equivalenced pointer or variable refers. Specify index only with direct
variables. index must end on a word boundary.
HP pTAL Reference Manual—523746-006
11 -24
Equivalenced Referral Structure
Equivalenced Variables
+
is the word or byte offset, relative to the base of previous-ident, where the
equivalenced variable is placed. For example, if a and b are declared:
INT a[0:9];
INT b = a+5
then b is placed at a[5].
offset
an equivalent INT values in the range 0 through 63.
structure-layout
a BEGIN-END block that contains declarations for structure items.
Example 11-15. Equivalenced Definition Structure Declaration
STRUCT def_struct = 'SG'[10];
BEGIN
STRING out;
FIXED up;
REAL in;
END;
Equivalenced Referral Structure
The equivalenced referral structure declaration associates a referral structure with a
location relative to the base address of the system global ('SG') or the extended
system global ('SGX') data area.
identifier
STRUCT
(
referral
)
.SG
.SGX
.EXT
=
;
'SG'
[
index
+
offset
]
VST703.vsd
HP pTAL Reference Manual—523746-006
11 -25
Equivalenced Referral Structure
Equivalenced Variables
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of a referral structure to be made equivalent to 'SG'.
referral
is the identifier of a previously declared structure or structure pointer that is to
provide the layout for this structure.
'SG'
denotes a 16-bit system global address.
index
is an INT constant that specifies the offset of the element in previous-ident to
which the equivalenced pointer or variable refers. Specify index only with direct
variables. index must end on a word boundary.
+
is the word or byte offset, relative to the base of previous-ident, where the
equivalenced variable is placed. For example, if a and b are declared:
INT a[0:9];
INT b = a+5
then b is placed at a[5].
offset
an equivalent INT values in the range 0 through 63.
If you specify an indirection symbol (see Table 2-7, Indirection Symbols, on page 2-7),
the structure behaves like a structure pointer. If you do not specify an indirection
symbol, the structure has direct addressing.
Example 11-16. Equivalenced Referral Structure Declaration
STRUCT def_struct;
BEGIN
STRING a[0:99];
REAL b[0:9];
END;
STRUCT ref_struct (def_struct) = 'SG'[30];
HP pTAL Reference Manual—523746-006
11 -26
Equivalenced Simple Pointer
Equivalenced Variables
Equivalenced Simple Pointer
The equivalenced simple pointer declaration associates a simple pointer with a location
relative to the base address of the system global ('SG') or the extended system global
('SGX') data area.
type
identifier
=
'SG'
.SG
.SGX
.EXT
;
[
index
+
offset
]
,
VST704.vsd
type
is any data type except UNSIGNED and specifies the data type of the value to
which the pointer points.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of a simple pointer to be made equivalent to 'SG'.
'SG'
denotes a 16-bit system global address.
index
is an INT constant that specifies the offset of the element in previous-ident to
which the equivalenced pointer or variable refers. Specify index only with direct
variables. index must end on a word (16-bit) boundary.
HP pTAL Reference Manual—523746-006
11 -27
Equivalenced Structure Pointer
Equivalenced Variables
+
is the word or byte offset, relative to the base of previous-ident, where the
equivalenced variable is placed. For example, if a and b are declared:
INT a[0:9];
INT b = a+5
then b is placed at a[5].
offset
an equivalent INT values in the range 0 through 63.
Example 11-17. Equivalenced Simple Pointer Declaration
INT .ptr = 'SG' + 2;
Equivalenced Structure Pointer
The equivalenced structure pointer declaration associates a structure pointer with a
location relative to the base address of the system global (.SG) or the extended system
global (SGX) data area.
STRING
identifier
.
.SG
INT
.SGX
.EXT
(
referral
)
=
'SG'
;
[
index
+
offset
]
,
VST711.vsd
STRING
is the STRING attribute.
INT
is the INT attribute.
HP pTAL Reference Manual—523746-006
11 -28
Equivalenced Structure Pointer
Equivalenced Variables
.
.EXT
.SG
.SGX
are indirection symbols (see Table 2-7 on page 2-7).
identifier
is the identifier of a structure pointer to be made equivalent to 'SG'.
referral
is the identifier of a previously declared structure or structure pointer that is to
provide the layout for identifier.
'SG'
denotes a 16-bit system global address.
index
is an INT constant that specifies the offset of the element in previous-ident to
which the equivalenced pointer or variable refers. Specify index only with direct
variables. index must end on a word (16-bit) boundary.
+
is the word or byte offset, relative to the base of previous-ident, where the
equivalenced variable is placed. For example, if a and b are declared:
INT a[0:9];
INT b = a+5
then b is placed at a[5].
offset
an equivalent INT values in the range 0 through 63.
Table 10-1 on page 10-6 describes the kind of addresses a structure pointer can
contain depending on the STRING or INT attribute and addressing symbol.
Example 11-18. Equivalenced Structure Pointer Declaration
STRUCT .some_struct;
BEGIN
INT a;
INT b[0:5];
END;
INT .struct_ptr (some_struct) = 'SG' + 30;
HP pTAL Reference Manual—523746-006
11 -29
Equivalenced Structure Pointer
Equivalenced Variables
HP pTAL Reference Manual—523746-006
11 -30
12
Statements
Statements—also known as executable statements—perform operations in a program.
They can modify the program’s data or control the program’s flow.
Table 12-1. Summary of Statements
Category
Statement
Operation
Program
control
ASSERT
Conditionally calls a procedure
CALL
Calls a procedure or subprocedure
CASE
Selects a set of statements based on a selector
value
DO-UNTIL
A post-test loop that repeatedly executes a
statement until a specified condition becomes true
FOR
Executes a pretest loop n times
GOTO
Unconditionally branches to a label within a
procedure or subprocedure
IF
Conditionally selects one of two possible
statements
RETURN
Returns from a procedure or a subprocedure to
the caller; returns a value from a function; returns
a condition code value
WHILE
Executes a pretest loop while a condition is true
Data
transfer
Assignment
Stores a value in a variable
Bit-Deposit Assignment
Stores a value in a bit or in a group of sequential
bits
Data scan
SCAN and RSCAN
Scan data for a test character, left-to-right and
right-to-left, respectively
Data
allocation
DROP
Removes either a label (from the symbol table) or
a temporary variable that was created by a USE
statement
USE
Creates a temporary variable
In addition to the statements summarized in Table 12-1 on page 12-1, this section
describes:
•
•
Using Semicolons in Statements on page 12-2
Compound Statements on page 12-2
HP pTAL Reference Manual—523746-006
12- 1
Using Semicolons in Statements
Statements
Using Semicolons in Statements
You use semicolons with statements as follows:
•
•
•
•
A semicolon is required between successive statements.
A semicolon is optional before an END keyword that terminates a compound
statement.
A semicolon must not immediately precede an ELSE or UNTIL keyword.
A semicolon alone in place of a statement creates a null statement. The compiler
generates no code for null statements. You can use a null statement wherever you
can use a statement except immediately before an ELSE or UNTIL keyword.
Compound Statements
A compound statement is a BEGIN-END block that groups statements to form a single
logical statement.
BEGIN
END
statement
;
;
VST034.vsd
BEGIN
indicates the start of the compound statement.
statement
is a statement described in this section.
; (semicolon)
is a statement separator that is required between successive statements. A
semicolon before an END that terminates a compound statement is optional and
represents a null statement.
END
indicates the end of the compound statement.
You can use compound statements anywhere you can use a single statement. You can
nest them to any level in statements such as IF, DO, FOR, WHILE, or CASE.
HP pTAL Reference Manual—523746-006
12- 2
ASSERT
Statements
Example 12-1. Null Compound Statement
BEGIN
END;
Example 12-2. Compound Statement
BEGIN
a := b + c;
d := %B101;
f := d - e;
END;
ASSERT
The ASSERT statement conditionally calls the procedure specified in the active
directive ASSERTION on page 17-19.
ASSERT
assert-level
:
condition
VST035.vsd
assert-level
is an integer in the range 0 through 32,767.
If assert-level is greater than or equal to the assertion-level specified in
the active ASSERTION directive and if condition is true, the program calls the
procedure specified in the active ASSERTION directive.
condition
is a conditional expression (see Conditional Expressions on page 5-15).
To use the ASSERT statement and the ASSERTION directive together for debugging
or error-handling:
1. Put an ASSERTION directive in the source code, specifying an assertionlevel and an error-handling procedure.
2. Put an ASSERT statement at each place where you want to execute the errorhandling procedure when an error occurs. In each ASSERT statement, specify:
°
°
An assert-level that is greater than or equal to the assertion-level
A condition that will be true when an error occurs
During program execution, if an assert-level is greater than or equal to the active
assertion-level and the associated condition is true, the program calls the
error-handling procedure.
HP pTAL Reference Manual—523746-006
12- 3
Assignment
Statements
Example 12-3 on page 12-4 calls PROCESS_DEBUG_ whenever a carry or overflow
condition occurs.
Example 12-3. ASSERTION Directive and ASSERT Statement
?SOURCE $SYSTEM.SYSTEM.EXTDECS (PROCESS_DEBUG_)
?ASSERTION 5, PROCESS_DEBUG_
! Activates all ASSERT conditions
SCAN array WHILE " " -> @pointer;
ASSERT 10 : LOCAL_CARRY_FLAG;
!Lots of code
ASSERT 10 : LOCAL_CARRY_FLAG;
!More code
ASSERT 20 : LOCAL_OVERFLOW_FLAG;
! $OVERFLOW routine tests for
!
arithmetic overflow
In Example 12-3 on page 12-4:
•
•
If you change the assertion-level from 5 to 15, you nullify the two ASSERT
statements that specify assert-level 10 and the LOCAL_CARRY_FLAG
condition.
If you change the assertion-level from 5 to 30, you nullify all the ASSERT
statements.
If all ASSERT statements that cover a particular condition have the same assertlevel, it is easier to nullify specific levels of ASSERT statements.
Assignment
The assignment statement assigns a value to a previously declared variable.
variable
:=
expression
VST012.vsd
variable
is the identifier of a simple variable, array element, simple pointer, structure
pointer, or structure data item, with or without a bit deposit field and/or index. To
update a pointer’s content, prefix the pointer identifier with @.
HP pTAL Reference Manual—523746-006
12- 4
Assignment
Statements
expression
is either:
•
•
An arithmetic expression of the same data type as variable
A conditional expression, which always has an INT result
expression can be a bit extraction value or an identifier prefixed with @ (the
address of a variable). expression cannot be a constant list.
In general, the data types of variable and expression must match. To
convert the data type of expression to match the data type of variable, use a
type-transfer routine, described in Section 15, Built-In Routines.
The following rules apply to assignment statements:
•
•
•
•
•
•
The data type of the expression on the right side of an assignment statement must
be compatible with the data type of the destination on the left side of the
assignment statement.
You cannot store a value into the implicit pointer of an indirect array or indirect
structure.
You cannot store a value into the implicit pointer of an equivalenced variable that
references the data of an indirect array or indirect structure.
Do not depend on whether the left side or the right side of an assignment
statement is evaluated first.
Address types must match.
pTAL disallows all assignments of unlike data types except the following:
°
STRING and UNSIGNED(1-16) variables are syntactically and semantically
equivalent to INT variables. Thus, STRING and UNSIGNED(1-16) variables
are valid anywhere an INT variable is valid.
An UNSIGNED(1-16) variable or one-byte STRING value that is used as an
INT value is left-filled with binary zeros. Conversely, the high-order bits of an
INT value are lost if the value is stored in an UNSIGNED variable that is less
than 16 bits, or to a one-byte STRING variable, as shown in the following
examples:
INT
STRING
UNSIGNED(12)
UNSIGNED(24)
s
i
u1
u2
:=
:=
:=
:=
i := 3;
s;
u1;
u2;
i + 1;
s + %H20;
i + s;
i;
!
!
!
!
!
OK: Assignment of INT to STRING
OK: Assignment of STRING to INT
OK: INT + STRING
ERROR: INT and UNSIGNED(17-31) are not
assignment-compatible
HP pTAL Reference Manual—523746-006
12- 5
Pointer Assignment
Statements
When an INT variable is assigned to a STRING variable, the upper 8 bits of the
INT variable are not retained in any way in the STRING variable. Thus, the
comparison of i1 to i2 in the final statement of the following code fails
because i2 still holds the full 16 bits that were assigned to it at the beginning
of the code, but i1 holds only the lower 8 bits. The upper 8 bits of I1 are not
transferred to s in the assignment statement s := i1.
INT i1 := %HFFFF,
i2;
STRING s;
i2
s
i1
IF
°
:=
:=
:=
i1
i1;
i1;
s;
= i2 THEN;
!
!
!
!
Copy i1 to i2
Assign 16-bit INT to 8-bit STRING
Assign 8-bit STRING to 16-bit INT
i1 (%HFF) is not equal to i2 (%HFFFF)
UNSIGNED(17-31) variables are syntactically and semantically equivalent to
INT(32) variables. Thus, UNSIGNED(17-31) variables are valid anywhere
INT(32) variables are valid:
INT(32)
i;
UNSIGNED(31) u;
INT
j;
i := u;
u := i;
u := j;
! OK: No bits are lost in assignment
! WARNING: Most significant bit of i could
! be lost
! ERROR: INT and UNSIGNED(17-31) are not
! assignment-compatible
Topics:
•
•
•
•
Pointer Assignment on page 12-6
Assigning Numbers to FIXED Variables on page 12-7
Assigning Character Strings on page 12-7
Examples on page 12-8
Pointer Assignment
The result of applying an @ operator to a variable or pointer is an address whose data
type is one of the pTAL address types.
In an assignment statement, one of the following must be true:
•
•
Both operands are the same address type.
Neither operand is an address type.
HP pTAL Reference Manual—523746-006
12- 6
Assigning Numbers to FIXED Variables
Statements
You can use type-conversion built-in routines to convert some address types to other
address types. For more information:
Topic
See ...
Type-conversion built-in routines
Section 15, Built-In Routines
Converting addresses
Section 5, Expressions
Pointers
Section 10, Pointers
Assigning Numbers to FIXED Variables
When you assign a number to a FIXED variable, the system scales the value up or
down to match the fpoint value. If the system scales the value down, you lose some
precision depending on the amount of scaling; for example:
FIXED(2) a;
a := 2.348F;
! System scales value to 2.34F
If the ROUND directive is active, the system scales the value as needed, then rounds
the value away from zero as follows:
(IF value < 0 THEN value - 5 ELSE value + 5) / 10
For example, if you assign 2.348F to a FIXED(2) variable, the ROUND directive scales
the value by one digit and then rounds it to 2.35F.
Assigning Character Strings
You can assign a character string to STRING, INT, or INT(32) variables.
If you assign a one-character string such as "A" to an INT simple variable, the system
places the value in the right byte of a word and 0 in the left byte. To store a character in
the left byte, assign the character and a space, as in:
"A "
If you assign a character string to a FIXED, REAL, or REAL(64) variable, the compiler
issues a type incompatibility error.
HP pTAL Reference Manual—523746-006
12- 7
Examples
Statements
Examples
Example 12-4. Assignment Statements
INT array[0:2];
INT .ptr;
REAL real_var;
! Array
! Simple pointer
! REAL variable
FIXED fixed_var;
! FIXED variable
array[2] := 255;
! Assign a value to array[2]
@ptr := @array[1];
! Assign address of array[1]
! to ptr
ptr := array[2];
! Assign value of array[2]
! to array[1], to which ptr
! points
real_var := 36.6E-3;
! Assign a REAL value to a
! REAL variable
fixed_var := $FIX (real_var);
! Convert a REAL value to FIXED
! and assign to a FIXED variable
Assignment statements can assign character strings but not constant lists, so in
Example 12-5 on page 12-8, the three assignment statements together store the same
value as the one constant list in the declaration.
Example 12-5. Assignment Statements Equivalent to a Constant List
INT .b[0:2] := ["ABCDEF"];
! Declare and initialize
! with constant list
b[0] := ["AB"];
b[1] := ["CD"];
b[2] := ["EF"];
In Example 12-6 on page 12-8, the first assignment statement (which contains
assignment expressions) is equivalent to the three separate assignments that follow it.
Example 12-6. Assignment Statement With Assignment Expressions
INT
INT
INT
INT
int1;
int2;
int3;
var := 16;
int1 := int2 := int3 := var;
! Assignment that contains
! assignment expressions
int1 := var;
int2 := var;
int3 := var;
! Separate assignments
HP pTAL Reference Manual—523746-006
12- 8
Bit-Deposit Assignment
Statements
Bit-Deposit Assignment
The bit deposit form of the assignment statement lets you assign a value to an
individual bit or to a group of sequential bits.
variable
.
<
>
left-bit
:
:=
right-bit
expression
VST037.vsd
variable
is the identifier of a STRING or INT variable, but not an UNSIGNED(1-16) variable.
variable can be the identifier of a simple variable, array element, or simple
pointer (inside or outside a structure).
left-bit
is an INT constant that specifies the leftmost bit of the bit deposit field.
For STRING variables, specify a bit number in the range 8 through 15. Bit 8 is the
leftmost bit in a STRING variable; bit 15 is the rightmost bit.
right-bit
is an INT constant specifying the rightmost bit of the bit deposit field. right-bit
must be equal to or greater than left-bit.
For STRING variables, specify a bit number in the range 8 through 15. Bit 8 is the
leftmost bit in a STRING variable; bit 15 is the rightmost bit.
expression
is an INT arithmetic or conditional expression, with or without a bit field
specification.
The bit deposit field is on the left side of the assignment operator (:=). The bit deposit
assignment changes only the bit deposit field. If the value on the right side has more
bits than the bit deposit field, the system ignores the excess high-order bits when
making the assignment.
Specify the variable/bit-field construct with no intervening spaces as shown:
myvar.<0:5>
Do not use bit deposit fields to pack data. Instead, declare an UNSIGNED variable and
specify the appropriate number of bits in the bit field.
HP pTAL Reference Manual—523746-006
12- 9
CALL
Statements
Examples:
1. The bit deposit assignment sets bits 3 through 7 of the word designated by x:
INT x;
x.<3:7> := %B11111;
2. The bit deposit assignment replaces bits <10> and <11> with zeros:
INT old := -1;
old.<10:11> := 0;
! old = %b1111111111111111
! old = %b1111111111001111
3. The bit deposit assignment sets bit <8>, the leftmost bit of strng, to 0:
STRING strng := -1;
strng.<8> := 0;
! strng = %b11111111
! strng = %b01111111
4. The value %577 is too large to fit in bits <7:12> of var. The system truncates
%577 to %77 before performing the bit deposit:
INT var := %125252;
var.<7:12> := %577;
! var
! %77
! var
= %b1010101010101010
= %b0000000101111111
= %b1010101111111010
5. The bit deposit assignment replaces bits <7:8> of new with bits <8:9> of old:
INT new := -1;
INT old := 0;
new.<7:8> := old.<8:9>;
! new = %b1111111111111111
! old = %b0000000000000000
! new = %b1111111001111111
CALL
The CALL statement calls a procedure, subprocedure, or entry-point identifier and
optionally passes parameters to it.
In pTAL, a procedure’s formal and actual parameters either match if the data type of
each formal parameter and its corresponding actual parameter match exactly or match
if the data type of the actual parameter is converted according to the rules under
Converting Between Address Types on page 3-7.
identifier
CALL
(
)
param-name
param-pair
,
VST038.vsd
identifier
is the identifier of a previously declared procedure, subprocedure, or entry-point
identifier.
HP pTAL Reference Manual—523746-006
12 -10
CALL
Statements
param-name
is a variable identifier or an expression that defines an actual parameter to pass to
a formal parameter declared in identifier.
param-pair
is an actual parameter pair to pass to a formal parameter pair declared in
identifier. param-pair has the form:
string
:
length
VST039.vsd
string
is an expression of the type STRING . or STRING .EXT.
length
is an INT expression that specifies the length, in bytes, of string.
Use the CALL statement to call procedures and subprocedures (but usually not
functions).
To call functions, you usually use their identifiers in expressions. If you call a function
by using a CALL statement, the caller does not use the returned value of the function.
Actual parameters are value or reference parameters and are optional or required
depending on the formal parameter specification in the called procedure or
subprocedure declaration (described in Section 14, Procedures, Subprocedures, and
Procedure Pointers). A value parameter passes the content of a location; a reference
parameter passes the address of a location.
In a CALL statement to a VARIABLE procedure or subprocedure or to an
EXTENSIBLE procedure, you can omit optional parameters in two ways:
•
•
You can omit parameters or parameter pairs unconditionally. Use an empty comma
for each omitted parameter or parameter pair up to the last specified parameter or
parameter pair. If you omit all parameters, you can specify an empty parameter list
(parentheses with no commas) or you can omit the parameter list altogether.
You can omit parameters or parameter pairs conditionally. Use the $OPTIONAL
built-in routine as described in Section 15, Built-In Routines.
After the called procedure or subprocedure completes execution, control returns to the
statement following the CALL statement that calls the procedure or subprocedure.
HP pTAL Reference Manual—523746-006
12 -11
CASE
Statements
Example 12-7. CALL Statement
PROC p (a,
INT(32)
REAL
REAL(64)
BEGIN
END;
b, c);
a;
b;
c;
PROC q;
BEGIN
CALL p(1.0E0, ! ERROR: Cannot pass REAL to INT(32)
1D,
! ERROR: Cannot pass INT(32) to REAL
1F);
! ERROR: Cannot pass FIXED
to REAL(64)
END;
CASE
The CASE statement executes a choice of statements based on a selector value.
Normally, you use labeled CASE statements. Labeled CASE statements are described
first, followed by unlabeled CASE statements.
If a case index does not match any alternative, an instruction trap occurs.
Topics:
•
•
•
Empty CASE on page 12-12
Labeled CASE on page 12-13
Unlabeled CASE on page 12-15
Empty CASE
pTAL does not allow empty CASE statements. A CASE statement include at least one
alternative, even if there are no statements specified for that alternative.
Example 12-8. Empty CASE Statement
CASE i OF
BEGIN
;
END;
! In this unlabeled CASE statement,
! the semicolon creates an alternative
HP pTAL Reference Manual—523746-006
12 -12
Labeled CASE
Statements
Labeled CASE
The labeled CASE statement executes a choice of statements when the value of the
selector matches a case label associated with those statements.
selector
CASE
OF
BEGIN
case-alternative
;
END
->
OTHERWISE
;
statement-2
VST041.vsd
selector
is an INT or INT (32) value arithmetic expression that uniquely selects the casealternative for the program to execute.
case-alternative
associates one or more case-label s or one or more ranges of case-label s
with one or more statement s. The statement s of a case-alternative are
executed if selector equals an associated case-label. Each casealternative has the form:
case-label
lower-case-label
->
..
upper-case-label
,
statement-1
;
VST042.vsd
case-label
a signed INT constant or LITERAL. Each case-label must be unique in the
CASE statement.
lower-case-label
is the smallest value in an inclusive range of signed INT constants or
LITERALs.
HP pTAL Reference Manual—523746-006
12 -13
Labeled CASE
Statements
upper-case-label
is the largest value in an inclusive range of signed INT constants or LITERALs.
statement-1
is any statement described in this section.
OTHERWISE
specifies an optional sequence of statements to execute if selector does not
select any case-alternative. If no OTHERWISE clause is present and
selector does not match a case-alternative, a run-time error occurs.
Always include an OTHERWISE clause, even if it contains no statements.
statement-2
is any statement described in this section.
A CASE statement must have at least one alternative.
If you omit the OTHERWISE clause and selector is out of range (negative or
greater than n), the a divide-by-zero instruction trap occurs.
A CASE index matches an alternative identified by the keyword OTHERWISE if and
only if the case index does not match any other alternative and OTHERWISE is an
alternative.
Example 12-9. Labeled CASE Statement
LITERAL apple, orange, pear, peach, prune;
INT i;
i := peach;
! Set index value
CASE i OF
BEGIN
apple
orange
prune
OTHERWISE
END;
! Execute CASE
->
->
->
->
CALL
CALL
CALL
CALL
p1;
p2;
p3;
p4;
! Execute this alternative
HP pTAL Reference Manual—523746-006
12 -14
Unlabeled CASE
Statements
Example 12-10. Labeled CASE Statement
INT location;
LITERAL bay_area, los_angeles, hawaii, elsewhere;
PROC area_proc (area_code);
INT area_code;
!
BEGIN
!
CASE area_code OF
!
BEGIN
408, 415 ->
location := bay_area;
213, 818 ->
location := los_angeles;
808 ->
location := hawaii;
OTHERWISE ->
location := elsewhere;
END;
!
END;
!
Declare selector as
formal parameter
Selector is area_code
End CASE statement
End area_proc
Unlabeled CASE
The unlabeled CASE statement executes a choice of statements, based on an
inclusive range of implicit selector values, from 0 through n, with one statement for
each value.
CASE
selector
OF
BEGIN
;
statement-1
END
OTHERWISE
;
statement-2
VST040.vsd
selector
is an INT or INT (32) arithmetic expression that selects the statement to execute.
HP pTAL Reference Manual—523746-006
12 -15
Unlabeled CASE
Statements
statement-1
is any statement described in this section. Include a statement-1 for each value
in the implicit selector range, from 0 through n. If a selector has no action,
specify a null statement (semicolon with no statement). If you include more than
one statement-1 for a value, you must use a compound statement.
OTHERWISE
indicates the statement to execute for any case outside the range of selector
values. If the OTHERWISE clause consists of a null statement, control passes to
the statement following the unlabeled CASE statement.
statement-2
is any statement described in this section. Include a statement-2 for each value
in the implicit selector range, from 0 through n. If a selector has no action,
specify a null statement (semicolon with no statement). If you include more than
one statement-2 for a value, you must use a compound statement.
The compiler numbers each statement in the BEGIN clause consecutively, starting
with 0. If the selector matches the compiler-assigned number of a statement, that
statement is executed. For example, if the selector is 0, the first statement
executes; if the selector is 4, the fifth statement executes. Conversely, if the
selector does not match a compiler-assigned number, the OTHERWISE
statement, if any, executes.
The index of an unlabeled CASE statement and the selector of a labeled CASE
statement can be INT(32) expressions.
Example 12-11. Unlabeled CASE Statement
INT(32) i;
CASE i OF
BEGIN
...
END;
CASE i OF
BEGIN
0-> ...
1-> ...
END;
If you omit the OTHERWISE clause and selector is out of range (negative or
greater than n), a divide-by-zero instruction trap occurs.
HP pTAL Reference Manual—523746-006
12 -16
DO-UNTIL
Statements
Example 12-12. Unlabeled CASE Statement
INT selector;
INT var0;
INT var1;
CASE selector OF
BEGIN
var0 := 0;
var1 := 1;
OTHERWISE
CALL error_handler;
END;
! Executes if selector=0
! Executes if selector=1
! Executes if selector is not 0 or 1
Example 12-13 on page 12-17 selectively moves one of several messages into an
array.
Example 12-13. Unlabeled CASE Statement Assigning Text to Array
PROC msg_handler (selector);
INT selector;
BEGIN
LITERAL len = 80;
! Length of array
STRING .a_array[0:len - 1]; ! Destination array
CASE selector OF
BEGIN
! Move statements
!0! a_array ':=' "Training Program";
!1! a_array ':=' "End of Program";
!2! a_array ':=' "Input Error";
!3! a_array ':=' "Home Terminal Now Open";
OTHERWISE
a_array ':=' "Bad Message Number";
END;
! End of CASE statement
END;
! End of procedure
DO-UNTIL
The DO-UNTIL statement is a posttest loop that repeatedly executes a statement until
a specified condition becomes true.
DO
UNTIL
condition
statement
VST046.vsd
statement
is any statement described in this section.
HP pTAL Reference Manual—523746-006
12 -17
DO-UNTIL
Statements
condition
is either:
•
•
A conditional expression
An INT, INT(32), or FIXED arithmetic expression. If the result of the arithmetic
expression is not 0, condition is true. If the result is 0, condition is false.
If condition is false, the DO-UNTIL statement continues to execute. If
condition is true, the statement following the DO-UNTIL statement executes.
A DO-UNTIL statement always executes at least once (unlike the WHILE on
page 12-45).
In Example 12-14 on page 12-18, the DO-UNTIL statement loops through array_a,
testing the content of each element until an alphabetic character occurs.
Example 12-14. DO-UNTIL Statement
index := -1;
DO index := index + 1 UNTIL $ALPHA (array_a[index]);
In Example 12-15 on page 12-18, the DO-UNTIL statement loops through array_a,
assigning a 0 to each element until all the elements contain a 0.
Example 12-15. DO-UNTIL Statement
LITERAL limit = 9;
INT index := 0;
STRING .array_a[0:limit];y
DO
BEGIN
array_a[index] := 0;
index := index + 1;
END
UNTIL index > limit;
! Compound statement to execute in
! DO loop
! Condition for ending loop
The conditional expression cannot reference hardware indicators (<, <=, =, <>, >, >=,
'<', '<=', '=', '<>', '>', '>=', $OVERFLOW, and $CARRY). Only IF statements can test
hardware indicators. For more information, see Section 13, Hardware Indicators.
To use a hardware indicator’s value to control a DO-UNTIL loop, save the hardware
indicator’s value and either test the saved value (as in Example 12-16 on page 12-19)
or execute an explicit GOTO statement to exit the loop (as in Example 12-17 on
page 12-19). Hardware indicators cannot appear in the conditional expression of a DOUNTIL statement.
HP pTAL Reference Manual—523746-006
12 -18
DROP
Statements
Example 12-16. DO-UNTIL Statement With Hardware Indicator
INT exit_loop;
...
exit_loop := FALSE;
DO
BEGIN
...
READ(...);
IF <> THEN exit_loop := TRUE;
END
UNTIL exit_loop;
Example 12-17. DO-UNTIL Statement With GOTO Statement
DO
BEGIN
...
READ(...);
IF <> THEN GOTO out;
END
UNTIL false;
out:
...
DROP
The DROP statement removes either a label (from the symbol table) or a temporary
variable that was created by the statement USE on page 12-45.
DROP
identifier
,
VST047.vsd
identifier
is the identifier of either a label or a temporary variable.
Dropping Labels
You can drop a label only if you have already declared the label or used it to label a
statement. Before you drop a label, be sure there are no further references to the label.
If a GOTO statement refers to a dropped label, a run-time error occurs. After you drop
a label, you can, however, use the identifier to label a statement preceding the GOTO
statement that refers to the label.
HP pTAL Reference Manual—523746-006
12 -19
Dropping Temporary Variables
Statements
Dropping Temporary Variables
When you no longer need a temporary variable, drop (remove) it by using a DROP
statement. After you drop a temporary variable, do not use its identifier without using a
new USE statement to assign a value to the temporary variable.
If you do not drop all temporary variables, the compiler automatically drops them when
the procedure or subprocedure completes execution.
If you reserve an temporary variable for a FOR loop, do not drop the temporary
variable within the scope of the loop.
FOR
The FOR statement is a pretest loop that repeatedly executes a statement while
incrementing or decrementing an index automatically.
FOR
index
:=
TO
initial-value
limit
DOWNTO
DO
BY
step
statement
VST048.vsd
index
is a value that increments or decrements automatically.
In Standard on page 12-21, index is the identifier of an INT or INT(32) simple
variable, array element, simple pointer, or structure data item.
In Optimized on page 12-22, index is the identifier of an index register you have
reserved with the USE on page 12-45.
initial-value
is an arithmetic expression (such as 0) that initializes index. If index is INT,
initial-value is INT. If index is INT(32), initial-value is INT(32).
TO
increments index each time the loop executes until index is greater than or
equal to limit, at which point the loop stops.
DOWNTO
decrements index each time the loop executes until index is less than or equal
to limit, at which point the loop stops.
HP pTAL Reference Manual—523746-006
12 -20
Nested
Statements
limit
is an arithmetic expression that terminates the loop. If index is INT, initialvalue is INT. If index is INT(32), initial-value is INT(32).
step
is an arithmetic expression by which to increment or decrement index each time
the loop executes. If index is INT, then step is INT; otherwise, index is
INT(32). The default is 1.
statement
is any statement described in this section.
The FOR statement tests index at the beginning of each iteration of the loop. If
index exceeds limit on the first test, the loop never executes.
Topics:
•
•
•
Nested on page 12-21
Standard on page 12-21
Optimized on page 12-22
Nested
You can nest FOR statements to any level.
The nested FOR statement in Example 12-18 on page 12-21 uses multiples as a
two-dimensional array. It fills the first row with multiples of 1, the next row with multiples
of 2, and so on.
Example 12-18. Nested FOR Statement
INT .multiples[0:10*10-1];
INT row;
INT column;
FOR row := 0 TO 9 DO
FOR column := 0 TO 9 DO
multiples [row * 10 + column] := column * (row + 1);
Standard
For index, standard FOR statements specify an INT or INT(32) variable. Standard
FOR statements execute as follows:
•
When the looping terminates, index is greater than limit if:
°
°
°
The step value is 1.
You use the TO keyword (not DOWNTO).
The limit value (not a GOTO statement) terminates the looping.
HP pTAL Reference Manual—523746-006
12 -21
Optimized
Statements
•
limit and step are recomputed at the start of each iteration of the statement.
The standard FOR statement in Example 12-19 on page 12-22 uses the DOWNTO
clause to reverse a string from "BAT" to "TAB".
Example 12-19. Standard FOR Statement
LITERAL len = 3;
LITERAL limit = len - 1;
STRING .normal_str[0:limit] := "BAT";
STRING .reversed_str[0:limit];
INT index;
FOR index := limit DOWNTO 0 DO
reversed_str[limit - index] := normal_str[index];
Optimized
For index, an optimized FOR statement specifies a temporary variable created by the
statement USE on page 12-45. Optimized FOR statements execute faster than
standard FOR statements because limit is computed only once, at the start of the first
iteration of the statement.
Example 12-20. Standard and Optimized FOR Statements (page 1 of 2)
INT x;
INT y;
INT PROC f;
BEGIN
x := x + 1;
RETURN 10;
END;
INT PROC p1;
BEGIN
INT i;
x := 0;
FOR i := 1 to f() DO ... ;
RETURN x;
END;
! p1 has standard FOR statement
! f is called 10 times
! i=11 here
! p1 returns 10
INT PROC q;
BEGIN
x := y + 1;
RETURN 10;
END;
HP pTAL Reference Manual—523746-006
12 -22
GOTO
Statements
Example 12-20. Standard and Optimized FOR Statements (page 2 of 2)
INT PROC p2;
BEGIN
USE i;
y := 0;
FOR i := 1 to q() DO ... ;
RETURN x;
END;
! p2 has optimized FOR statement
! q is called 1 time
! i=10 here
! p2 returns 1
GOTO
The GOTO statement unconditionally transfers control to a labeled target statement.
GOTO
label-name
VST049.vsd
label-name
is the label that precedes the target statement (see Labels in Procedures on
page 14-37).
A GOTO statement can be either local or nonlocal.
Topics:
•
•
•
Local on page 12-23
Nonlocal on page 12-24 (not recommended)
GOTO and Target Statements With Different Trapping States on page 12-24
Local
If the GOTO statement and the target statement are in the same procedure or in the
same subprocedure, the GOTO statement is local.
Example 12-21. Local GOTO Statement
PROC p
BEGIN
LABEL calc_a;
INT a;
INT b := 5;
calc_a :
a := b * 2;
! Lots of code
GOTO calc_a;
END;
! Declare local label
! Place label at local statement
! Local branch to local label
HP pTAL Reference Manual—523746-006
12 -23
Nonlocal
Statements
Nonlocal
Note. Nonlocal GOTO statements are are inefficient and not recommended.
If the GOTO statement is in a subprocedure and the target statement is in the
enclosing procedure, the GOTO statement is nonlocal.
Example 12-22. Nonlocal GOTO Statement
int global_var;
proc p;
begin
int
i;
label L1;
int subproc s (x);
int (x);
begin
label L2:
if x = 0 then goto L1;
if x > 10 goto L2;
return 1;
! Nonlocal goto
! Local goto
L2: return x;
end;
i := s (global_var);
if i <> 1 then goto L1;
! Local goto
! Processing occurs here
L1:
end;
GOTO and Target Statements With Different Trapping States
A GOTO statement, local or nonlocal, must have the same trapping state as its target
statement.
Example 12-23. Local GOTO and Target Statements That Have Different Trapping
States
proc p nooverflow_traps;
begin
subproc s overflow_traps;
begin
goto L1; ! Illegal trapping states differ
end;
L1:
end;
HP pTAL Reference Manual—523746-006
12 -24
GOTO and Target Statements With Different
Trapping States
Statements
If a GOTO statement and the target statement are in different BEGIN-END blocks:
•
You must declare the target label in a LABEL declaration in the containing
procedure.
Note. LABEL is an invalid data type for a formal parameter. You cannot pass a label as an
actual parameter.
•
•
Overflow trapping must be enabled in both blocks or disabled in both blocks. The
respective overflow trapping states can be established by compiler directive, by
procedure attribute, or by BEGIN-END block attribute.
A GOTO statement in a BEGIN-END block that does not specify a block-level
trapping attribute cannot branch to a label in a BEGIN-END block in which a blocklevel trapping attribute is specified.
The compiler uses attributes on BEGIN-END blocks to determines whether a GOTO
within one BEGIN-END block can branch to a label in another BEGIN-END block.
For more information, see Section 13, Hardware Indicators.
Example 12-24. Nonlocal GOTO and Target Statements That Have Different
Trapping States
PROC p OVERFLOW_TRAPS;
BEGIN
INT i := 0;
label_a:
! Overflow traps are enabled at label_a
i := i + 1;
IF i < 10 THEN
GOTO label_a
! OK: Traps enabled here and at label_a
ELSE
BEGIN:ENABLE_OVERFLOW_TRAPS
GOTO label_a;
! OK: Branch from block with traps
IF i <> 1 THEN ! specified
BEGIN
label_b: ...
END;
END;
BEGIN:DISABLE_OVERFLOW_TRAPS
GOTO label_b;
! ERROR: Cannot branch between blocks
END;
! that have different trapping states
BEGIN
GOTO label_b;
END;
END;
! ERROR: Cannot branch from a BEGIN-END
! block that does not specify a trapping
! attribute to a BEGIN-END block that
! does
HP pTAL Reference Manual—523746-006
12 -25
IF
Statements
IF
The IF statement conditionally selects one of two statements to execute.
IF
condition
THEN
statement-1
ELSE
statement-2
VST050.vsd
condition
is either:
•
•
A conditional expression whose value has 16 bits
An INT, INT(32), or FIXED arithmetic expression. If the result of the arithmetic
expression is not 0, condition is true. If the result is 0, condition is false.
statement-1
specifies the statement to execute if condition is true. statement-1 can be
any statement described in this section. If you omit statement-1, no action
occurs for the THEN clause.
statement-2
specifies the statement to execute if condition is false. statement-2 can be
any statement described in this section.
If the condition is true, statement-1 executes. If the condition is false,
statement-2 executes. If no ELSE clause is present, the statement following the IF
statement executes.
Example 12-25 on page 12-26 compares two arrays.
Example 12-25. IF Statement
INT .new_array[0:9];
INT .old_array[0:9];
INT item_ok;
IF new_array = old_array FOR 10 WORDS THEN
item_ok := 1
ELSE
item_ok := 0;
HP pTAL Reference Manual—523746-006
12 -26
Testing Address Types
Statements
You can nest IF statements to any level.
Topics:
•
•
Testing Address Types on page 12-27
Testing Hardware Indicators on page 12-27
Testing Address Types
An IF statement can test the following as if they were Boolean values:
•
•
Any 16-bit-compatible value:
°
°
°
INT
STRING
UNSIGNED(1-16)
All address-typed variables except:
°
°
°
CBADDR
CWADDR
PROCADDR
Testing Hardware Indicators
pTAL does not have the hardware indicators—the overflow bit, the carry bit, or the
condition codes—that TAL has. Instead, the compiler emits code that supports the
$OVERFLOW, $CARRY, and condition code test operators (<, >, =, <=, >=, <>,'<', '>',
'=', '<=', '>=', '<>').
For more information, see Section 13, Hardware Indicators.
HP pTAL Reference Manual—523746-006
12 -27
Move
Statements
Move
A move statement copies a block of data from one location in memory to another. You
specify the number of bytes, words, or elements to copy in the move statement. With
PVU T9248AAD, you can move any variable up to the current maximum allowed size
for any object on a TNS/R platform of 127.5 megabytes.
A value parameter cannot be the target of a move statement.
:=
destination
=:
&
source
count
FOR
count-unit
constant
[
constant
]
constant-list
->
next-addr
VST051.vsd
destination
the identifier, with or without an index, of the variable to which the copy operation
begins. It can be a simple variable, array, simple pointer, structure, structure data
item, or structure pointer, but not a read-only array.
':='
specifies a left-to-right sequential move. It starts copying data from the leftmost
item in source.
'=:'
specifies a right-to-left sequential move. It starts copying data from the rightmost
item in source.
source
the identifier, with or without an index, of the variable from which the copy
operation begins. It can be a simple variable, array, read-only array, simple pointer,
structure, structure data item, or structure pointer.
HP pTAL Reference Manual—523746-006
12 -28
Move
Statements
count
is an unsigned INT arithmetic expression that defines the number of units in
source to copy. If you omit count-unit, the units copied (depending on the
nature of the source variable) are:
Source Variable
Data Type
Units Copied
Simple variable, array, simple pointer
(including structure item)
STRING
INT
INT(32) or REAL
FIXED or REAL(64)
Bytes
Words
Doublewords
Quadruplewords
Structure
Not applicable
Words
Substructure
Not applicable
Bytes
Structure pointer
STRING
INT
Bytes
Words
count-unit
is the value BYTES, WORDS, or ELEMENTS. count-unit changes the meaning
of count from that described previously to the following:
BYTES
Copies count bytes. If both source and destination have
word addresses, BYTES generates a word move for
(count + 1) / 2 words.
WORDS
Copies count words. (WORDS is 16 bits)
ELEMENTS
Copies count elements as follows (depending on the nature of
the source variable):
Source Variable
Data Type
Units Copied
Simple variable
STRING
INT
INT(32) or REAL
FIXED or REAL(64)
Bytes
Words
Doublewords
Quadruplewords
Structure
Not applicable
Structure occurrences
Substructure
Not applicable
Substructure
occurrences
Structure Pointer
(STRING and INT
have meaning only
in group
comparison
expressions and
move statements.)
STRING
INT
Structure occurrences
Array
Simple pointer
(including structure
item)
HP pTAL Reference Manual—523746-006
12 -29
Move
Statements
If count-unit is not BYTES, WORDS, or ELEMENTS, the compiler issues an
error. If you specify BYTES, WORDS, or ELEMENTS for count-unit, that term
cannot also appear as a LITERAL or DEFINE identifier in the global declarations or
in any procedure or subprocedure in which the move statement appears.
constant
is a numeric constant, a character string constant, or a LITERAL to copy.
If you enclose constant in brackets ([ ]) and if destination has a byte
address or is a STRING structure pointer, the system copies constant as a
single byte regardless of the size of constant. If you do not enclose constant
in brackets or if destination has a word address or is an INT structure pointer,
the system copies a word, doubleword, or quadrupleword as appropriate for the
size of constant.
constant-list
is a list of constants to copy. Specify constant-list in the form shown in
Section 3, Data Representation.
next-addr
is a variable to contain the location in destination that follows the last item
copied. The compiler returns a 16-bit or 32-bit address as described in “Usage
Considerations” that follows.
&
is the concatenation operator. It lets you move more than one source or
constant-list, each separated by the concatenation operator.
The following rules apply to using MOVE statements:
•
•
•
A value parameter cannot be the target of a move statement.
The compiler reports a warning if it can determine that there are more bytes in the
source of the move than in the destination of the move (see Destination Shorter
Than Source on page 12-32).
Built-in routines, $FILL8, $FILL16, and $FILL32, fill an array with repetitions of the
same 8-bit, 16-bit, or 32-bit data, respectively (see $FILL8, $FILL16, and $FILL32
Statements on page 12-33).
Example 12-26 on page 12-31 copies spaces into the first five elements of an array
and then uses next-addr as destination to copy dashes into the next five
elements.
HP pTAL Reference Manual—523746-006
12 -30
Move
Statements
Example 12-26. MOVE Statement Copying to an Array
LITERAL len = 10;
LITERAL num = 5;
STRING .array[0:len - 1];
STRING .next_addr;
!
!
!
!
Length of array
Number of elements
Destination array
Next address simple pointer
array[0] ':=' num * [" "] -> @next_addr;
! Do first copy and capture next-addr
next_addr ':=' num * ["-"];
! Use next-addr as start of second copy
Example 12-27 on page 12-31 contrasts copying a bracketed constant with copying an
unbracketed constant. A bracketed constant copies a single byte regardless of the size
of the constant. An unbracketed constant copies words, doublewords, or
quadruplewords depending on the size of the constant.
Example 12-27. MOVE Statement Copying Bracketed and Unbracketed
Constants
STRING x[0:8];
x[0] ':=' [0];
x[0] ':=' 0;
! Copy one byte
! Copy two bytes
Example 12-28. MOVE Statement Copying From One Structure to Another
LITERAL copies = 3;
! Number of occurrences
STRUCT .s[0:copies - 1];
BEGIN
INT a, b, c;
END;
! Source structure
STRUCT .d (s) [0:copies - 1];
! Destination structure
PROC p;
BEGIN
d ':=' s FOR copies ELEMENTS;
END;
! Word move of three
! structure occurrences
HP pTAL Reference Manual—523746-006
12 -31
Destination Shorter Than Source
Statements
Example 12-29. MOVE Statement Copying a Substructure
LITERAL copies = 3;
STRUCT .s;
BEGIN
STRUCT s_sub[0:copies - 1];
BEGIN
INT a, b;
END;
END;
STRUCT .d (s);
! Number of occurrences
! Source substructure
! Destination substructure
! is within structure d
PROC p;
BEGIN
d.s_sub ':=' s.s_sub FOR copies ELEMENTS;
END;
!Byte move of three
! substructure
! occurrences
Destination Shorter Than Source
The compiler reports a warning when it can detect that there are more bytes in the
source of a move than in the destination of the move. For example, if the number of
bytes to move is a constant or constant expression whose value is larger than the
number of bytes in the destination. The compiler does not report a warning if the
destination is:
•
•
•
A global variable
A reference parameter
An array or an element of an array
If the number of bytes to move is a dynamic expression, the compiler reports a warning
only if the number of bytes in the source is greater than the number of bytes in the
destination. It cannot detect whether the number of bytes to move is too large.
Example 12-30. MOVE Statement With Destination Shorter Than
Source (page 1 of 2)
INT g;
INT(32) m;
PROC p( r );
INT .r;
HP pTAL Reference Manual—523746-006
12 -32
$FILL8, $FILL16, and $FILL32 Statements
Statements
Example 12-30. MOVE Statement With Destination Shorter Than
Source (page 2 of 2)
BEGIN
FIXED f;
INT n[0:9];
INT i;
g
n
n[3]
r
i
END;
':='
':='
':='
':='
':='
f
m
m
m
m
FOR
FOR
FOR
FOR
FOR
8
8
8
8
8
BYTES;
BYTES;
BYTES;
BYTES;
BYTES;
!
!
!
!
!
OK: g is
OK: n is
OK: n is
OK: r is
Warning
global
an array
an array element
a reference param
$FILL8, $FILL16, and $FILL32 Statements
pTAL provides the built-in routines $FILL8, $FILL16, and $FILL32, which fill a data
area with repetitions of the same 8-bit, 16-bit, or 32-bit value, respectively. This
operation is sometimes referred to as a “smear.”
Example 12-31. FILL16 Statement
$FILL16(a, a_size, 0);
For more information, see $FILL8, $FILL16 and, $FILL32 in Section 15, Built-In
Routines.
Variables (including structure data items) are byte addressed or word addressed as
follows:
Byte addressed
Word addressed
•
•
•
•
•
•
•
•
•
•
STRING simple variables
STRING arrays
Variables to which STRING simple pointers point
Variables to which STRING structure pointers point
Substructures
INT, INT(32), FIXED, REAL, or REAL(64) simple variables
INT, INT(32), FIXED, REAL, or REAL(64) arrays
Variables to which INT, INT(32), FIXED, REAL, or REAL(64)
simple pointers point
Variables to which INT structure pointers point
Structures
After a move, next-addr might point to the middle of an element, rather than to the
beginning of the element. If destination is word addressed and source is byte
addressed and you copy an odd number of bytes, next-addr will not point to an
element boundary.
HP pTAL Reference Manual—523746-006
12 -33
RETURN
Statements
RETURN
A RETURN statement causes a procedure or function to return control to its caller.
When you return from a function, the RETURN statement also specifies a value to
return to the function’s caller.
Note.
•
•
In the discussion of the RETURN statement, the word “procedure” implies both procedures
and subprocedures but not functions.
The EpTAL compiler issues a warning whenever a pTAL procedure returns both a
result-expression and a cc-expression and has the procedure attribute
RETURNSCC on page 14-8. The reason for this warning is in Appendix D, RETURN,
RETURNSCC, and C/C++ on TNS/E.
RETURN
cc-expression
result-expression
,
cc-expression
VST052.vsd
cc-expression
is an INT expression whose numeric value specifies the condition code value to
return to the caller:
Value of cc-expression
The condition code is set to ...
Less than 0
Less than (<)
Equal to 0
Equal (=)
Greater than 0
Greater than (>)
Specify cc-expression in RETURN statements only in functions and
procedures that specify the attribute RETURNSCC (see Procedure Attributes on
page 14-5).
result-expression
is an arithmetic or conditional expression that a function must return to the caller.
result-expression must be of the same return type as the data type specified
in the function header. The data type of a conditional expression is always INT.
Specify result-expression only when returning from a function.
If result-expression is any type except FIXED or REAL(64), a function can
return both result-expression and cc-expression.
HP pTAL Reference Manual—523746-006
12 -34
Functions
Statements
Topics:
•
•
•
Functions on page 12-35
Procedures and Subprocedures on page 12-36
Condition Codes on page 12-37
Functions
Every function must include at least one RETURN statement. The compiler does not
verify that every path through a function’s code includes a RETURN statement;
therefore, a function can reach the end of its code without executing a RETURN
statement. If this happens, the function returns zero.
Functions that return a condition code that is not based on the value returned by the
function must specify explicitly the condition code value to return to the function’s
caller.
Example 12-32. RETURN Statements Nested in an IF Statement
INT PROC other (nuff, more);
INT nuff;
INT more;
BEGIN
IF nuff < more THEN
RETURN nuff * more
ELSE
RETURN 0;
END;
! Function with return type INT
! IF statement
! Return a value
! Return a different value
Example 12-33. RETURN Statement That Returns a Value and a Condition Code
INT PROC p (i);
INT i;
BEGIN
RETURN i, i - max_val;
END;
! Return a value and a condition code
If you call a function, rather than calling it in an expression, you can test the returned
condition code, as Example 12-34 on page 12-35 does.
Example 12-34. Testing a Condition Code (page 1 of 2)
INT PROC p1 (i);
INT i;
BEGIN
RETURN i;
END;
HP pTAL Reference Manual—523746-006
12 -35
Procedures and Subprocedures
Statements
Example 12-34. Testing a Condition Code (page 2 of 2)
INT PROC p2 (i);
INT i;
BEGIN
INT j := i + 1;
RETURN i, j;
END;
CALL p1 (i);
IF < THEN ... ;
! Test return value
CALL p2 (i);
IF < THEN ... ;
! Test condition code
Procedures and Subprocedures
In procedures and subprocedures that are not functions, a RETURN statement is
optional. A nonfunction procedure or subprocedure that returns a condition code value,
however, must return to the caller by executing a RETURN statement that includes
cc-expression.
In a procedure designated MAIN, a RETURN statement stops execution of the
procedure and passes control to the operating system.
Procedures that return a condition code must specify explicitly the value of the
condition code to return to the procedure’s caller. In general, a procedure or
subprocedure returns control to the caller when:
•
•
A RETURN statement is executed.
The called procedure or subprocedure reaches the end of its code.
Example 12-35. RETURN Statement in a Procedure
PROC something;
BEGIN
INT a,
b;
! Manipulate a and b
IF a < b THEN
RETURN;
! Lots more code
END;
! Return to caller
The procedure in Example 12-36 on page 12-37 returns a condition code that indicates
whether an add operation overflows.
HP pTAL Reference Manual—523746-006
12 -36
Condition Codes
Statements
Example 12-36. RETURN Statement in a Procedure That Returns a Condition
Code
PROC p (s, x, y) RETURNSCC;
INT .s, x, y;
BEGIN
INT cc_result;
INT i;
i := x + y;
IF $OVERFLOW THEN cc_result := 1
ELSE cc_result := 0;
s := i;
RETURN cc_result; ! If overflow, condition code is >;
END;
! otherwise, it is =
Condition Codes
A procedure (but not a function) returns a condition code only if the procedure
declaration includes the RETURNSCC attribute. The compiler reports an error if a
procedure attempts to test the condition code after calling a procedure that does not
specify RETURNSCC.
Example 12-37. Procedure Without RETURNSCC
PROC p;
BEGIN
END;
PROC q;
BEGIN
CALL p;
IF < THEN ...
! ERROR: p did not return a condition code
! or a return value
END;
Example 12-38 on page 12-37 is similar to Example 12-37 on page 12-37, but is
syntactically correct because p specifies RETURNSCC and returns a condition code
value.
Example 12-38. Procedure With RETURNSCC (page 1 of 2)
PROC p RETURNSCC;
BEGIN
INT i;
...
RETURN i;
END;
HP pTAL Reference Manual—523746-006
12 -37
Condition Codes
Statements
Example 12-38. Procedure With RETURNSCC (page 2 of 2)
PROC q;
BEGIN
CALL p;
IF < THEN ...
END;
! OK: p returns a condition code
Functions that do not specify RETURNSCC return a condition code that is based on
the numeric value returned by the function, regardless of the nature of the expression
in the RETURN statement.
Example 12-39. Function Without RETURNSCC
INT PROC p(i);
INT i;
BEGIN
RETURN IF i = 0 THEN -1
ELSE IF i = 1 THEN 0
ELSE 1
END;
! Returns a condition code
! based on the value returned
Functions can return a condition code that is independent of the value returned by the
function, as follows:
•
•
The function declaration must specify the RETURNSCC attribute.
Each RETURN statement in the function must specify the value of the condition
code.
Example 12-40. Function With RETURNSCC
INT i;
BEGIN
INT cc_result;
...
cc_result :=
IF i <
ELSE
IF i
ELSE
RETURN
END;
max_val THEN -1
= max_val THEN 0
1;
i, cc_result; ! Return a function value and a
! condition code that indicates
! whether the function value is
! less than, equal to, or
! greater than some maximum
Note. The EpTAL compiler issues a warning whenever a pTAL procedure returns both a
traditional function value and a condition code value. For details, see Appendix D, RETURN,
RETURNSCC, and C/C++ on TNS/E.
HP pTAL Reference Manual—523746-006
12 -38
Condition Codes
Statements
A function or procedure that specifies RETURNSCC must include cc-expression
on every RETURN statement. Conversely, specify cc-expression in RETURN
statements only in functions and procedures that specify RETURNSCC.
You can test the condition code returned by a function, even if you call the function in a
CALL statement.
Example 12-41. Condition Code Returned by Function Called by CALL Statement
INT PROC p1(i);
INT i;
BEGIN
RETURN i;
END;
INT PROC p2(i) RETURNSCC;
INT i;
BEGIN
INT j := i + 1;
RETURN i, j;
END;
CALL p1(1);
IF < THEN ...
CALL p2(1);
IF < THEN ...
Note. The EpTAL compiler issues a warning whenever a pTAL procedure returns both a
traditional function value and a condition code value. For details, see Appendix D, RETURN,
RETURNSCC, and C/C++ on TNS/E.
Example 12-42. Condition Code Based on Numeric Value
INT PROC p(i);
INT i;
BEGIN
...
RETURN i;
END;
! Return i and set the condition code
! based on the numeric value of i
HP pTAL Reference Manual—523746-006
12 -39
SCAN and RSCAN
Statements
Example 12-43. Condition Code That Is Independent of the Function’s Value
INT PROC p(i) RETURNSCC;
INT i;
BEGIN
...
RETURN i, f(i);
END;
! Return the value of i and set the
! condition code according to the
! value returned by function f
Note. The EpTAL compiler issues a warning whenever a pTAL procedure returns both a
traditional function value and a condition code value. For details, see Appendix D, RETURN,
RETURNSCC, and C/C++ on TNS/E.
Example 12-44. Invalid Function That Attempts to Return an Explicit Condition
Code
INT PROC p(i);
INT i;
BEGIN
...
RETURN i, f(i);
END;
! ERROR: Cannot specify an explicit
! condition code because procedure
! header does not specify RETURNSCC
SCAN and RSCAN
The SCAN and RSCAN statements search a scan area for a test character from left to
right or from right to left, respectively.
The scan variable in an RSCAN or SCAN statement can be a pointer declared with
the.EXT indirection symbol.
variable
SCAN
test-char
UNTIL
RSCAN
->
WHILE
next-addr
VST053.vsd
SCAN
indicates a left-to-right search.
HP pTAL Reference Manual—523746-006
12 -40
SCAN and RSCAN
Statements
RSCAN
indicates a right-to-left search.
variable
is the identifier, with or without an index, of a variable at which to start the scan.
The following restrictions apply:
•
•
•
The variable can be a simple variable, array, read-only array, simple pointer,
structure pointer, structure, or structure data item.
The variable can be of any data type but UNSIGNED.
The variable cannot have extended indirection.
WHILE
specifies that the scan continues until a character other than test-char occurs
or until a 0 occurs. A scan stopped by a character other than test-char resets
$CARRY. A scan stopped by a 0 sets $CARRY.
UNTIL
specifies that the scan continues either until test-char occurs or until a 0
occurs. A scan stopped by test-char resets the hardware carry bit. A scan
stopped by a 0 sets the hardware carry bit.
test-char
is an INT arithmetic expression whose value is a maximum of eight significant bits
(one byte). A larger value might cause execution errors.
next-addr
is a 16-bit variable to contain the 16-bit byte address of the character that stopped
the scan, regardless of the data type of identifier.
Delimit the scan area with zeros; otherwise, a scan operation might continue to pass all
valid data if either:
•
•
A SCAN UNTIL operation does not find a zero or the test character.
A SCAN WHILE operation does not find a zero or a character other than the test
character.
To delimit the scan area, you can specify zeros as follows:
INT .buffer[-1:10] := [0,"
John James Jones
",0];
Example 12-45 on page 12-42 converts the word address of an INT array to a byte
address. The assignment statement stores the resulting byte address in a STRING
pointer. The SCAN statement then scans the bytes in the array until it finds a comma.
HP pTAL Reference Manual—523746-006
12 -41
Determining What Stopped a Scan
Statements
Example 12-45. SCAN UNTIL Statement
INT .words[-1:3] := [0,"Doe, J",0];
STRING .byte_ptr := @words[0] '<<' 1;
! Initialize with byte
! address of words[0]
SCAN byte_ptr[0] UNTIL ",";
! Scan bytes in words
Topics:
•
•
•
•
Determining What Stopped a Scan on page 12-42
Extended Pointers on page 12-42
Crossing Variable Boundaries on page 12-43
P-Relative Arrays on page 12-43
Determining What Stopped a Scan
To determine what stopped a scan, test $CARRY in an IF statement immediately after
the SCAN or RSCAN statement.
Example 12-46. Determining What Stopped a Scan
IF $CARRY THEN ... ;
IF NOT $CARRY THEN ... ;
! If test character not found
! If test character found
If $CARRY is true after a SCAN UNTIL, the test character did not occur. If $CARRY is
true after SCAN WHILE, a character other than the test character did not occur.
To determine the number of multibyte elements processed, divide (next-addr '-' byte
address of identifier ) by the number of bytes per element using unsigned
arithmetic.
For more information about $CARRY, see Section 13, Hardware Indicators.
Extended Pointers
Example 12-47. Extended Pointers in SCAN and RSCAN Statements
STRING .EXT s;
STRING .EXT t;
EXTADDR
u;
SCAN s until " " -> @t;
SCAN s until " " -> u;
! OK
! OK
HP pTAL Reference Manual—523746-006
12 -42
Crossing Variable Boundaries
Statements
Crossing Variable Boundaries
SCAN and RSCAN statements can access data contained within single named
variables or arrays as long as the scan encounters either the target character specified
in the SCAN or RSCAN statement or a 0 byte before it reaches the end of the named
variable or array.
SCAN and RSCAN statements that depend on accessing data that precedes or follows
the variable named in the SCAN or RSCAN statement do not work.
Topics:
•
•
Data Layout Considerations on page 12-43
Data Passed to Procedures in Reference Parameters on page 12-43
Data Layout Considerations
Example 12-48. Scanning Adjacent Fields Within a Structure
STRUCT s FIELDALIGN(SHARED2);
BEGIN
STRING buffer[0:99];
STRING stopper;
END;
BADDR end_addr;
...
s.stopper := 0;
SCAN s.buffer UNTIL char -> end_addr;
IF end_addr = @s.stopper THEN
BEGIN
...
END;
! Target character was not found
Data Passed to Procedures in Reference Parameters
The rules in of the preceding subsection about data layouts apply if the buffer scanned
in a SCAN statement is a reference parameter.
P-Relative Arrays
The address type of pointers in a SCAN statement that scans a P-relative array must
be CBADDR or CWADDR.
When the SCAN statement in Example 12-49 on page 12-44 completes, t_start
points to the first character in the third message, and t_end points immediately after
the last character in the third message. The object data type of t_start and t_end is
STRING; therefore, their address type is BADDR.
HP pTAL Reference Manual—523746-006
12 -43
P-Relative Arrays
Statements
Example 12-49. Scanning Data in a P-Relative Array
STRING s = 'P' :=
[ 1, "msg1.",
2, "msg2.",
3, "msg3.",
0 ];
! STRING P-relative array s
STRING
! Start address of msg
! End address of msg
INT
.t_start,
.t_end;
c := 3,
z := ".";
! Value to scan for in s
! Value to stop the scan
SCAN s UNTIL c -> @t_start;
! Scan s for c and store c's
! address in t_start
@t_start := @t_start '+' 1;
! Skip c
SCAN s[@t_start '-' @s]
UNTIL z -> @t_end;
! Find end of message
In Example 12-50 on page 12-44, the data type of t_start and of t_end is
CBADDR. The object data type of s is STRING. Its address type is CBADDR, not
BADDR; therefore, you can subtract @s from t_start because the data types of
both are CBADDR.
Example 12-50. Scanning Data in a P-Relative Array
STRING s = 'P' := [
1, "msg1.",
2, "msg2.",
3, "msg3.",
0 ];
! STRING P-relative array s
CBADDR
t_start,
t_end;
! Start address of msg
! End address of msg
INT
c := 3,
z := -1;
! Value to scan for in s
! Value to stop the scan?
SCAN s UNTIL c -> t_start;
! Scan s for c and store c's
! address in t_start
t_start := t_start '+' 1;
! Skip character in c
SCAN s[t_start '-' @s]
UNTIL z -> t_end;
! Find end of message
HP pTAL Reference Manual—523746-006
12 -44
USE
Statements
USE
The USE statement creates a temporary variable.
USE
identifier
,
VST056.vsd
identifier
is the name of the temporary variable being created.
A temporary variable that the USE statement creates:
•
•
•
Is equivalent to a variable declared INT
Is usually kept in a register
Exists until either:
°
°
You drop it with the statement DROP on page 12-19 (recommended)
The procedure that creates it ends
WHILE
The WHILE statement is a pretest loop that repeatedly executes a statement while a
specified condition is true.
WHILE
condition
DO
statement
VST057.vsd
condition
is either:
•
•
A conditional expression
An INT, INT(32), or FIXED arithmetic expression. If the result of the arithmetic
expression is not 0, condition is true. If the result is 0, condition is false.
statement
is any pTAL statement.
The WHILE statement tests the condition before each iteration of the loop. If the
condition is false before the first iteration, the loop never executes.
HP pTAL Reference Manual—523746-006
12 -45
WHILE
Statements
Hardware indicators cannot appear in the conditional expression of a WHILE
statement.
Example 12-51. WHILE Statement
LITERAL len = 100;
INT .array[0:len - 1];
INT item := 0;
WHILE item < len DO
BEGIN
array[item] := 0;
item := item + 1;
END;
! item equals len at this point
The WHILE statement in Example 12-52 on page 12-46 increments index until a
nonalphabetic character occurs.
Example 12-52. WHILE Statement
LITERAL len = 255;
STRING .array[0:len - 1];
INT index := -1;
WHILE (index < len - 1) AND
($ALPHA(array[index := index + 1]))
DO ... ;
HP pTAL Reference Manual—523746-006
12 -46
13
Hardware Indicators
Table 13-1. Hardware Indicators
Hardware
Indicator
Representation
Overflow bit
$OVERFLOW
Carry bit
$CARRY
Condition code
< or ‘<’
Less than
> or ‘>’
Greater than
= or ‘=’
Equal
<= or ‘<=’
Less than or equal
>= or ‘>=’
Greater than or equal
<> or ‘<>’
Not equal
Meaning
In TNS architecture, a “hardware indicator” is one of three fields of the environment (ENV) register.
Topics:
•
•
•
•
•
Managing Overflow Traps on page 13-1
Hardware Indicators After Assignments on page 13-3
Hardware Indicators in Conditional Expressions on page 13-8
Nesting Condition Code Tests on page 13-12
Using Hardware Indicators Across Procedures on page 13-14
Managing Overflow Traps
pTAL provides a “static T flag” with which you specify whether traps are enabled or
disabled at any point in your program. You manipulate the static T flag with:
Directive or Attribute
Scope
Comment
OVERFLOW_TRAPS
Compilation unit
OVERFLOW_TRAPS is the
default
[NO]OVERFLOW_TRAPS Procedure
Attribute
Procedure or
subprocedure
Overrides the
[NO]OVERFLOW_TRAPS
directive
[EN|DIS]ABLE_OVERFLOW_TRAPS
Block Attribute
Block
Overrides both the
[NO]OVERFLOW_TRAPS
directive and the
[NO]OVERFLOW_TRAPS
procedure attribute
HP pTAL Reference Manual—523746-006
13- 1
[NO]OVERFLOW_TRAPS Procedure Attribute
Hardware Indicators
The directives and attributes active when a pTAL statement is compiled determine the
overflow trapping state of the code that the compiler generates for that statement. A
procedure does not inherit the trapping state of its caller.
[NO]OVERFLOW_TRAPS Procedure Attribute
The OVERFLOW_TRAPS and NOOVERFLOW_TRAPS procedure attributes specify
the default overflow trapping behavior for a procedure or subprocedure (see Procedure
Attributes on page 14-5).
The OVERFLOW_TRAPS and NOOVERFLOW_TRAPS procedure attributes override
the current setting of the directive OVERFLOW_TRAPS on page 17-49.
Example 13-1. OVERFLOW_TRAPS Compiler Directive and Procedure Attribute
?OVERFLOW_TRAPS
! Enable traps
PROC x NOOVERFLOW_TRAPS;
BEGIN
...
END;
! Disable traps for x
PROC y;
BEGIN
...
END;
! Traps for y are still enabled
PROC z NOOVERFLOW_TRAPS;
BEGIN
SUBPROC s OVERFLOW_TRAPS;
BEGIN
...
END;
...
s;
...
END;
! Disable traps for z
! Enable traps for s
! Traps for z are still disabled
! upon return from s
[EN|DIS]ABLE_OVERFLOW_TRAPS Block Attribute
The ENABLE_OVERFLOW_TRAPS and DISABLE_OVERFLOW_TRAPS block
attributes establish the trapping state of a block, regardless of the trapping state of the
procedure’s or subprocedure’s caller or of the code surrounding the block.
BEGIN
:
ENABLE_OVERFLOW_TRAPS
DISABLE_OVERFLOW_TRAPS
VST682.vsd
HP pTAL Reference Manual—523746-006
13- 2
Hardware Indicators After Assignments
Hardware Indicators
Example 13-2. ENABLE_OVERFLOW_TRAPS and
DISABLE_OVERFLOW_TRAPS Block Attributes
PROC p;
BEGIN: ENABLE_OVERFLOW_TRAPS
...
END;
! Enable traps for block
PROC q;
BEGIN
SUBPROC q1;
BEGIN: DISABLE_OVERFLOW_TRAPS
...
END;
...
END;
! Disable traps for block
PROC r;
BEGIN: ENABLE_OVERFLOW_TRAPS
CALL p;
END;
! Call p with traps enabled
PROC s;
BEGIN: DISABLE_OVERFLOW_TRAPS
CALL p;
END;
! Call p with traps disabled
Hardware Indicators After Assignments
Topics:
•
•
•
$OVERFLOW on page 13-3
$CARRY on page 13-4
Condition Codes on page 13-4
$OVERFLOW
After every assignment statement, the compiler generates code that tests for overflow
if either:
•
•
Overflow traps are enabled
All of the following conditions are true:
°
°
Overflow traps are disabled.
The root operator is one of the following:
°
°
°
°
Negation (unary -), +, -, *, /, '/'
$DBL of an INT, FIXED, REAL, or REAL(64) value
$DBLR of an INT, FIXED, REAL, or REAL(64) value
$FLTR of a REAL(64) value
HP pTAL Reference Manual—523746-006
13- 3
$CARRY
Hardware Indicators
°
°
°
°
°
°
°
°
°
°
$FIX of a REAL or REAL(64) value
$FIXD
$FIXI
$FIXL
$FIXR of a REAL or REAL(64) value
$INT of a FIXED, REAL, or REAL(64) value
$INTR of a FIXED, REAL, or REAL(64) value
$FIXEDTOASCII
$SCALE for which 1 <= exponent <= 4
The next statement is an IF statement that tests $OVERFLOW.
$CARRY
You can test $CARRY if the root operator is one of the following:
•
Signed integer addition or subtraction
INT i, j, k;
i := j + k;
i := j - k;
•
Unsigned integer addition or subtraction
INT i, j, k;
i := j '+' k;
i := j '-' k;
•
! $CARRY can be tested after this statement
! $CARRY can be tested after this statement
! $CARRY can be tested after this statement
! $CARRY can be tested after this statement
Unary minus
INT i;
i := -i;
! $CARRY can be tested after this statement
Condition Codes
When the condition code is accessible following an assignment statement, the numeric
value of the evaluated expression on the right side of the assignment statement
determines the value of the condition code.
Topics:
•
•
When Condition Codes Are Accessible on page 13-5
When Condition Codes Are Not Accessible on page 13-5
HP pTAL Reference Manual—523746-006
13- 4
Condition Codes
Hardware Indicators
When Condition Codes Are Accessible
The condition code is accessible after an assignment statement only if:
•
The right side of the assignment statement is not:
°
A 1-byte item:
STRING s;
INT i;
i := s; ! Condition code is not accessible
°
A call to a built-in routine (for a list of these, see Table 15-1 on page 15-4):
i := $ABS(i);
°
An expression whose value is an address type (for example, WADDR or
EXTADDR):
INT i;
INT .p;
@p := @i;
°
! Condition code is not accessible
! Right side is a WADDR value;
! condition code is not accessible
An expression whose value is a floating-point data type [REAL or REAL(64)]:
REAL r := 1.0E0;
r := r + 1.0E0;
°
A constant or constant expression:
INT a;
a := 2 << 3;
•
! Right side is a floating-point number;
! condition is code not accessible
! Right side is a constant expression;
! condition is code not accessible
None of the exceptions in When Condition Codes Are Not Accessible on page 13-5
apply
When Condition Codes Are Not Accessible
The following exceptions override the conditions in When Condition Codes Are
Accessible on page 13-5:
•
If the last operation on the right side of an assignment statement is a function call,
these rules apply:
•
•
If the function specifies the RETURNSCC attribute, you can test the condition
code following the assignment statement, independent of the data type of the
value returned by the function.
The numeric value returned by the function always determines the value of the
condition code.
HP pTAL Reference Manual—523746-006
13- 5
Condition Codes
Hardware Indicators
•
If the right side of an assignment statement is an INT function, the condition
code is determined by the INT value returned by the function. The value
returned is always an INT, even if the expression in the function’s RETURN
statement is a byte value. The byte value is not sign-extended.
INT PROC p;
BEGIN
RETURN "A";
END;
PROC p1;
BEGIN
INT i;
i := p;
END;
! P is an INT function but the
! expression in the RETURN statement
! yields a single byte
! Condition code is accessible because
! p returns an INT value
The left side of the assignment statement must be one of:
°
A local or sublocal simple variable:
PROC p;
BEGIN
INT i;
i := i + 1;
END;
°
! Declare a local simple variable
! Condition code accessible
The address cell of a local pointer:
INT i;
INT .ptr;
@ptr := f(i);
°
! Declare a local pointer
! Condition code is accessible if
! f specifies RETURNSCC
A value parameter:
PROC p (param);
INT param;
! Value parameter
BEGIN
INT i := 0;
param := i; ! Condition code is accessible
END;
•
The left side of the assignment statement cannot be:
°
A STRING variable:
STRING s;
s := "a";
°
! Condition code is not accessible
An UNSIGNED(n) variable:
UNSIGNED(12) u;
u := %HFFF;
! Condition code is not accessible
HP pTAL Reference Manual—523746-006
13- 6
Condition Codes
Hardware Indicators
°
A global variable:
INT g;
PROC p;
BEGIN
INT i := 0;
g := i;
END;
°
A pointer:
INT .p;
INT i := 0;
p := i;
°
! Condition code is not accessible
! Condition code is not accessible
A variable containing indexing, field selection, or bit selection:
STRUCT s;
BEGIN
INT f;
END;
INT a[0:9];
INT i;
s.f := i;
! Field selection: condition code is
! not accessible
a[9] := i;
! Index: condition code is not accessible
i.<3:5> := a;
! Bit Selection: condition code is
! not accessible
Example 13-3. Assignments After Which You Can Test Condition
Codes (page 1 of 2)
INT m;
PROC p(x, y);
INT
x;
INT
.y;
BEGIN
INT
a[0:9];
INT
i;
INT .EXT k;
INT(32) j;
STRING
str;
REAL
r;
EXTADDR SUBPROC f(x) RETURNSCC;
INT x;
BEGIN
RETURN %200000D, x;
END;
HP pTAL Reference Manual—523746-006
13- 7
Hardware Indicators in Conditional Expressions
Hardware Indicators
Example 13-3. Assignments After Which You Can Test Condition
Codes (page 2 of 2)
STRUCT s;
BEGIN
INT s1[0:4];
INT s2;
END;
i := k;
i := i + 1;
! OK: Left and right sides are simple
! OK: Left and right sides are simple
x := x + 1;
! OK: Left side is value parameter,
! right side is INT
@k := f(0);
! OK: Left side is pointer cell,
! right side is RETURNSCC function
y := i + 1;
a[i] := a[i+1];
s.s1[0] := i;
s.s2
:= i;
i.<0:8> := i;
!
!
!
!
!
i := str;
! ERROR: Right side is 1-byte item
i := $ABS(i);
! ERROR: Right side is call to
! built-in routine
@k := @k + 1D;
r := r + 1.0E0;
END;
ERROR:
ERROR:
ERROR:
ERROR:
ERROR:
Left
Left
Left
Left
Left
side
side
side
side
side
is reference parameter
has index
has field and index
has field reference
has bit selection
! ERROR: Right side is address type
! ERROR: Right side is floating-point type
Hardware Indicators in Conditional
Expressions
Hardware indicators can appear in conditional expressions in these statements:
•
DO-UNTIL on page 12-17
The last statement in the DO-UNTIL statement must set the hardware indicator.
The last statement can be nested in a BEGIN...END statement. See Example 13-4
on page 13-9.
•
IF on page 12-26
These are valid references to hardware indicators:
IF $OVERFLOW THEN ...
IF $CARRY THEN ...
IF < THEN ...
•
WHILE on page 12-45
HP pTAL Reference Manual—523746-006
13- 8
Hardware Indicators in Conditional Expressions
Hardware Indicators
Both the statement preceding the WHILE statement and the last statement in the
WHILE statement must set the condition code indicator. See Example 13-5 on
page 13-9.
Example 13-4. Hardware Indicators in DO-UNTIL Statements
proc p returnscc;
begin
...
end;
proc q;
begin
...
end;
do
call p ()
until = ;
! Sets condition code indicator
! OK
do
begin
...
call p ();
end
until = ;
! OK
do
begin
...
call q ();
end
until > ;
int i := 0;
...
do
begin
...
i := i + 1;
end
until $overflow;
! ERROR: last statement in do-until statement
! does not set condition indicator
! ERROR: $overflow and $carry not allowed
! in do-until statement
Example 13-5. Hardware Indicators in WHILE Statements (page 1 of 2)
int proc p;
begin
...
end;
proc q;
begin
end;
HP pTAL Reference Manual—523746-006
13- 9
Hardware Indicators in Conditional Expressions
Hardware Indicators
Example 13-5. Hardware Indicators in WHILE Statements (page 2 of 2)
call p ();
while >= do
call p ();
call p ();
!
!
!
!
Sets condition code indicator
OK
Sets condition code indicator
Sets condition code indicator
while > do
begin
...
call p ();
! OK
! Sets condition code indicator
end;
call q ();
! Doesn't set the condition code indicator
while > do
begin
...
call p ();
end;
! ERROR: statement preceding WHILE
! and last statement of WHILE
! must both set condition code indicator
! Sets condition code indicator
call p ();
! Sets the condition code indicator
while >= do
begin
...
call q ();
end;
! ERROR: statement preceding WHILE
!
and last statement of WHILE
!
must both set condition code indicator
! Doesn't set condition code indicator
int i;
...
i := i + 1;
while not $overflow do
begin
...
i := i + 1;
end;
! ERROR: not a condition code indicator
You cannot:
•
Reference a hardware indicator in an expression other than in the conditional
expression of an IF statement
INT i;
i := IF < THEN -i ELSE i;
•
Assign the value of a hardware indicator to a variable in an assignment statement
INT i;
i := >;
•
!ERROR: invalid in IF expression
! ERROR: invalid in assignment statement
Pass a hardware indicator as an actual parameter to a procedure
INT i;
CALL p( < );
! ERROR: invalid as parameter
HP pTAL Reference Manual—523746-006
13 -10
Hardware Indicators in Conditional Expressions
Hardware Indicators
An IF statement that tests a hardware indicator must either:
•
Immediately follow the statement that establishes the value of the hardware
indicator
INT a;
a := a - 1;
IF < THEN ...
! OK: hardware indicator tested immediately
a := a + 1;
IF $CARRY THEN ...
! OK: hardware indicator tested
! immediately
CALL WRITEREAD(...);
IF <> THEN...
a := a - 1;
BEGIN
IF < THEN ...
...
a := a + 1;
END;
! OK: hardware indicator tested
! immediately
! ERROR: intervening BEGIN is invalid
IF $CARRY THEN ...
! ERROR: intervening END is invalid
CALL WRITEREAD(...);
firstchar := str_buff;
IF <= THEN...
CALL WRITEREAD(...);
IF < THEN ...
•
! ERROR: intervening assignment
! statement is invalid
! ERROR: previous statement does not
! set condition code
Be part of a nest of IF statements as described in Nesting Condition Code Tests on
page 13-12
The hardware indicator in the conditional expression of an IF statement must be the
first operand in the expression.
IF $CARRY THEN ...
! OK: hardware indicator is
! first operand
IF <= OR a >= 99 THEN ...
! OK: hardware indicator is
! first operand
IF I <= 999 AND > THEN ...
! ERROR: condition code must be
! first operand
IF a = b OR $CARRY THEN ...
! ERROR: $CARRY must be
! first operand
IF a = b OR $OVERFLOW THEN ...
! ERROR: $OVERFLOW must be
! first operand
HP pTAL Reference Manual—523746-006
13 -11
Nesting Condition Code Tests
Hardware Indicators
The first statement in an IF statement’s THEN clause or ELSE clause (or both) can, in
turn, be an IF statement that tests the condition code established by the conditional
expression of the containing IF statement. In this case, the root operator in the
containing IF statement’s conditional expression must be either:
•
A relational operator
i := i + 1;
IF i >= 0 THEN
IF > THEN ...
•
! OK: >= is a relational operator
An expression that consists only of a condition code
i := i + 1;
IF >= THEN
IF > THEN...
! OK: >= is a condition code
An IF statement that tests a hardware indicator cannot be labeled.
Nesting Condition Code Tests
You can test for more than one value of a condition code by nesting IF statements; for
example:
i := i + 1;
IF < THEN
...
ELSE IF = THEN
...
ELSE ! Must be >
...
INT PROC p;
BEGIN
CALL READX( ... );
IF < THEN RETURN -1
ELSE IF > THEN RETURN 1
ELSE RETURN 0;
END;
The following rules apply to nested IF statements:
•
Neither $OVERFLOW nor $CARRY can appear in the conditional expression of
any IF statement in a nest of IF statements.
i := i + 1;
IF > THEN
IF $OVERFLOW THEN ...
i := i + 1;
IF $CARRY THEN
IF > THEN ...
! ERROR: cannot test $OVERFLOW in
! nest of IF statements
! ERROR: cannot test $CARRY in
! nest of IF statements
HP pTAL Reference Manual—523746-006
13 -12
Nesting Condition Code Tests
Hardware Indicators
You cannot test $OVERFLOW or $CARRY to determine if an overflow or carry
occurred while evaluating an IF statement’s conditional expression.
IF i + 1 < 100 THEN
BEGIN
IF $CARRY THEN ...
END
! ERROR: invalid to test $CARRY here
You can test $OVERFLOW or $CARRY by evaluating, in a separate assignment
statement, the expression in which overflow or carry could occur, then test
$OVERFLOW or $CARRY.
INT temp;
•
temp := i + 1;
! Carry could occur here
IF NOT $CARRY THEN
BEGIN
IF temp < 100 THEN ...
END
ELSE ...
! OK to test $CARRY here
! Handle $CARRY condition
Except as noted in the following item, the conditional expression in each IF
statement in a nest of IF statements can test only the value of the condition code,
optionally preceded by the NOT operator. The conditional expression cannot
include any other operator or operand.
i := i + 1;
IF <= THEN
IF NOT = THEN ...
•
! OK
The conditional expression of the innermost IF statement can be a complex
expression, but the condition code must be the first operand in the expression.
i := j + 1;
IF >= THEN
IF = AND (j + 4) / 5 * 5 > 0 THEN ...
•
! OK
If the root operator in the conditional expression of an IF statement is a relational
operator, the first statement in the THEN or ELSE clause of the IF statement can
be an IF statement that tests the condition code set by the root operator of the
encompassing IF statement.
IF (i + 10) <= (m - 2) THEN
BEGIN
IF < THEN
...
ELSE
END;
IF (i < -1) OR (i > 1) THEN
BEGIN
IF < THEN
...
END;
! Root operator (<=) is
! relational operator
! OK: test if condition was
! "less than"
! ERROR: root operator of IF
! statement is Boolean,
! not relational
HP pTAL Reference Manual—523746-006
13 -13
Using Hardware Indicators Across Procedures
Hardware Indicators
•
If an outer IF statement’s conditional expression uses a signed operator (= or <>)
to compare two 16-bit addresses, an inner IF statement’s THEN or ELSE clause
cannot test the condition code established by the outer IF statement’s conditional
expression.
WADDR
w1, w2;
EXTADDR e1, e2;
IF e1 <> e2 THEN
BEGIN
IF < THEN ...
END;
! OK: e1 and e2 are EXTADDR values
IF w1 '<>' w2 THEN
BEGIN
IF < THEN ...
END;
! OK: Original test is unsigned
IF w1 <> w2 THEN
BEGIN
IF < THEN ...
END;
! ERROR: cannot test condition code
! set by signed comparison of
! 16-bit addresses
Using Hardware Indicators Across Procedures
Topics:
•
•
•
Testing a Hardware Indicator Set in the Calling Procedure on page 13-14
Returning a Condition Code to the Calling Procedure on page 13-15
Returning the Value of $OVERFLOW or $CARRY to the Calling Procedure on
page 13-16
Testing a Hardware Indicator Set in the Calling Procedure
A called procedure cannot test the value of a hardware indicator that was set in the
procedure that called the hardware indicator. To achieve this effect:
1. In the calling procedure:
a. Test the value of the hardware indicator and set a variable to reflect its value.
b. Pass the variable to the called procedure.
2. In the called procedure, test the variable that you passed to the procedure in
Step 1b.
HP pTAL Reference Manual—523746-006
13 -14
Returning a Condition Code to the Calling Procedure
Hardware Indicators
Example 13-6. Testing a Hardware Indicator Set in a Calling Procedure
PROC b(status);
INT status;
BEGIN
IF status <> 0 THEN ...
END;
PROC a;
BEGIN
INT i, j, k;
...
j := i;
! Called procedure
! Test parameter value from PROC a
! Calling procedure
IF <> THEN k := 1
ELSE k := 0;k
CALL b(k);
END;
! Test hardware indicator and set k
! Call PROC b, passing k
Returning a Condition Code to the Calling Procedure
A called procedure can return a condition code value to its caller by using the
RETURNSCC procedure attribute in its procedure or subprocedure declaration and a
RETURN statement.
For more information:
Topic
Source
Procedure declarations
Procedure Declarations on page 14-2
Subprocedure declarations
Subprocedure Declarations on page 14-19
RETURNSCC procedure attribute
Procedure Attributes on page 14-5
RETURN statement
RETURN on page 12-34
HP pTAL Reference Manual—523746-006
13 -15
Returning the Value of $OVERFLOW or $CARRY to
the Calling Procedure
Hardware Indicators
Returning the Value of $OVERFLOW or $CARRY to the Calling
Procedure
A called procedure cannot return the value of $OVERFLOW or $CARRY to its caller.
To achieve this effect, set variables with the values of these indicators and return the
variables’ values using either parameters, global variables, or return values.
Example 13-7. Returning the Value of $OVERFLOW in a Reference Parameter
PROC p;
BEGIN
INT rtn_ovfl;
CALL q(rtn_ovfl);
IF rtn_ovfl = 0 THEN ...
END;
PROC q(ovfl);
INT .ovfl;
BEGIN
INT i := 32767;
! Calling procedure
! q returns rtn_ovfl
! Test value of rtn_ovfl
! Called procedure
i := i + 1;
IF $OVERFLOW THEN
ovfl := 1
ELSE
ovfl := 0;
END;
! Test hardware indicator and
! set ovfl
! Return ovfl to caller
HP pTAL Reference Manual—523746-006
13 -16
14
Procedures, Subprocedures, and
Procedure Pointers
Procedures are program units that contain the executable portions of a pTAL program
and that are callable from anywhere in the program. Procedures allow you to segment
a program into discrete parts that each perform a particular task such as I/O or error
handling.
An executable program contains at least one procedure. One procedure in the program
has the attribute MAIN, which identifies it as the first procedure to execute when you
run the program.
A procedure can contain subprocedures, which are callable from various points within
the same procedure.
A function is a procedure or subprocedure that returns a value. A function is also
known as a typed procedure or typed subprocedure.
Topics:
•
•
•
•
•
•
•
•
•
Procedure Declarations on page 14-2
Procedure Attributes on page 14-5
Formal Parameter Specification on page 14-10
Procedure Body on page 14-17
Subprocedure Declarations on page 14-19
Subprocedure Body on page 14-21
Entry-Point Declarations on page 14-22
Procedure Pointers on page 14-26
Labels in Procedures on page 14-37
In this section, references to procedures refers to procedures and subprocedures
unless otherwise specified.
HP pTAL Reference Manual—523746-006
14- 1
Procedures, Subprocedures, and Procedure
Pointers
Procedure Declarations
Procedure Declarations
A procedure is a program unit that is callable from anywhere in the program. You
declare a procedure as follows:
PROC
identifier
type
public-name-spec
;
proc-attribute
parameter-list
,
proc-body
;
param-spec
;
EXTERNAL
FORWARD
VST058.vsd
type
specifies that the procedure is a function that returns a result and indicates the
data type of the returned result. type can be any data type described in
Section 3, Data Representation.
identifier
is the procedure identifier to use in the compilation unit.
public-name-spec
=
"
public-name
"
VST209.vsd
public-name
is the procedure name to use in the linker, not in the compilation unit. The
default public-name is identifier . public-name must conform to the
identifier rules of the language in which the external procedure is written. For all
languages except HP C, the compiler upshifts public-name automatically.
If a procedure declaration includes public-name-spec, it must also include
EXTERNAL on page 14-4.
HP pTAL Reference Manual—523746-006
14- 2
Procedures, Subprocedures, and Procedure
Pointers
Procedure Declarations
If a procedure declaration includes LANGUAGE on page 14-8, it must also include
public-name-spec.
parameter-list
(
)
param-name
param-pair
,
VST210.vsd
param-name
is the identifier of a formal parameter. A procedure can have up to 32 formal
parameters.
param-pair
is a pair of formal parameter identifiers that comprise a language-independent
string descriptor in the form:
string
:
length
VST039.vsd
string
is the identifier of a standard or extended STRING simple pointer. The
actual parameter is the identifier of a STRING array or simple pointer
declared inside or outside a structure.
length
is the identifier of a directly addressed INT simple variable. The actual
parameter is an INT expression that specifies the length of string, in
bytes.
proc-attribute
is a procedure attribute, as described in Procedure Attributes on page 14-5.
param-spec
specifies the parameter type of a formal parameter and whether it is a value or
reference parameter, as described in Formal Parameter Specification on
page 14-10.
HP pTAL Reference Manual—523746-006
14- 3
Procedures, Subprocedures, and Procedure
Pointers
Procedure Declarations
proc-body
is a BEGIN-END block that contains local declarations and statements, as
described in Procedure Body on page 14-17.
FORWARD
specifies that the procedure body is declared later in the compilation.
EXTERNAL
specifies that the procedure body is either declared in another compilation unit or
later in this compilation unit.
Example 14-1. Procedure Declaration
INT var;
WADDR PROC p(i), RETURNSCC,;
! var is a global INT
! Attributes: empty, RETURNSCC,
! and empty
INT .i;
BEGIN
RETURN @var, i+1;
END;
! Return address and
! condition code value
Example 14-1 on page 14-4 illustrates the following procedure declarations:
•
•
•
p specifies three attributes, the first and third of which are empty.
The second attribute to p, RETURNSCC, is a valid procedure, subprocedure, or
function attribute, which, if present, requires that the code execute a RETURN
statement that specifies a value from which to determine the condition code to
return to the caller. For more information about using RETURNSCC, see RETURN
on page 12-34.
The data type of the value returned by p is WADDR: namely, the address of the
global variable var. The RETURN statement sets the condition code to CCL, CCE,
or CCG, depending on whether the value of i+1 is less than, equal to, or greater
than 0.
HP pTAL Reference Manual—523746-006
14- 4
Procedures, Subprocedures, and Procedure
Pointers
Procedure Attributes
Procedure Attributes
Procedures can have the following attributes:
MAIN
INTERRUPT
RESIDENT
CALLABLE
PRIV
VARIABLE
EXTENSIBLE
count
(
)
RETURNSCC
OVERFLOW_TRAPS
NOOVERFLOW_TRAPS
LANGUAGE
C
COBOL
FORTRAN
PASCAL
UNSPECIFIED
VST635.vsd
MAIN
causes the procedure to execute first when you run the program. When the MAIN
procedure completes execution, it passes control to the PROCESS_STOP_
system procedure, rather than executing an EXIT instruction.
If more than one procedure in a compilation has the MAIN attribute, the compiler
emits a warning and uses the first main procedure it sees as the main procedure.
For example, in the following source code, procedures main_proc1 and
main_proc2 have the MAIN attribute, but in the object file only main_proc1 has
the MAIN attribute:
PROC main_proc1 MAIN;
BEGIN
CALL this_proc;
CALL that_proc;
END;
! This MAIN procedure is MAIN
! in the object file
PROC main_proc2 MAIN;
BEGIN
CALL some_proc;
END;
! This MAIN procedure is not MAIN
! in the object file
HP pTAL Reference Manual—523746-006
14- 5
Procedures, Subprocedures, and Procedure
Pointers
Procedure Attributes
INTERRUPT
causes the pTAL compiler to generate an interrupt exit instruction instead of an
EXIT instruction at the end of execution. Only operating system interrupt handlers
use the INTERRUPT attribute. An example is:
PROC int_handler INTERRUPT;
BEGIN
! Do some work
END;
Note. The EpTAL compiler ignores INTERRUPT.
RESIDENT
causes procedure code to remain in main memory for the duration of program
execution. The operating system does not swap pages of this code. The linker
allocates storage for RESIDENT procedures as the first procedures in the code
space. An example is:
PROC res_proc RESIDENT;
BEGIN
! Do some work
END;
CALLABLE
authorizes a procedure to call a PRIV procedure (described next). Nonprivileged
procedures can call CALLABLE procedures, which can call PRIV procedures.
Thus, nonprivileged procedures can only access PRIV procedures indirectly by first
calling CALLABLE procedures. Normally, only operating system procedures have
the CALLABLE attribute. In the following example, a CALLABLE procedure calls
the PRIV procedure declared next:
PROC callable_proc CALLABLE;
BEGIN
CALL priv_proc;
END;
PRIV
means the procedure can execute privileged instructions. Only PRIV or CALLABLE
procedures can call a PRIV procedure. Normally, only operating system
procedures have the PRIV attribute. PRIV protects the operating system from
unauthorized (nonprivileged) calls to its internal procedures.
The following PRIV procedure is called by the preceding CALLABLE procedure:
PROC priv_proc PRIV;
BEGIN
! Privileged instructions
END;
For information about privileged mode, see Privileged Mode on page 15-1.
HP pTAL Reference Manual—523746-006
14- 6
Procedures, Subprocedures, and Procedure
Pointers
Procedure Attributes
VARIABLE
means the compiler treats all parameters of the subprocedure as if they are
optional, even if some are required by your code. If you add parameters to the
VARIABLE subprocedure declaration, all procedures that call it must be
recompiled. The following example declares a VARIABLE subprocedure:
SUBPROC v (a, b) VARIABLE;
INT a, b;
BEGIN
! Lots of code
END;
When you call a VARIABLE subprocedure, the compiler allocates space in the
parameter area for all the parameters. The value of the data for a missing
parameter is unspecified.
EXTENSIBLE
lets you add new parameters to the procedure declaration without recompiling its
callers. The compiler treats all parameters of the procedure as if they are optional,
even if some are required by your code. The following example declares an
EXTENSIBLE procedure:
PROC x (a, b) EXTENSIBLE;
INT a, b;
BEGIN
! Do some work
END;
When you call an EXTENSIBLE procedure, the compiler allocates space in the
parameter area for all the parameters. The values of missing parameters are
unspecified.
Declare procedures EXTENSIBLE, but not subprocedures.
count
converts a VARIABLE procedure to an EXTENSIBLE procedure. The count
value is the number of formal parameters in the VARIABLE procedure that you
are converting to EXTENSIBLE. For the count value, specify an INT value in
the range 1 through 15.
HP pTAL Reference Manual—523746-006
14- 7
Procedures, Subprocedures, and Procedure
Pointers
Parameters and VARIABLE and EXTENSIBLE
Procedures
RETURNSCC
causes a procedure to return a condition code. The compiler reports an error if a
procedure attempts to test the condition code after calling a procedure that does
not specify RETURNSCC. Procedures declared with RETURNSCC cannot return
64-bit values.
Note. The EpTAL compiler issues a warning if a procedure that has this attribute returns
both a traditional function value and a condition code value by means of RETURN on
page 12-34. The reason for this warning is in Appendix D, RETURN, RETURNSCC, and
C/C++ on TNS/E.
OVERFLOW_TRAPS
enables overflow traps for a procedure.
NOOVERFLOW_TRAPS
disables overflow traps for a procedure.
LANGUAGE
specifies that the external routine is an HP C, HP COBOL, FORTRAN, or Pascal
routine. If you do not know if the external routine is an HP C, HP COBOL,
FORTRAN, or Pascal routine, use LANGUAGE UNSPECIFIED. The following
example shows the LANGUAGE COBOL option and a public name "a_proc" (in
HP COBOL identifier format):
PROC a_proc = "a-proc" (a, b, c)
LANGUAGE COBOL;
STRING .a, .b, .c;
EXTERNAL;
! EXTERNAL declaration for
! HP COBOL procedure
Specify no more than one LANGUAGE attribute in a declaration.
Note. Because no FORTRAN or Pascal compilers exist especially for TNS/R or TNS/E
architecture, LANGUAGE FORTRAN and LANGUAGE PASCAL have no meaning on
TNS/R or TNS/E architecture.
If a procedure declaration includes LANGUAGE, it must also include public-namespec on page 14-2.
Parameters and VARIABLE and EXTENSIBLE Procedures
To determine which parameters were passed by the caller, use the $PARAM on
page 15-77.
Memory is allocated for all parameters to VARIABLE procedures or EXTENSIBLE
procedures; therefore, your program can store default values for parameters the caller
does not pass.
HP pTAL Reference Manual—523746-006
14- 8
Procedures, Subprocedures, and Procedure
Pointers
VARIABLE, EXTENSIBLE and RETURNSCC
Procedures as Actual Parameters
VARIABLE, EXTENSIBLE and RETURNSCC Procedures as
Actual Parameters
You can pass a procedure or procedure pointer that includes an EXTENSIBLE,
VARIABLE, or RETURNSCC attribute as a parameter to a procedure whose formal
parameter is a PROC, but you cannot reference the PROC formal parameter identifier
in a CALL statement. Instead, you must assign the address from the formal parameter
to a procedure pointer and then specify the procedure pointer in a CALL statement.
Example 14-2. EXTENSIBLE Procedures as Actual Parameters
PROC p1 (i, j) EXTENSIBLE;
INT i, j;
EXTERNAL;
PROC p2( p );
PROC p;
BEGIN
PROCPTR pp(a, b) EXTENSIBLE; INT a, b; END PROCPTR;
INT i, j;
...
pp := pi;
CALL pp(i, j);
END;
PROC p3;
BEGIN
CALL p2(p1);
END;
HP pTAL Reference Manual—523746-006
14- 9
Procedures, Subprocedures, and Procedure
Pointers
Formal Parameter Specification
Formal Parameter Specification
A formal parameter specification defines the parameter type of a formal parameter and
whether the parameter is a value parameter or a reference parameter.
param-type
param-name
.
.EXT
.SG
.SGX
(
referral
)
;
REFALIGNED
(
2
)
8
,
VST636.vsd
HP pTAL Reference Manual—523746-006
14 -10
Procedures, Subprocedures, and Procedure
Pointers
Formal Parameter Specification
param-type
is the parameter type of the formal parameter and can be one of the following:
STRING
INT
REAL
UNSIGNED
(
width
)
(
width
)
FIXED
(
fpoint
)
*
STRUCT
BADDR
WADDR
EXTADDR
PROCADDR
CBADDR
CWADDR
SGBADDR
SGWADDR
SGXBADDR
SGXWADDR
PROC
type
VST637.vsd
Descriptions for STRUCT, PROC, PROC(32), and type, are included below. You
can find descriptions of the remaining data types in Section 3, Data
Representation.
STRUCT
means the parameter is one of:
•
•
A standard indirect or extended indirect definition structure (not supported
in future software platforms)
A standard indirect or extended indirect referral structure
HP pTAL Reference Manual—523746-006
14 -11
Procedures, Subprocedures, and Procedure
Pointers
Formal Parameter Specification
PROC
is the address of the entry point of a procedure. You must assign PROC to a
PROCPTR before you can call it.
type
specifies that the parameter is a function procedure, the return value of which
is one of the following data types:
STRING
INT
REAL
(
width
)
UNSIGNED
(
width
)
(
fpoint
)
FIXED
*
VST214.vsd
width
is a constant expression that specifies the number of bits in the variable.
The result of the constant expression must be one of the following values:
Data Type
width
INT
16, 32, or 64
REAL
32 or 64
UNSIGNED
A value in the range 1 through 31
UNSIGNED parameters must be passed by value; you cannot use an
indirection symbol (see Table 2-7, Indirection Symbols, on page 2-7) with
UNSIGNED parameters.
fpoint
is an integer in the range -19 through 19 that specifies the implied decimal
point position. The default is 0 (no decimal places). A positive fpoint
specifies the number of decimal places to the right of the decimal point. A
negative fpoint specifies a number of integer places to the left of the
decimal point.
*
prevents scaling of the fpoint of a FIXED actual parameter to match the
fpoint in the parameter specification. Such scaling might cause loss of
precision. The called procedure treats the actual parameter as having an
fpoint of 0.
HP pTAL Reference Manual—523746-006
14 -12
Procedures, Subprocedures, and Procedure
Pointers
Formal Parameter Specification
.
.EXT
.SG
.SGX
are indirection symbols (see Indirection Symbols on page 2-7). If present, the
parameter is passed by reference; if absent, the parameter is passed by value.
Specify reference parameters for actual parameters that will be:
•
•
•
Arrays
Structures
Simple variables (when you want to update the original value in the caller’s
scope)
param-name
is the identifier of a formal parameter. The identifier has local scope if declared in a
procedure or sublocal scope if declared in a subprocedure.
referral
is the identifier of a previously declared structure or structure pointer. The diagram
under param-type describes lists the kind parameter requiring a referral.
REFALIGNED
For simple pointers, the default for REFALIGNED is the value you specify in the
REFALIGNED on page 17-53.
2
specifies that the variables and structures that identifier references are aligned as
they would be aligned in TAL (and might not be well-aligned in pTAL).
8
specifies that the variables and structures are well-aligned in pTAL (and in TAL,
that they might have more space).
For nonstructure pointers, the default for REFALIGNED is the value you specify in
the REFALIGNED on page 17-53.
When a procedure is called, each actual parameter is bound to its corresponding
formal parameter. Parameters passed by value must follow the same rules for
assignment compatibility as do assignment statements. Each actual value parameter
corresponds to the right side of an assignment statement.
Table 14-1 on page 14-14 lists the characteristics that you can declare in a formal
parameter specification depending on the kind of actual parameter the procedure or
subprocedure expects.
HP pTAL Reference Manual—523746-006
14 -13
Procedures, Subprocedures, and Procedure
Pointers
Formal Parameter Specification
Table 14-1. Formal Parameter Specification
Formal Parameter Characteristics
Expected Actual
Parameter
Declare Formal
Parameter As:
Simple variable
A value or reference
parameter
Simple variable
A value parameter
Array or
simple pointer
Parameter Type
STRING*
INT
INT(32)
REAL
REAL(64)
FIXED(n)
FIXED(*)
Indirection
Symbol
Referral
Value, no;
reference,
yes
No
UNSIGNED
No
No
A reference
parameter
STRING
INT
INT(32)
REAL
REAL(64)
FIXED(n)
Yes
No
Definition structure,
referral structure, or
structure pointer
A reference
parameter
INT or STRING
Yes
Yes
Referral structure or
structure pointer
A reference
parameter
STRUCT
Yes
Yes
Constant
expression**
(including
@identifier )
A value parameter
INT
INT(32)
UNSIGNED
REAL
REAL(64)
FIXED(n)
No
No
Procedure
A value parameter
PROC
PROC(32)
No
No
* You cannot declare a STRING value parameter. The compiler reports a syntax error if you declare a STRING
value parameter.
** The data type of the expression and of the formal parameter must match, except that you can mix the
STRING, INT, and UNSIGNED (1-16) data types, and you can mix the INT(32) and UNSIGNED(17-31) data
types.
Any of the 10 address types can be used as formal parameters.
In Example 14-3 on page 14-15, the compiler treats var1 as if it were a simple
variable and treats var2 as if it were a simple pointer.
HP pTAL Reference Manual—523746-006
14 -14
Procedures, Subprocedures, and Procedure
Pointers
Formal Parameter Specification
Example 14-3. Function With Value and Reference Formal Parameters
PROC mult (var1, var2);
INT var1,
.var2;
BEGIN
var2 := var2 + var1;
END;
! Value parameter
! Reference parameter
! Manipulate parameters
Example 14-4. Reference Structure as a Formal Reference Parameter
STRUCT template (*);
BEGIN
INT a;
INT b;
END;
! Template structure
PROC .EXT p;
STRUCT ref_struct (template);
BEGIN
! Lots of code
END;
Topics:
•
•
•
•
Using STRUCT as a Formal Parameter on page 14-16
Passing an .EXT Parameter to a Non-EXTENDED Reference Parameter on
page 14-16
Using the PROC Formal Parameter on page 14-16
Referencing Parameters on page 14-16
HP pTAL Reference Manual—523746-006
14 -15
Procedures, Subprocedures, and Procedure
Pointers
Using STRUCT as a Formal Parameter
Using STRUCT as a Formal Parameter
You cannot declare a definition STRUCT as a formal parameter. You can, however,
achieve the same effect by using a referral STRUCT as a formal parameter, and
having it reference a previously declared structure.
Example 14-5. Using a Referral STRUCT as a Formal Parameter
STRUCT s (*);
BEGIN
INT a;
INT b;
END;
PROC p (i, j);
INT i;
STRUCT .j (s);
BEGIN
...
END;
! Template
! Declare j by referring to template s
Passing an .EXT Parameter to a Non-EXTENDED Reference
Parameter
You can pass a variable declared with a .EXT indirection symbol to a formal parameter
declared with a “.” indirection symbol. pTAL converts the extended address to a
BADDR or WADDR, as appropriate. In the following example, pTAL converts the
extended address of I to a WADDR address:
INT .EXT i;
PROC p(a);
INT .a;
BEGIN
...
END;
p(i);
Using the PROC Formal Parameter
The @ character is not allowed on the actual parameter if the formal parameter is a
PROC.
Referencing Parameters
Do not depend on the order in which parameters are allocated in memory. You must
refer to each parameter only as a named entity. Do not refer to one parameter as a
base off of which you reference other parameters.
HP pTAL Reference Manual—523746-006
14 -16
Procedures, Subprocedures, and Procedure
Pointers
Procedure Body
Guidelines:
•
•
•
•
•
Do not treat a procedure’s formal parameters as an implied array or implied
structure.
Do not index a parameter to access another parameter or local variable.
Do not perform block moves in which the source or destination spans more than
one parameter.
Do not pass the address of a value parameter to another procedure that expects
the address of an array or structure.
Do not proceed through a parameter list using indexing and address calculations.
Procedure Body
A procedure body can contain local declarations, subprocedure declarations, and
statements.
BEGIN
local-decl
subproc-decl
;
;
END
statement
VST061.vsd
local-decl
is a declaration for one of:
•
•
•
•
•
•
•
•
•
•
•
simple variable
array (direct, indirect, or read-only)
structure (direct or indirect)
simple pointer
structure pointer
equivalenced variable
LITERAL
DEFINE
label
entry point
FORWARD subprocedure
HP pTAL Reference Manual—523746-006
14 -17
Procedures, Subprocedures, and Procedure
Pointers
Procedure Body
subproc-decl
is a subprocedure declaration, as described in Subprocedure Declarations on
page 14-19.
statement
is any statement described in Section 12, Statements.
Example 14-6. Procedures
INT c;
! Global declaration
PROC first;
BEGIN
INT a,
b;
...
END;
! Procedure body
! Local declarations
PROC second;
BEGIN
...
CALL first;
...
END;
! Procedure body
! Call first procedure
Example 14-7. FORWARD Declaration for a Procedure
INT g2;
PROC procb (param1);
INT param1;
FORWARD;
PROC proca;
BEGIN
INT i1 := 2;
CALL procb (i1);
END;
PROC procb (param1);
INT param1;
BEGIN
g2 := g2 + param1;
END;
! FORWARD declaration for procb
! Call procb
! Body for procb
HP pTAL Reference Manual—523746-006
14 -18
Procedures, Subprocedures, and Procedure
Pointers
Subprocedure Declarations
Subprocedure Declarations
You can declare subprocedures within procedures, but not within subprocedures.
identifier
SUBPROC
type
parameter-list
;
VARIABLE
RETURNSCC
OVERFLOW_TRAPS
NOOVERFLOW_TRAPS
subproc-body
parameter-spec
;
;
FORWARD
VST702.vsd
type
specifies that the subprocedure is a function that returns a result and indicates the
data type of the returned result. type can be any data type described in
Section 3, Data Representation.
identifier
is the identifier of the subprocedure.
parameter-list
(
param-name
)
param-pair
,
VST210.vsd
param-name
is the identifier of a formal parameter. The number of formal parameters a
subprocedure can have is limited by space available in the parameter area of
the subprocedure.
HP pTAL Reference Manual—523746-006
14 -19
Procedures, Subprocedures, and Procedure
Pointers
Subprocedure Declarations
param-pair
is a pair of formal parameter identifiers that comprise a language-independent
string descriptor in the form:
string
:
length
VST039.vsd
string
is the identifier of a standard or extended STRING simple pointer. The
actual parameter is the identifier of a STRING array or simple pointer
declare inside or outside a structure.
length
is the identifier of a directly addressed INT simple variable. The actual
parameter is an expression that specifies the length of string in bytes.
VARIABLE
specifies that the compiler treats all parameters as optional, even if some are
required by your code.
RETURNSCC
causes a subprocedure to return a condition code. The compiler reports an error if
a subprocedure attempts to test the condition code after calling a subprocedure
that does not specify RETURNSCC. Subprocedures declared with RETURNSCC
cannot return 64-bit values.
OVERFLOW_TRAPS
enables overflow traps for a subprocedure.
NOOVERFLOW_TRAPS
disables overflow traps for a subprocedure.
parameter-spec
specifies the parameter type of a formal parameter and whether it is a value or
reference parameter, as described in Formal Parameter Specification on
page 14-10.
subproc-body
is a BEGIN-END block that contains sublocal declarations and statements—see
Subprocedure Body on page 14-21.
HP pTAL Reference Manual—523746-006
14 -20
Procedures, Subprocedures, and Procedure
Pointers
Subprocedure Body
FORWARD
means the subprocedure body is declared later in this procedure.
Subprocedure Body
A subprocedure body can contain sublocal declarations and statements.
BEGIN
END
sublocal-decl
;
;
statement
;
VST062.vsd
sublocal-decl
is a declaration for one of:
•
•
•
•
•
•
•
•
•
•
simple variable
array (direct or read-only)
structure (direct only)
simple pointer
structure pointer
equivalenced variable
LITERAL
DEFINE
label
entry point
statement
is any statement described in Section 12, Statements.
In subprocedures, declare pointers and directly addressed variables only. Here are
examples:
Sublocal Variable
Example
Simple variable
(always direct)
INT var;
Direct array
INT array[0:5];
Read-only array
INT ro_array = 'P' := [0,1,2,3,4,5];
Simple variable
(always direct)
INT var;
Direct array
INT array[0:5];
Read-only array
INT ro_array = 'P' := [0,1,2,3,4,5];
HP pTAL Reference Manual—523746-006
14 -21
Procedures, Subprocedures, and Procedure
Pointers
Entry-Point Declarations
Example 14-8. Function Subprocedure
PROC p;
BEGIN
SUBPROC p1;
BEGIN
INT .a[0:9];
INT .ext b[0:9];
a[0] := 1;
b[9] := 2;
END;
CALL p1;
END;
PROC q;
BEGIN
SUBPROC q1;
BEGIN
STRUCT .s;
BEGIN
INT i;
INT j;
END;
END;
END;
Entry-Point Declarations
The entry-point declaration associates an identifier with a secondary location in a
procedure or subprocedure where execution can start.
ENTRY
identifier
;
,
VST195.vsd
identifier
is an entry-point identifier to be placed in the procedure or subprocedure body. It is
an alternate or secondary point in the procedure or subprocedure at which to start
executing.
Topics:
•
•
Procedure Entry-Point Identifiers on page 14-23
Subprocedure Entry-Point Identifiers on page 14-24
HP pTAL Reference Manual—523746-006
14 -22
Procedures, Subprocedures, and Procedure
Pointers
Procedure Entry-Point Identifiers
Procedure Entry-Point Identifiers
Here are guidelines for using procedure entry point identifiers:
•
•
•
•
•
•
•
Declare all entry-point identifiers for a procedure within the procedure.
Place each entry-point identifier and a colon (:) at a point in the procedure at which
execution is to start.
You can call a procedure entry-point identifier from anywhere in the program. (For
functions, use the entry-point identifier in an expression; for other procedures, use
a CALL statement.)
Pass actual parameters as if you were calling the procedure identifier.
You cannot use a GOTO statement to branch to a procedure entry-point identifier.
To obtain the address of a procedure entry-point identifier, preface the identifier
with @.
You can specify FORWARD or EXTERNAL procedure entry-point declarations,
which look like FORWARD procedure declarations and EXTERNAL procedure
declarations.
Example 14-9. Procedure Entry-Point Identifiers
INT to_this := 314;
! Declare global data
PROC add_3 (g2);
INT .g2;
BEGIN
ENTRY add_2;
ENTRY add_1;
INT m2 := 1;
! Declare entry-point identifiers
g2 := g2 + m2;
add_2:
g2 := g2 + m2;
! Location of entry-point identifier add_2
add_1:
g2 := g2 + m2;
END;
! Location of entry-point identifier add_1
PROC mymain MAIN;
BEGIN
CALL add_1 (to_this);
END;
! Main procedure
! Call entry point add_1
HP pTAL Reference Manual—523746-006
14 -23
Procedures, Subprocedures, and Procedure
Pointers
Subprocedure Entry-Point Identifiers
Example 14-10. FORWARD Declarations for Entry Points
INT to_this := 314;
PROC add_1 (g2);
INT .g2;
FORWARD;
! FORWARD entry-point identifier
! declaration
PROC add_2 (g2);
INT .g2;
FORWARD;
! FORWARD entry-point identifier
! declaration
PROC add_3 (g2);
INT .g2;
FORWARD;
! FORWARD procedure declaration
PROC mymain MAIN;
BEGIN
CALL add_1 (to_this);
END;
! Main procedure declaration
PROC add_3 (g2);
INT .g2;
BEGIN
ENTRY add_2;
ENTRY add_1;
INT m2 := 1;
! Body for FORWARD procedure
! Call entry-point identifier
! Declare entry-point identifiers
g2 := g2 + m2;
add_2:
g2 := g2 + m2;
! Location of entry-point identifier
! add_2
add_1:
g2 := g2 + m2;
END;
! Location of entry-point identifier
! add_1
Subprocedure Entry-Point Identifiers
Here are guidelines for using subprocedure entry-point identifiers:
•
•
•
•
•
Declare all entry-point identifiers for a subprocedure within the subprocedure.
Place each entry-point identifier and a colon (:) at a point in the subprocedure at
which execution is to start.
You call a subprocedure entry-point identifier from anywhere in the encompassing
procedure, including from within the same subprocedure. (For functions, use the
entry-point identifier in an expression; for other subprocedures, use a CALL
statement.)
Pass actual parameters as if you were calling the subprocedure identifier.
You cannot use a GOTO statement to branch to a subprocedure entry-point
identifier.
HP pTAL Reference Manual—523746-006
14 -24
Procedures, Subprocedures, and Procedure
Pointers
•
•
Subprocedure Entry-Point Identifiers
To obtain the code address of a subprocedure entry-point identifier, preface the
identifier with @.
You can specify FORWARD subprocedure entry-point declarations, which look like
FORWARD subprocedure declarations.
Example 14-11. Subprocedure Entry-Point Identifiers
literal write_op,
read_op,
writeread_op,
readwrite_op;
int proc io (op, buf);
int
op;
int .ext buf;
begin
int subproc do_read_op (buf);
int .ext buf;
forward;
int subproc do_write_op (buf);
int .ext buf;
forward;
int subproc do_writeread_op (buf);
int .ext buf;
begin
entry do_read_op;
call do_write_op (buf);
do_read_op:
! Perform read operation
end;
int subproc do_readwrite_op (buf);
int .ext buf
begin
entry do_write_op;
call do_read_op (buf);
do_write_op:
! Perform write operation
end;
case op of
begin
! write_op !
! read_op !
! writeread_op !
! readwrite_op !
end;
end;
call
call
call
call
do_write_op (buf);
do_read_op (buf);
writeread_op (buf);
readwrite_op (buf);
HP pTAL Reference Manual—523746-006
14 -25
Procedures, Subprocedures, and Procedure
Pointers
Procedure Pointers
Procedure Pointers
Procedure pointers allow a program to call a variable dynamically or to call an
EXTENSIBLE procedure.
The syntax of procedure pointers is similar to the syntax of forward procedures;
however, instead of the keyword PROC, you declare a procedure pointer using the
keyword PROCPTR. As with a forward procedure, a procedure pointer fully specifies
the procedure’s attributes and formal parameters but has no body—a procedure
pointer does not include executable statements.
You can declare procedure pointers as:
•
•
•
Variables
Formal parameters
Structure fields
procptr-name
PROCPTR
return-type
formal-param-names
formal-param-spec
attributes
END
;
PROCPTR
VST600.vsd
return-type
specifies that the procedure is a function that returns a result and indicates the
data type of the returned result, and can be any of:
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
BADDR
CBADDR
CWADDR
EXTADDR
FIXED
FIXED [(scale )]
INT
REAL
REAL(64)
PROCADDR
SGWADDR
SGBADDR
SGXWADDR
SGXBADDR
STRING
HP pTAL Reference Manual—523746-006
14 -26
Procedures, Subprocedures, and Procedure
Pointers
•
•
Procedure Pointers
UNSIGNED (width )
WADDR
scale
is a constant integer expression from -19 to 19.
width
is a constant integer expression from 1 to 31.
procptr-name
is the name of the procedure pointer.
formal-param-names
is the identifier of a formal parameter. A procedure can have up to 32 formal
parameters, with no limit on the number of words of parameters and has the form:
(
)
param-name
param-pair
,
VST210.vsd
param-name
is the identifier of a formal parameter. A procedure can have up to 32 formal
parameters, with no limit on the number of words of parameters.
param-pair
is a pair of formal parameter identifiers that comprise a language-independent
string descriptor in the form:
string
:
length
VST039.vsd
string
is the identifier of a standard or extended STRING simple pointer. The
actual parameter is the identifier of a STRING array or simple pointer
declared inside or outside a structure.
HP pTAL Reference Manual—523746-006
14 -27
Procedures, Subprocedures, and Procedure
Pointers
Procedure Pointers
length
is the identifier of a directly addressed INT simple variable. The actual
parameter is an INT expression that specifies the length of string in
bytes.
attributes
is an attribute described in Procedure Attributes on page 14-5.
formal-param-spec
is a formal parameter and has the following form:
procptr
param-type
identifier
.
.EXT
.SG
.SGX
(
referral
)
,
VST712.vsd
procptr
is a pointer identifier.
param-type
is any data type described in the data-type parameter of this syntax
description.
.
.EXT
.SG
.SGX
are indirection symbols (see Indirection Symbols on page 2-7). If present, the
parameter is passed by reference; if absent, the parameter is passed by value.
identifier
is an identifier (as described in Identifiers on page 2-8).
HP pTAL Reference Manual—523746-006
14 -28
Procedures, Subprocedures, and Procedure
Pointers
Declaring PROCPTR Variables
referral
is the name of a previously declared structure or structure pointer. You must
include referral if the formal parameter identifier is the name of a
structure.
Topics:
•
•
•
•
•
Declaring PROCPTR Variables on page 14-29
Declaring PROCPTR in Structures on page 14-30
Declaring PROCPTRs as Formal Parameters on page 14-32
Assignments to PROCPTRs on page 14-33
Dynamically Selected Procedure Calls on page 14-35
Declaring PROCPTR Variables
procptr
=
prev-identifier
:=
procaddr
;
VST714.vsd
procptr
is a pointer identifier.
prev-identifier
is the identifier of a previously declared variable. On TNS architecture, previdentifier must be 16 bits. On TNS/R and TNS/E architecture, previdentifier must be 32 bits or more.
procaddr
is a constant or dynamic expression of type PROCADDR. procaddr must be the
name of a procedure, procedure pointer, or PROCADDR variable. If procaddr is
a procedure or procedure pointer, the parameters of procptr and procaddr
must match and the following procedure attributes must match: EXTENSIBLE,
VARIABLE, RETURNSCC, MAIN, and INTERRUPT; the following procedure
attributes do not have to match: OVERFLOW_TRAPS, CALLABLE, PRIV, and
RESIDENT.
You can declare a PROCPTR anywhere a data declaration is valid. For purposes of
declarations, PROCPTRs are treated as data, not as procedures.
The address type of a PROCPTR is PROCADDR.
The address type of a PROCADDR variable is WADDR.
HP pTAL Reference Manual—523746-006
14 -29
Procedures, Subprocedures, and Procedure
Pointers
Declaring PROCPTR in Structures
The object data type of a reference to a function PROCPTR is the data type returned
by the PROCPTR.
You can equivalence a PROCPTR to any previously declared variable provided that
the width of the previous variable is greater than or equal to the width of the
PROCPTR.
Example 14-12. PROCPTRs as Variables and Formal Parameters
INT
i;
INT .EXT j;
REAL
k;
PROCADDR pa;
PROC p (i, j) EXTENSIBLE, CALLABLE;
INT i, .EXT j;
FORWARD;
! Declare PROC p in a
! FORWARD declaration
PROCPTR a (i, j) EXTENSIBLE,CALLABLE;
INT i, .EXT j;
END PROCPTR := @p;
! Declare PROCPTR a and
! initialize it to point
! to PROC p
FIXED PROCPTR b (str : length);
STRING .str;
INT
length;
END PROCPTR;
! Declare FIXED PROCPTR b
! with one
! parameter pair
PROCPTR c (p);
REAL PROCPTR p(x);
REAL x;
END PROCPTR;
! Declare PROCPTR c
! with one parameter, p,
! a PROCPTR
REAL PROCPTR d (x);
REAL x;
END PROCPTR;
! Declare REAL PROCPTR d
! with one
! REAL parameter
PROCPTR e(i);
INT i;
END PROCPTR = d;
! Declare PROCPTR e
! Equivalence e to d
Declaring PROCPTR in Structures
You can declare PROCPTR fields within structure declarations.
procptr
;
=
prev-identifier
VST715.vsd
procptr
is a pointer identifier.
HP pTAL Reference Manual—523746-006
14 -30
Procedures, Subprocedures, and Procedure
Pointers
Declaring PROCPTR in Structures
previous-identifier
The identifier of a field at the same level as procptr in the same structure.
Example 14-13 on page 14-31 declares a REAL PROCPTR as a field in a structure
array of 10 elements. Use an index to reference elements of array s1:
CALL s1[3].f(3.0e1);
Example 14-13. PROCPTR in a Structure
STRUCT s1 [0:9];
BEGIN
REAL PROCPTR f(x); REAL x; END PROCPTR;
END;
Example 14-14 on page 14-31 declares a template structure s2 with three
components. When s2 is the referent of a referral structure, pTAL allocates space for
PROCPTR f. pTAL does not allocate space for PROCPTRs g or h because they
redefine PROCPTR f. PROCPTRs f, g, and h are the same except for the type of the
parameter passed to the procedure.
Example 14-14. PROCPTRs in Structure
STRUCT s2 (*);
BEGIN
REAL PROCPTR f(x);
REAL x;
END PROCPTR;
REAL PROCPTR g(x);
INT x;
END PROCPTR = f;
REAL PROCPTR h(x);
FIXED x;
END PROCPTR = g;
END;
The code in Example 14-15 on page 14-31 uses the structure s2 in Example 14-14 on
page 14-31.
Example 14-15. Code That Uses the Structure in Example 14-14 on page 14-31
STRUCT s(s2);
REAL my_real;
INT my_index := type_int;
CASE my_index OF
BEGIN
type_real -> my_real := s.f(3.0E1);
type_int
-> my_real := s.g(3);
type_fixed -> my_real := s.h(3F);
END;
HP pTAL Reference Manual—523746-006
14 -31
Procedures, Subprocedures, and Procedure
Pointers
Declaring PROCPTRs as Formal Parameters
Declaring PROCPTRs as Formal Parameters
The compiler:
•
•
Ensures that the procedure attributes and parameter data types of procedures
passed as actual parameters match those defined in the formal parameters of the
called procedure
Builds parameter masks for calls to VARIABLE procedures and EXTENSIBLE
procedures
You can declare a formal parameter to be a PROCPTR as in the following example:
PROC p(pp);
PROCPTR pp(i, j);
INT i, j;
END PROCPTR;
BEGIN
...
END;
An @ character in front of the actual parameter is:
•
•
Not allowed if the formal parameter is a PROC or a PROCPTR
Required if the formal parameter is a PROCADDR
Example 14-16. PROCPTRs as Formal Parameters
PROC a(i);
INT i;
EXTERNAL;
PROC b(p);
PROCPTR p(a);
INT a;
END PROCPTR;
EXTERNAL;
PROC c(pa);
PROCADDR pa;
BEGIN
END;
PROC d;
BEGIN
CALL b(a);
CALL b(@a);
CALL c(a);
CALL c(@a);
END;
!
!
!
!
OK
ERROR: @ character is not valid
ERROR: @ character is required
OK: @ character is required
HP pTAL Reference Manual—523746-006
14 -32
Procedures, Subprocedures, and Procedure
Pointers
Assignments to PROCPTRs
Assignments to PROCPTRs
You can assign values to a PROCPTR variable in much the same way as you assign
values to any variable; however, only values of data type PROCADDR can be
assigned to a PROCPTR.
You can assign the following items to a PROCPTR:
•
•
•
The address of a procedure or function
The value of another PROCPTR
The value of a variable whose data type is PROCADDR
Assignment statements involving PROCPTRs fall into one of two categories:
•
•
If the left side is a PROCPTR and right side is an @ character followed by the
name of a procedure, subprocedure, or function—that is, neither the left side nor
the right side is a PROCADDR variable—the attributes and the formal parameter
types of each side of the assignment must match. The attributes specified must be
the same but do not have to be presented in the same order.
If either the left side or the right side of the assignment statement is a PROCADDR
variable, the compiler does not attempt to match attributes or parameter types.
Example 14-17. Assignments to PROCPTRs
PROCPTR pp1 (a, b) RETURNSCC;
INT a, b;
END PROCPTR;
PROCPTR pp2 (a) RETURNSCC;
INT a;
END PROCPTR;
PROCPTR pp3 (a, b);
INT a, b;
END PROCPTR;
PROC p(i, j) RETURNSCC;
INT i, j;
BEGIN
RETURN ,j;
END;
PROCADDR paddr;
paddr := @p;
@pp1 := @p;
@pp1 := @pp2;
@pp1 := @pp3;
paddr := @pp2;
@pp1 := paddr;
!
!
!
!
!
!
OK: PROCADDR variable is assigned PROC addr
OK: Left side is PROCPTR, right side is PROC
ERROR: pp1 has two parameters, pp2 has one
ERROR: pp1 specifies RETURNSCC, pp3 does not
OK: paddr is a PROCADDR variable
OK: paddr is a PROCADDR variable
HP pTAL Reference Manual—523746-006
14 -33
Procedures, Subprocedures, and Procedure
Pointers
Assignments to PROCPTRs
Example 14-18. Assignments to PROCPTRs
REAL r;
INT i;
STRUCT s1 [0:9];
BEGIN
REAL PROCPTR f(x);
REAL x;
END PROCPTR;
END;
PROC p (i, j) EXTENSIBLE, CALLABLE;
INT i, .EXT j;
FORWARD;
! Declare PROC p in a
! FORWARD declaration
PROCPTR a (i, j) EXTENSIBLE,CALLABLE;
INT i, .EXT j;
END PROCPTR;
! Declare PROCPTR a and
! initialize it to
! point to PROC p
PROCPTR c (p);
REAL PROCPTR p (x);
REAL x;
END PROCPTR;
END PROCPTR;
REAL PROCPTR d (x);
REAL x;
END PROCPTR;
! Declare REAL PROCPTR d
! with REAL parametera
@a := @p;
@d := @s1[2].f;
@s1[3].f := @d;
CALL c(d);
Once you have set up a PROCPTR to point to a procedure, you can call the procedure
by using the PROCPTR name in a CALL statement or, if the PROCPTR is typed, in an
expression:
CALL a(1, 2);
r := d(r);
IF (s1[i].f(r)) < 1.0E0 THEN ...
HP pTAL Reference Manual—523746-006
14 -34
Procedures, Subprocedures, and Procedure
Pointers
Dynamically Selected Procedure Calls
Dynamically Selected Procedure Calls
You can use a PROCPTR to dynamically select a procedure to call.
Example 14-19. Dynamically Selected Procedure Call
LITERAL dev_6530, dev_3270, dev_dove;
INT device_type;
INT param1, param2;
PROC device_6530(i, j);
INT i, j;
EXTERNAL;
PROC device_3270(i, j);
INT i, j;
EXTERNAL;
PROC device_dove(i, j);
INT i, j;
EXTERNAL;
PROCPTR p(i, j);
INT i, j;
END PROCPTR;
CASE device_type of
BEGIN
dev_6530 -> @p := @device_6530;
dev_3270 -> @p := @device_3270;
dev_dove -> @p := @device_dove;
END;
CALL p(param1, param2);
Although you cannot create an array of PROCPTRs, you can create a structure that
includes a PROCPTR field. You can choose dynamically which PROCPTR in the
structure array to call.
HP pTAL Reference Manual—523746-006
14 -35
Procedures, Subprocedures, and Procedure
Pointers
Dynamically Selected Procedure Calls
Example 14-20. Dynamically Selected Procedure Call
LITERAL dev_6530, dev_3270, dev_dove;
STRUCT s1 [dev_6530:dev_dove];
BEGIN
PROCPTR d(device, param);
INT device, param;
END PROCPTR;
END;
! Array of PROCPTRs
PROC device_6530(i, j);
INT i, j;
EXTERNAL;
PROC device_3270(i, j);
INT i, j;
EXTERNAL;
PROC device_dove(i, j);
INT i, j;
EXTERNAL;
You must initialize the array s1 to hold the addresses of the procedures that you want
to dynamically call, as in the following example:
@s1[dev_6530].d := @device_6530;
@s1[dev_3270].d := @device_3270;
@s1[dev_dove].d := @device_dove;
Use an index to choose which element of array s1 to call, as in the following example:
CALL s1[dev_6530].d(80, 2);
HP pTAL Reference Manual—523746-006
14 -36
Procedures, Subprocedures, and Procedure
Pointers
Labels in Procedures
Labels in Procedures
A label is the target location of a GOTO statement.
identifier
LABEL
;
,
VST196.vsd
identifier
is as described in Identifiers on page 2-8. It cannot be an entry-point identifier.
The following guidelines apply:
•
•
•
LABEL is not a valid data type for a formal procedure parameter. You cannot pass
a label to a procedure.
A label is not a valid actual procedure parameter.
If a GOTO statement in a subprocedure branches to a label in the containing
procedure, the label must be declared in a LABEL declaration in the containing
procedure, before the subprocedure that contains the GOTO statement (see
Nonlocal on page 12-24).
Note. This is not recommended in pTAL because it is very inefficient.
•
The executable statement identified by a label cannot be an IF statement that tests
the hardware indicator.
The conditional expression in an IF statement that is identified by a label cannot test a
hardware indicator.
Example 14-21. IF Statements Identified by Labels
INT i, j := 0;
i := i + 1;
IF < THEN ...
! OK
i := i + 1
label_a:
IF < THEN ...
! ERROR: label cannot immediately precede an
! IF statement that tests a hardware indicator
HP pTAL Reference Manual—523746-006
14 -37
Procedures, Subprocedures, and Procedure
Pointers
HP pTAL Reference Manual—523746-006
14 -38
Labels in Procedures
15
Built-In Routines
Topics:
•
•
•
•
•
Privileged Mode on page 15-1
Parameters on page 15-2
Hardware Indicators on page 15-4
Atomic Operations on page 15-4
Nonatomic Operations on page 15-11
Built-in routine calls whose results do not depend on the values of variables (such as
$LEN(n ) or $INT(10D)) can be used wherever constant values are allowed.
The syntax descriptions in this section use these terms:
Term
Definition
sINT
Signed 16-bit integer. Range is -32,768 through 32,767.
uINT
Unsigned 16-bit integer. Range is 0 through 65,535. Must be an INT variable, not
a STRING or UNSIGNED variable.
word
16-bit word unless otherwise specified
“sINT” and “uINT” are not pTAL data types. This section uses them only to specify how
built-in routines use INT parameters.
Privileged Mode
Many built-in routines can be executed only by processes running in privileged mode.
Routines that operate in privileged mode can:
•
•
•
•
Call other routines that operate in privileged mode
Perform privileged operations by means of calls to system procedures
Execute privileged instructions that can affect other programs or the operating
system
Use system global pointers and 'SG' equivalencing to:
°
Access system tables (which are described in the system description manual
for your system)
°
°
°
Access the system data area
Compare and move data between the system data area and the user data area
Initiate certain input-output transfers
(Only procedures that operate in privileged mode can access system global data.)
HP pTAL Reference Manual—523746-006
15- 1
Built-In Routines
Parameters
Routines that operate in privileged mode must be specially licensed, because they
might (if improperly written) adversely affect the status of the processor in which they
are running.
The following execute in privileged mode:
•
•
•
•
CALLABLE procedures (that is, procedures declared with the attribute CALLABLE
on page 14-6)
PRIV procedures (that is, procedures declared with the attribute PRIV on
page 14-6)
Nonprivileged procedures that are called by CALLABLE or PRIV procedures
pTAL Privileged Routines on page 15-11
Parameters
Parameters of built-in routines are always passed by value.
Topics:
•
•
Addresses as Parameters on page 15-2
Expressions as Parameters on page 15-3
Addresses as Parameters
If a parameter of a built-in routine is an address, the address must have the correct
address type—whether the parameter is an input parameter, an output parameter, or
both.
In Example 15-1 on page 15-2, the built-in routine $BUILT_IN_1 has one formal
parameter whose data type is BADDR. The corresponding actual parameter must be
either a BADDR variable or the address field of a STRING pointer.
Example 15-1. Built-In Routine With Address Parameter
BADDR
b;
STRING .s;
$BUILT_IN_1(b);
$BUILT_IN_1(@s);
$BUILT_IN_1(s);
! OK: data type of b is BADDR
! OK: address type of @s is BADDR
! ERROR: data type of s is STRING
If an output parameter of a built-in routine is an address, the corresponding actual
parameter must not be an indirect array pointer or an indirect structure pointer.
In Example 15-2 on page 15-3, the built-in routine $BUILT_IN_2 has one formal output
parameter whose data type is BADDR.
HP pTAL Reference Manual—523746-006
15- 2
Built-In Routines
Expressions as Parameters
Example 15-2. Built-In Routine With Address Output Parameter
STRING .s[0:99];
$BUILT_IN_2(@s);
! ERROR: s has no address container
! in which to store a new address
Expressions as Parameters
Many built-in routines accept expressions as parameters (see their individual syntax
descriptions). If a parameter of a built-in routine is an expression:
•
•
•
The value of the expression can be any data type except STRING or UNSIGNED.
Except in INT and INT(32) expressions, all operands must be of the same data
type.
An INT expression can include STRING, INT, and UNSIGNED(1-16) operands.
The system treats STRING and UNSIGNED(1-16) operands as if they were 16-bit
values; that is, the system:
•
°
Places a STRING operand in the right byte of a word and sets the left byte to
0.
°
Places an UNSIGNED(1-16) operand in the right bits of a word and sets the
unused left bits to 0.
An INT(32) expression can include INT(32) and UNSIGNED(17-31) operands.
The system treats UNSIGNED(17-31) operands as if they were 32-bit values.
Before evaluating the expression, the system places an UNSIGNED(17-31)
operand in the right bits of a doubleword and sets the unused left bits to 0.
•
The built-in routine, not the expression or its data type, determines whether the
value of the parameter is signed or unsigned:
°
Built-in routines that expect signed arguments treat unsigned expressions as if
they were signed.
°
Built-in routines that expect unsigned arguments treat signed expressions as if
they were unsigned.
HP pTAL Reference Manual—523746-006
15- 3
Built-In Routines
Hardware Indicators
Hardware Indicators
The description of each built-in routine specifies which hardware indicators (condition
code, $CARRY, and $OVERFLOW) the built-in routine sets. If the description does not
specify the conditions for which the built-in routine sets the value of a hardware
indicator, see the system description manual for your system.
If a built-in routine does not set a particular hardware indicator, then the value of that
hardware indicator is undefined after the built-in routine completes. If you reference a
hardware indicator when its value is undefined, the compiler reports a syntax error.
If the value of $OVERFLOW would be nonzero after executing a built-in routine, an
overflow trap occurs if overflow traps are enabled. If overflow traps are disabled, you
must test $OVERFLOW explicitly in your program.
For general information about hardware indicators, see Section 13, Hardware
Indicators.
Atomic Operations
The built-in routines in Table 15-1 on page 15-4 perform atomic operations. No other
process can access the memory referenced by an atomic operation until the atomic
operation completes; for example, $ATOMIC_ADD is equivalent to the following
algorithm:
var := var + value;
After the atomic operation reads var, no other process can access the memory
location associated with var until the read completes. The read, add, and store
operations are performed without interruption, as if the three operations were one.
Table 15-1. Built-In Routines for Atomic Operations
Routine
Atomic Operation
Can Set ...
$ATOMIC_ADD
Adds two INT values
Condition code
$CARRY
$OVERFLOW
$ATOMIC_AND
Performs a LAND on two INT values
Condition code
$ATOMIC_DEP
Deposits bits into an INT variable
Condition code
$ATOMIC_GET
Gets (returns) the value of a variable
Condition code
$ATOMIC_OR
Performs a LOR on two INT values
Condition code
$ATOMIC_PUT
Puts a value into a variable
HP pTAL Reference Manual—523746-006
15- 4
Built-In Routines
$ATOMIC_ADD
$ATOMIC_ADD
$ATOMIC_ADD atomically adds two INT values.
$ATOMIC_ADD
(
var
,
value
)
;
VST607.vsd
Sets condition code
Yes (according the final value of var )
Sets $CARRY
Yes, if traps are disabled
Sets $OVERFLOW
Yes, if traps are disabled; otherwise, traps on overflow
var
input,output
sINT:variable
is the variable that $ATOMIC_ADD increments.
value
input
sINT:value
is the value $ATOMIC_ADD adds to var.
$ATOMIC_ADD performs the following operation:
var := var + value
The read, add, and store operations are performed without interruption, as if the three
operations were one.
Example 15-3. $ATOMIC_ADD Routine
INT var;
INT value;
$ATOMIC_ADD (var, value);
The following table shows examples of $ATOMIC_ADD:
var
value
result
%H1234
%HAAAA
%HBCDE
%H1234
%H5555
%H6789
%H6789
%HAAAA
%H1233
%H6789
%H5555
%HBCDE
HP pTAL Reference Manual—523746-006
15- 5
Built-In Routines
$ATOMIC_AND
$ATOMIC_AND
$ATOMIC_AND performs an atomic LAND on two INT values.
$ATOMIC_AND
(
var
,
mask
)
;
VST608.vsd
Sets condition code
Yes (according the final value of var )
Sets $CARRY
No
Sets $OVERFLOW
No
var
input,output
sINT:variable
is the variable to which $ATOMIC_AND applies mask.
mask
input
INT:value
is a 16-bit mask that $ATOMIC_AND applies to var.
$ATOMIC_AND performs the following operation:
var := var LAND mask
The read, LAND, and store operations are performed without interruption, as if the
three operations were one.
Example 15-4. $ATOMIC_AND Routine
INT var;
INT mask;
$ATOMIC_AND(var, mask);
The following table shows examples of $ATOMIC_AND:
var
value
result
%H1234
%HAAAA
%HBCDE
%H1234
%H5555
%H6789
%H6789
%HAAAA
%H1233
%H6789
%H5555
%HBCDE
HP pTAL Reference Manual—523746-006
15- 6
Built-In Routines
$ATOMIC_DEP
$ATOMIC_DEP
$ATOMIC_DEP atomically deposits bits into an INT variable.
$ATOMIC_DEP
value
)
(
var
,
mask
,
;
VST609.vsd
Sets condition code
Yes (according the final value of var )
Sets $CARRY
No
Sets $OVERFLOW
No
var
input,output
INT:variable
is the variable into which $ATOMIC_DEP deposits bits from value.
mask
input
INT:value
is a 16-bit mask word that determines which bits of value to deposit into var.
$ATOMIC_DEP stores into each bit position of var. The corresponding bit in
value after performing an “and” operation between the corresponding bits in
value and mask.
value
input
INT:value
holds the bits that, after being masked, $ATOMIC_DEP deposits in var.
$ATOMIC_DEP performs the following operation:
var := (var LAND $COMP(mask)) LOR (value LAND mask)
All the operations are performed without interruption, as if they were one.
Example 15-5. $ATOMIC_DEP Routine
INT var;
INT mask;
INT value;
$ATOMIC_DEP(var, mask, value);
HP pTAL Reference Manual—523746-006
15- 7
Built-In Routines
$ATOMIC_GET
The following table shows examples of $ATOMIC_DEP:
var
value
mask
result
%H0000
%H1234
%HAAAA
%H0220
%H0000
%H1234
%H5555
%H1010
%H0000
%H6789
%HAAAA
%H2288
%H0000
%H6789
%H5555
%H1010
$ATOMIC_GET
$ATOMIC_GET atomically gets (returns) the value of a variable.
$ATOMIC_GET
(
var
)
;
VST610.vsd
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
var
input
type:variable
is the variable whose value $ATOMIC_GET returns. var must be one of:
•
•
A well-aligned byte, 2-byte, or 4-byte variable whose address is an integral
multiple of its width.
A bit field fully contained in a 1-byte, 2-byte, or 4-byte variable that is
aligned on an even-byte boundary.
If var is not well aligned, an error occurs.
The operation is performed without interruption.
Example 15-6. $ATOMIC_GET Routine
INT var1;
INT var2;
var1 := $ATOMIC_GET(var2);
if < then ...
! OK: $ATOMIC_GET sets condition code
HP pTAL Reference Manual—523746-006
15- 8
Built-In Routines
$ATOMIC_OR
$ATOMIC_OR
$ATOMIC_OR performs an atomic LOR on two INT values.
$ATOMIC_OR
(
var
,
mask
)
;
VST611.vsd
Sets condition code
Yes (according the final value of var )
Sets $CARRY
No
Sets $OVERFLOW
No
var
input,output
INT:variable
is the variable to which $ATOMIC_OR applies mask.
mask
input
INT:value
is a 16-bit mask that $ATOMIC_OR applies to var.
$ATOMIC_OR performs the following statement:
var := var LOR mask
The read, LOR, and store operations are performed without interruption, as if the three
operations were one.
Example 15-7. $ATOMIC_OR Routine
INT var;
INT mask;
$ATOMIC_OR(var, mask);
The following table shows examples of $ATOMIC_OR:
var
mask
result
%H1234
%HAAAA
%HBABC
%H1234
%H5555
%H5775
%H6789
%HAAAA
%HEFAB
%H6789
%H5555
%H77DB
HP pTAL Reference Manual—523746-006
15- 9
Built-In Routines
$ATOMIC_PUT
$ATOMIC_PUT
$ATOMIC_PUT atomically puts a value into a variable.
$ATOMIC_PUT
(
,
var
value
)
;
VST612.vsd
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
var
output
type:variable
the variable into which $ATOMIC_PUT stores value. var must be one of:
•
•
A 1-byte, 2-byte, or 4-byte variable whose address is an integral multiple of
its width.
A bit field fully contained in a 1-byte, 2-byte, or 4-byte variable that is
aligned on an even-byte boundary.
value
input
type:value
the value $ATOMIC_PUT stores in var. value must be assignmentcompatible with var.
$ATOMIC_PUT performs the following action:
var := value
Example 15-8. $ATOMIC_PUT Routine
INT var;
INT value;
$ATOMIC_PUT(var, value);
HP pTAL Reference Manual—523746-006
15 -10
Built-In Routines
Nonatomic Operations
Nonatomic Operations
•
•
•
•
•
•
•
•
•
•
•
pTAL Privileged Routines on page 15-11
Type-Conversion Routines on page 15-12
Address-Conversion Routines on page 15-14
Character-Test Routines on page 15-14
Minimum and Maximum Routines on page 15-15
Arithmetic Routines on page 15-15
Carry and Overflow Routines on page 15-15
FIXED-Expression Routines on page 15-15
Variable-Characteristic Routines on page 15-16
Procedure-Parameter Routines on page 15-16
Miscellaneous Routines on page 15-16
Table 15-13 on page 15-17 lists the built-in routines for nonatomic operations
alphabetically and shows which hardware indicators they can can set.
pTAL Privileged Routines
pTAL privileged routines execute in privileged mode (see Privileged Mode on
page 15-1).
The pTAL compiler supports all pTAL privileged routines except $TRIGGER.
The EpTAL compiler supports no pTAL privileged routines except $TRIGGER.
Table 15-2. pTAL Privileged Routines (page 1 of 2)
Procedure
Description
$AXADR
Converts a standard address or a relative extended address to an
absolute extended address
$EXECUTEIO
Executes an I/O operation
$FREEZE
Freezes (halts) the processor in which its process is running and any
other processes on the same node that have FREEZE enabled
$HALT
Halts the processor in which its process is running
$INTERROGATEIO
Stores cause and status information from an I/O interrupt
$LOCKPAGE
Locks one page of memory
$READBASELIMIT
Returns the base and limit of the current extended segment
HP pTAL Reference Manual—523746-006
15 -11
Built-In Routines
Type-Conversion Routines
Table 15-2. pTAL Privileged Routines (page 2 of 2)
Procedure
Description
$TRIGGER
Replaces $FREEZE and $HALT, which are available only for code
generated for the TNS/R architecture
$UNLOCKPAGE
Unlocks one page of memory
$WRITEPTE
Writes a segment-page-table entry
Type-Conversion Routines
A type-conversion routine converts its argument or arguments from one data type to
another data type.
Table 15-3. Built-In Type-Conversion Routines (page 1 of 2)
Routine
Converts ...
To ...
$ASCIITOFIXED
ASCII value
FIXED value
$DBL
INT, INT(32), FIXED, REAL,
or REAL(64), or
UNSIGNED(1-31) value
INT(32) value
EXTADDR or PROCADDR
address
$DBLL
Two INT values
INT(32) value
$DBLR
INT, INT(32), FIXED, REAL,
or REAL(64) value
Rounded INT(32) value
$DFIX
INT(32) value
FIXED(fpoint ) value
$EFLT
INT, INT(32),
FIXED(fpoint ), REAL, or
REAL(64) value
REAL(64) value
$EFLTR
INT, INT(32),
FIXED(fpoint ), or REAL,
or REAL(64) value
Rounded REAL(64) value
$FIX
INT, INT(32), REAL,
REAL(64), or FIXED value
signed FIXED value
$FIXD
FIXED value
INT(32) value
$FIXEDTOASCII
Absolute value of a FIXED
value
ASCII value
$FIXEDTOASCIIRESIDUE
Same as $FIXEDTOASCII but returns the value of the residue
$FIXI
FIXED value
Signed INT value
$FIXL
FIXED value
Unsigned INT value
$FIXR
INT, INT(32), REAL,
REAL(64), or FIXED value
Rounded FIXED value
HP pTAL Reference Manual—523746-006
15 -12
Built-In Routines
Type-Conversion Routines
Table 15-3. Built-In Type-Conversion Routines (page 2 of 2)
Routine
Converts ...
To ...
$FLT
INT, INT(32),
FIXED(fpoint ), REAL, or
REAL(64) value
REAL value
$FLTR
INT, INT(32),
FIXED(fpoint ), REAL, or
REAL(64) value
Rounded REAL value
$HIGH
Upper 16 bits of an INT(32)
or EXTADDR value
INT value
$IFIX
Signed INT value
FIXED(fpoint ) value
$INT
INT, INT(32), FIXED,
UNSIGNED (1-31), REAL, or
REAL(64) value
INT value
Some address types
$INT_OV
Same as $INT, but sets $OVERFLOW in some cases
$INTR
Low-order 16 bits of an INT,
INT(32), or FIXED value
Rounded INT value
REAL or REAL(64) value
$LFIX
Unsigned INT value
FIXED(fpoint ) value
$UDBL
Unsigned INT value
INT(32) value
Type-conversion routines that convert an argument from a smaller data type to a larger
data type, such as $DFIX, perform a sign extension of the expression to the high bits.
Type-conversion routines whose names end in R, such as $DBLR, round their results.
All other type-transfer routines truncate their results.
Type-conversion routines round values as follows:
(IF value < 0 THEN value
− 5 ELSE value + 5) / 10
That is:
1. If value is negative, 5 is subtracted; if value is positive, 5 is added.
2. Integer division by 10 truncates the result; therefore, if the absolute value of the
least significant digit of the result after initial truncation is 5 or more, one is added
to the absolute value of the final least significant digit.
Rounding has no effect on INT, INT(32), or FIXED expressions.
HP pTAL Reference Manual—523746-006
15 -13
Built-In Routines
Address-Conversion Routines
Address-Conversion Routines
An address-conversion routine converts one address type to another address type.
Table 15-4. Built-In Address-Conversion Routines
Routine
Converts ...
To ...
$BADDR_TO_EXTADDR
BADDR address
EXTADDR address
$BADDR_TO_WADDR
BADDR address
WADDR address
$EXTADDR_TO_BADDR
EXTADDR address
BADDR address
$EXTADDR_TO_WADDR
EXTADDR address
WADDR address
$PROCADDR
INT(32) value
PROCADDR address
$SGBADDR_TO_EXTADDR
SGBADDR or SGXBADDR
address
EXTADDR address
$SGBADDR_TO_SGWADDR
SGBADDR or SGXBADDR
address
SGWADDR address
$SGWADDR_TO_EXTADDR
SGWADDR or SGXWADDR
address
EXTADDR address
$SGWADDR_TO_SGBADDR
SGWADDR or SGXWADDR
address
SGBADDR address
$WADDR_TO_BADDR
WADDR address
BADDR address
$WADDR_TO_EXTADDR
WADDR address
EXTADDR address
$XADR
Standard address
EXTADDR address
The pTAL privileged routine $AXADR on page 15-26, supported only by the pTAL
compiler, is also an address-conversion routine.
Character-Test Routines
A character-test routine tests the right byte of an INT value for an alphabetic, numeric,
or special character, returning a true value if the character is there and a false value
otherwise.
Table 15-5. Built-In Character-Test Routines
Routine
Tests for ...
$ALPHA
Alphabetic character
$NUMERIC
Numeric character
$SPECIAL
Special (ASCII nonalphanumeric) character (see Table 2-1 on page 2-2)
HP pTAL Reference Manual—523746-006
15 -14
Built-In Routines
Minimum and Maximum Routines
Minimum and Maximum Routines
Minimum routines return the minimum of two arguments. Maximum routines return the
maximum of two arguments.
Table 15-6. Built-In Minimum and Maximum Routines
Arguments are of the type ...
Minimum
Maximum
Unsigned INT
$LMIN
$LMAX
Signed INT, INT(32), FIXED(fpoint ), REAL, or
REAL(64)
$MIN
$MAX
Arithmetic Routines
Table 15-7. Built-In Arithmetic Routines
Routine
Description
$ABS
Returns the absolute value of its argument
$COMP
Returns the one’s complement of its argument
$UDIVREM16
Divides an INT(32) dividend by an INT divisor to produce an INT quotient
and an INT remainder
$UDIVREM32
Divides an INT(32) dividend by an INT divisor to produce an INT(32)
quotient and an INT remainder
Carry and Overflow Routines
Table 15-8. Built-In Carry and Overflow Routines
Routine
Indicates whether ...
$CARRY
An arithmetic carry occurred during certain arithmetic operations or during
execution of a SCAN or RSCAN statement
$OVERFLOW
An overflow occurred during certain arithmetic operations
FIXED-Expression Routines
Table 15-9. Built-In FIXED-Expression Routines
Routine
Description
$POINT
Returns the fpoint value of a FIXED expression
$SCALE
Moves the position of the implied decimal point by changing a
FIXED(fpoint ) value
HP pTAL Reference Manual—523746-006
15 -15
Built-In Routines
Variable-Characteristic Routines
Variable-Characteristic Routines
Variable-characteristic routines return INT values that represent various characteristics
of variables.
Table 15-10. Built-In Variable-Characteristic Routines
Routine
Returns an INT value that is the ...
$BITLENGTH
Length, in bits, of a variable
$BITOFFSET
Offset, in bits, of a structure data item from the address of the zeroth
structure occurrence
$LEN
Length, in bytes, of a variable
$OCCURS
Number of elements in an array
$OFFSET
Offset, in bytes, of a structure item from the beginning of the structure
$TYPE
Data type of a variable
Procedure-Parameter Routines
Table 15-11. Built-In Procedure-Parameter Routines
Routine
Description
$OPTIONAL
Controls whether a given parameter or parameter pair is passed to a
VARIABLE procedure or EXTENSIBLE procedure
$PARAM
Checks for the presence or absence of an actual parameter in the call that
called the current procedure or subprocedure
Miscellaneous Routines
Table 15-12. Miscellaneous Built-In Routines (page 1 of 2)
Routine
Description
$CHECKSUM
Returns the checksum of data
$COUNTDUPS
Returns the number of duplicate words in a buffer
$EXCHANGE
Exchanges the values of two variables of the same data
type
$FILL8, $FILL16, and $FILL32
Fill an array or structure with repetitions of an 8-bit, 16-bit,
and 32-bit value, respectively
$INTERROGATEHIO*,**
Stores cause and status information from a high-priority
I/O interrupt
$LOCATESPTHDR *,**
Returns the address of the Segment Page Table (SPT)
* Only procedures executing in privileged mode can call this routine (see Privileged Mode on page 15-1)
** The EpTAL compiler does not support this routine.
HP pTAL Reference Manual—523746-006
15 -16
Built-In Routines
Miscellaneous Routines
Table 15-12. Miscellaneous Built-In Routines (page 2 of 2)
Routine
Description
$MOVEANDCXSUMBYTES
Moves bytes from one memory location to another and
computes a checksum (bytewise exclusive “or”) on them
$MOVENONDUP
Moves words until it encounters two adjacent identical
words
$READCLOCK
$READSPT*,**
Returns the current setting of the system clock
$READTIME
Returns the number of microseconds since the last cold
load
$STACK_ALLOCATE
Allocates a block of memory on the stack and returns the
address of the block
Returns (copies) an entry from the Segment Page Table
(SPT)
* Only procedures executing in privileged mode can call this routine (see Privileged Mode on page 15-1)
** The EpTAL compiler does not support this routine.
Table 15-13. Built-In Routines for Nonatomic Operations (page 1 of 6)
Routine
Description
Can Set ...
$ABS
Returns the absolute value of its
argument
$OVERFLOW
$ALPHA
Tests for an alphabetic character
$ASCIITOFIXED
Converts an ASCII value to a FIXED
value
$AXADR1,2,3
Converts a standard address or a
relative extended address to an
absolute extended address
$BADDR_TO_EXTADDR
Converts a BADDR address to an
EXTADDR address
Condition code
$BADDR_TO_WADDR
Converts a BADDR address to a
WADDR address
Condition code
$BITLENGTH
Returns the length, in bits, of a
variable
$BITOFFSET
Returns the offset, in bits, of a
structure data item from the address
of the zeroth structure occurrence
Condition code
$OVERFLOW
1. pTAL privileged procedure (see Privileged Mode on page 15-1)
2. Only procedures operating in privileged mode can execute this routine (see Privileged Mode on page 15-1).
3. The EpTAL compiler does not support this routine.
4. The pTAL compiler does not support this routine.
HP pTAL Reference Manual—523746-006
15 -17
Built-In Routines
Miscellaneous Routines
Table 15-13. Built-In Routines for Nonatomic Operations (page 2 of 6)
Routine
Description
$CARRY
Indicates whether an arithmetic carry
occurred during certain arithmetic
operations or during execution of a
SCAN or RSCAN statement
$CHECKSUM
Returns the checksum of data
$COMP
Returns the one’s complement of its
argument
$COUNTDUPS
Returns the number of duplicate
words in a buffer
$DBL
Converts its argument to an INT(32)
value
$DBLL
Converts two INT values to an INT(32)
value
$DBLR
Converts its argument to a rounded
INT(32) value
$DFIX
Converts an INT(32) value to a
FIXED(fpoint ) value
$EFLT
Converts its argument to a REAL(64)
value
$EFLTR
Converts its argument to a rounded
REAL(64) value
$EXCHANGE
Exchanges the values of two variables
of the same data type
$EXECUTEIO1,2,3
Executes an I/O operation
$EXTADDR_TO_BADDR
Converts a EXTADDR address to a
BADDR address
$EXTADDR_TO_WADDR
Converts a EXTADDR address to a
WADDR address
$FILL8, $FILL16, and $FILL32
Fill an array or structure with
repetitions of an 8-bit, 16-bit, and 32bit value, respectively
$FIX
Converts its argument to a FIXED
value
$FIXD
Converts a FIXED value to an INT(32)
value
Can Set ...
$OVERFLOW
$OVERFLOW
Condition code
$OVERFLOW
1. pTAL privileged procedure (see Privileged Mode on page 15-1)
2. Only procedures operating in privileged mode can execute this routine (see Privileged Mode on page 15-1).
3. The EpTAL compiler does not support this routine.
4. The pTAL compiler does not support this routine.
HP pTAL Reference Manual—523746-006
15 -18
Built-In Routines
Miscellaneous Routines
Table 15-13. Built-In Routines for Nonatomic Operations (page 3 of 6)
Routine
Description
Can Set ...
$FIXEDTOASCII
Converts the absolute value of a
FIXED value to an ASCII value
$OVERFLOW
$FIXEDTOASCIIRESIDUE
Converts the absolute value of a
FIXED value to an ASCII value and
returns the value of the residue
$OVERFLOW
$FIXI
Converts a FIXED value to a signed
INT value
$OVERFLOW
$FIXL
Converts a FIXED value to an
unsigned INT value
$OVERFLOW
$FIXR
Converts its argument to a rounded
FIXED value
$OVERFLOW
$FLT
Converts its argument to a REAL
value
$FLTR
Converts its argument to a rounded
REAL value
$FREEZE1,2,3
Freezes (halts) the processor in which
its process is running and any other
processes on the same node that
have FREEZE enabled
$HALT1,2,3
Halts the processor in which its
process is running
$HIGH
Converts the high-order (leftmost) 16
bits of an INT(32) or EXTADDR value
to an INT value
$IFIX
Converts a signed INT value to a
FIXED(fpoint ) value
$INT
Converts its argument to an INT value
$INT_OV
Same as $INT, but sets overflow
indicator in some cases
$OVERFLOW
$INTERROGATEHIO2,3
Stores cause and status information
from a high-priority I/O interrupt
Condition code
$INTERROGATEIO1,2,3
Stores cause and status information
from an I/O interrupt
Condition code
$OVERFLOW
1. pTAL privileged procedure (see Privileged Mode on page 15-1)
2. Only procedures operating in privileged mode can execute this routine (see Privileged Mode on page 15-1).
3. The EpTAL compiler does not support this routine.
4. The pTAL compiler does not support this routine.
HP pTAL Reference Manual—523746-006
15 -19
Built-In Routines
Miscellaneous Routines
Table 15-13. Built-In Routines for Nonatomic Operations (page 4 of 6)
Routine
Description
Can Set ...
$INTR
Converts the low-order 16 bits of an
INT, INT(32), or FIXED value to an
INT value
$OVERFLOW
Converts a REAL or REAL(64) value
to a rounded INT value
$LEN
Returns the length, in bytes, of a
variable
$LFIX
Converts an unsigned INT value to a
FIXED(fpoint ) value
$LMAX
Returns the maximum of two unsigned
INT values
$LMIN
Returns the minimum of two unsigned
INT values
$LOCATESPTHDR 2,3
Returns the address of the Segment
Page Table (SPT)
$CARRY
$LOCKPAGE1,2,3
Locks one page of memory
Condition code
$CARRY
$MAX
Returns the maximum of two signed
values
$MIN
Returns the minimum of two signed
values
$MOVEANDCXSUMBYTES
Moves bytes from one memory
location to another and computes a
checksum (bytewise exclusive “or”) on
them
$MOVENONDUP
Moves words until it encounters two
adjacent identical words
$NUMERIC
Tests for a numeric character
$OCCURS
Returns the number of elements in an
array
$OFFSET
Returns the offset, in bytes, of a
structure item from the beginning of
the structure
$OPTIONAL
Controls whether a given parameter or
parameter pair is passed to a
VARIABLE procedure or
EXTENSIBLE procedure
Condition code
1. pTAL privileged procedure (see Privileged Mode on page 15-1)
2. Only procedures operating in privileged mode can execute this routine (see Privileged Mode on page 15-1).
3. The EpTAL compiler does not support this routine.
4. The pTAL compiler does not support this routine.
HP pTAL Reference Manual—523746-006
15 -20
Built-In Routines
Miscellaneous Routines
Table 15-13. Built-In Routines for Nonatomic Operations (page 5 of 6)
Routine
Description
$OVERFLOW
Indicates whether an overflow
occurred during certain arithmetic
operations
$PARAM
Checks for the presence or absence
of an actual parameter in the call that
called the current procedure or
subprocedure
$POINT
Returns the fpoint value of a
FIXED expression
$PROCADDR
Converts an INT(32) value to a
PROCADDR address
$READBASELIMIT1,2
Returns the base and limit of the
current extended segment
$READCLOCK
Returns the current setting of the
system clock
$READSPT2,3
Returns (copies) an entry from the
Segment Page Table (SPT)
$READTIME
Returns the number of microseconds
since the last cold load
$SCALE
Moves the position of the implied
decimal point by changing a
FIXED(fpoint ) value
$SGBADDR_TO_EXTADDR
Converts a SGBADDR or SGXBADDR
address to an EXTADDR address
$SGBADDR_TO_SGWADDR
Converts a SGBADDR or SGXBADDR
address to a SGWADDR address
$SGWADDR_TO_EXTADDR
Converts a SGWADDR or
SGXWADDR address to an
EXTADDR address
$SGWADDR_TO_SGBADDR
Converts a SGWADDR or
SGXWADDR address to a SGBADDR
address
$SPECIAL
Tests for a special (ASCII
nonalphanumeric) character
$STACK_ALLOCATE
Allocates a block of memory on the
stack and returns the address of the
block
Can Set ...
$CARRY
$OVERFLOW
1. pTAL privileged procedure (see Privileged Mode on page 15-1)
2. Only procedures operating in privileged mode can execute this routine (see Privileged Mode on page 15-1).
3. The EpTAL compiler does not support this routine.
4. The pTAL compiler does not support this routine.
HP pTAL Reference Manual—523746-006
15 -21
Built-In Routines
$ABS
Table 15-13. Built-In Routines for Nonatomic Operations (page 6 of 6)
Routine
Description
Can Set ...
$TRIGGER1,2,4
Replaces $FREEZE and $HALT,
which are available only for code
generated for the TNS/R architecture
$TYPE
Returns an INT value that represents
the data type of a variable
$UDBL
Converts an unsigned INT value to an
INT(32) value
$UDIVREM16
Divides an INT(32) dividend by an INT
divisor to produce an INT quotient and
INT remainder
$OVERFLOW
$UDIVREM32
Divides an INT(32) dividend by an INT
divisor to produce an INT(32) quotient
and INT remainder
$OVERFLOW
$UNLOCKPAGE1,2,3
Unlocks one page of memory
Condition code
$WADDR_TO_BADDR
Converts a WADDR address to a
BADDR address
$WADDR_TO_EXTADDR
Converts a WADDR address to an
EXTADDR address
$WRITEPTE1,2,3
Writes a segment-page table entry
$XADR
Converts a standard address to an
EXTADDR address
$CARRY
1. pTAL privileged procedure (see Privileged Mode on page 15-1)
2. Only procedures operating in privileged mode can execute this routine (see Privileged Mode on page 15-1).
3. The EpTAL compiler does not support this routine.
4. The pTAL compiler does not support this routine.
$ABS
$ABS returns the absolute value of its argument. The returned value has the same
data type as the argument.
$ABS
expression
(
)
VST072.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
HP pTAL Reference Manual—523746-006
15 -22
Built-In Routines
$ALPHA
expression
is an expression (as described in Section 5, Expressions).
If the absolute value of a negative INT, INT(32), or FIXED expression cannot be
represented in two’s complement form (for example, if expression has the INT
value -32,768), $ABS traps if overflow traps are enabled (see Section 13, Hardware
Indicators); otherwise, $ABS ignores the problem.
Example 15-9. $ABS Routine
INT int_val := -5;
INT abs_val;
abs_val := $ABS(int_val);
! Return 5, the absolute value of -5
$ALPHA
$ALPHA tests the right byte of an INT value for the presence of an alphabetic
character.
$ALPHA
(
int-expression
)
VST073.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
int-expression
is an INT expression.
$ALPHA inspects bits <8:15> of int-expression and ignores bits <0:7>. It tests for
an alphabetic character according to the following criteria:
int-expression >= "A" AND int-expression <= "Z" OR
int-expression >= "a" AND int-expression <= "z"
If an alphabetic character occurs, $ALPHA sets the condition code indicator to CCE
(condition code equal to). If you plan to check the condition code, do so before an
arithmetic operation or assignment occurs.
If the character passes the test, $ALPHA returns a -1 (true); otherwise, it returns a 0
(false).
int-expression can include STRING and UNSIGNED(1-16) operands, as
described in “Expression Arguments” at the beginning of this section.
HP pTAL Reference Manual—523746-006
15 -23
Built-In Routines
$ASCIITOFIXED
Example 15-10. $ALPHA Routine
STRING some_char;
IF $ALPHA (some_char) THEN ... ;
! Test for alphabetic character
$ASCIITOFIXED
$ASCIITOFIXED converts an ASCII value to a FIXED value.
$ASCIITOFIXED
remainingdigits
(
qvaluein
,
bufferaddr
qvalueout
,
,
maxdigits
)
;
VST606.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
Yes
bufferaddr
input,output
BADDR:variable
is the byte address from which $ASCIITOFIXED reads ASCII digits. When
$ASCIITOFIXED completes, bufferaddr contains the address following the
last byte read.
maxdigits
input
uINT:value
is the maximum number of ASCII digits to read from bufferaddr.
remainingdigits
output
uINT:variable
is the number of bytes that $ASCIITOFIXED did not convert because it
encountered a nonnumeric ASCII byte. remainingdigits must be an INT
variable; it cannot be a STRING, UNSIGNED, or USE variable or a bit field.
HP pTAL Reference Manual—523746-006
15 -24
Built-In Routines
$ASCIITOFIXED
qvaluein
input
FIXED(*):value
is a value that $ASCIITOFIXED adds to the result of converting the bytes at
bufferaddr. $ASCIITOFIXED multiplies qvaluein by 10 for each digit it
converts from ASCII to FIXED. After it converts the last digit at bufferaddr,
$ASCIITOFIXED adds qvaluein to the result of the conversion to establish the
value that it returns qvalueout.
qvalueout
output
FIXED(*):variable
is a quadrupleword integer value that holds the final result of the conversion.
$ASCIITOFIXED converts a string of ASCII-coded digits at bufferaddr to a binarycoded FIXED value, adds qvaluein times 10n, where n is the number of digits
converted, and stores the result in qvalueout.
If a nondigit ASCII code is encountered, $ASCIITOFIXED ends the conversion.
$ASCIITOFIXED converts only the digits before the nondigit ASCII code. CCG
indicates that $ASCIITOFIXED converted only part of the ASCII number. CCE
indicates $ASCIITOFIXED converted the entire string. If overflow traps are enabled
and the result is greater than 263-1 or less than 263, $ASCIITOFIXED sets
$OVERFLOW and qvalueout is undefined.
Example 15-11. $ASCIITOFIXED Routine
LITERAL
STRING
STRING
INT
INT
FIXED
FIXED
buffer_len = 100;
.buffer[ 0:buffer_len - 1 ];
.ptr := @buffer;
maxdigits;
remainingdigits;
qvaluein;
qvalueout;
! Buffer to convert
! pointer to buffer
$ASCIITOFIXED (@ptr, maxdigits, remainingdigits, qvaluein,
qvalueout);
HP pTAL Reference Manual—523746-006
15 -25
Built-In Routines
$AXADR
$AXADR
Note. The EpTAL compiler does not support this routine. (The EpTAL compiler does allow
$AXADR as a DEFINE name.)
$AXADR converts a standard address or a relative extended address to an absolute
extended address.
$AXADR
(
variable
)
VST116.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
variable
is the identifier of a simple variable, pointer, array element, structure, or structure
data item.
If variable is a pointer, $AXADR returns the absolute extended address of the item
to which the pointer points, not the address of the pointer itself.
Example 15-12. $AXADR Routine
PROC myproc PRIV;
BEGIN
STRING .EXT str;
INT intr;
! Lots of code
@str := $AXADR (intr);
! Convert standard address of intr
! to an absolute extended address
!More code
END;
$BADDR_TO_EXTADDR
$BADDR_TO_EXTADDR converts a BADDR address to an EXTADDR address.
$BADDR_TO_EXTADDR
(
expression
)
VST683.vsd
HP pTAL Reference Manual—523746-006
15 -26
Built-In Routines
$BADDR_TO_WADDR
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is a BADDR address.
Example 15-13. $BADDR_TO_EXTADDR Routine
STRING .EXT s;
STRING
t;
@s := $BADDR_TO_EXTADDR(@t);
! @t is a BADDR address
$BADDR_TO_WADDR
$BADDR_TO_WADDR converts a BADDR address to a WADDR address.
$BADDR_TO_WADDR
(
expression
)
VST684.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is a BADDR address.
The result of $BADDR_TO_WADDR is undefined if the least significant bit of
expression is 1. The least significant bit of an address is not truncated when a byte
address is converted to a word address—the address is not rounded down to the
preceding even-byte address.
Example 15-14. $BADDR_TO_WADDR Routine
INT
.i;
STRING s;
@i := $BADDR_TO_WADDR(@s);
! @s is a BADDR address
HP pTAL Reference Manual—523746-006
15 -27
Built-In Routines
$BITLENGTH
$BITLENGTH
$BITLENGTH returns an INT value that is the length, in bits, of a variable.
$BITLENGTH
(
variable
)
VST074.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
variable
is the identifier of a simple variable, array element, pointer, structure, or structure
data item.
$BITLENGTH returns the length, in bits, of a single occurrence of a simple variable,
array element, structure, structure item, or item to which a pointer points.
The length of a structure or substructure occurrence is the sum of the lengths of all
items contained in the structure or substructure. Complete the structure before you use
$BITLENGTH to obtain the length of any of the items in the structure.
To compute the total number of bits in an entire array or substructure, multiply the
value returned by $BITLENGTH by the value returned by $OCCURS. To compute the
total number of bits in a structure, first round up the value returned by $BITLENGTH to
the word boundary and then multiply the rounded value by the value returned by
$OCCURS.
You can use $BITLENGTH in LITERAL expressions and global initializations, because
it always returns a constant value.
Example 15-15. $BITLENGTH Routine
INT s_len;
STRUCT .s[0:3];
BEGIN
UNSIGNED(1) flags[0:15];
UNSIGNED(2) status;
BIT_FILLER 14;
END;
! Declare four occurrences of a
! structure
s_len := $BITLENGTH (s);
! Return 32, the number of bits
! in one structure occurrence
HP pTAL Reference Manual—523746-006
15 -28
Built-In Routines
$BITOFFSET
$BITOFFSET
$BITOFFSET returns an INT value that is the offset, in bits, of a structure data item
from the address of the zeroth structure occurrence.
$BITOFFSET
(
variable
)
VST075.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
variable
is the fully qualified identifier of a structure item.
The zeroth structure occurrence has an offset of 0. For items other than substructure,
simple variable, array, or pointer declared within a structure, $BITOFFSET returns a 0.
When you qualify the identifier of variable, you can use constant indexes but not
variable indexes; for example:
$BITOFFSET (struct1.subst[1].item)
!1 is a constant index
To find the offset of an item in a structure, complete the structure before you use
$BITOFFSET.
You can use $BITOFFSET in LITERAL expressions and global initializations, because
it always returns a constant value.
Example 15-16. $BITOFFSET Routine
STRUCT a;
BEGIN
INT array[0:40];
STRUCT ab[0:9];
BEGIN
UNSIGNED(1) flag;
UNSIGNED(15) offset;
END;
END;
INT c;
c := $BITOFFSET (a.ab[2]);
! Return offset of 3rd occurrence
! of ab
HP pTAL Reference Manual—523746-006
15 -29
Built-In Routines
$CARRY
$CARRY
$CARRY returns a value that indicates whether an arithmetic carry occurred during
certain arithmetic operations or during execution of a SCAN or RSCAN statement.
$CARRY
VST076.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
The value returned by $CARRY is based on instructions emitted by the compiler that
determine whether a carry occurred. $CARRY returns -1 if a carry occurred, 0
otherwise.
Procedures cannot return $CARRY.
You can test $CARRY only after one of the following statements:
•
•
An assignment statement in which the final operator executed in the expression on
the right side of the assignment is one of the following:
°
°
Signed integer add, subtract, or negate
Unsigned integer add, subtract, or negate
A SCAN or RSCAN statement.
$CARRY cannot be an actual parameter. If it is important to pass the value of $CARRY
to a procedure, use code similar to that in Example 15-17 on page 15-30.
Example 15-17. $CARRY Routine
INT a, carry_flag;
carry_flag := 0;
a := a + 1;
IF $CARRY THEN carry_flag := 1;
CALL p1(carry_flag, .... );
HP pTAL Reference Manual—523746-006
15 -30
Built-In Routines
$CHECKSUM
$CHECKSUM
$CHECKSUM returns the checksum of data.
$CHECKSUM
wordcount
checksum
(
)
,
bufferaddr
,
;
VST613.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
checksum
input,output
uINT:variable
the initial value (“seed” value) of the checksum. When $CHECKSUM
completes, checksum holds the final checksum. checksum must be an INT
variable. It cannot be a STRING, UNSIGNED, or USE variable or a bit field.
bufferaddr
input
EXTADDR:value
the address of the first 16-bit word to include in the checksum.
wordcount
input
uINT:value
the number of 16-bit words to include in the checksum.
$CHECKSUM accumulates the checksum by performing an exclusive-or operation on
the accumulated checksum and wordcount successive 16-bit words, starting at
bufferaddr. When $CHECKSUM completes, checksum holds the accumulated
checksum and bufferaddr is unchanged.
HP pTAL Reference Manual—523746-006
15 -31
Built-In Routines
$COMP
Example 15-18. $CHECKSUM Routine
LITERAL buffer_len = 100;
INT
c_sum_val;
INT .EXT buffer1 [ 0:buffer_len - 1 ];
INT .EXT buffer2 [ 0:buffer_len - 1 ];
buffer1 ':=' [%H0123, %H4567, %H89AB];
c_sum_val:= 3;
$CHECKSUM(c_sum_val, @buffer1, buffer_len);
! Value of c_sum_val is now %HCDEF
! Checksum buffer2 in same checksum word as buffer1
$CHECKSUM(c_sum_val, @buffer2, buffer_len);
! c_sum_val now has the combined checksum of buffer1 & buffer2
$COMP
$COMP returns the one’s complement of its argument.
$COMP
(
int-expression
)
VST077.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
int-expression
is an expression whose value is an INT or INT(32) value.
The data type of the expression returned by $COMP is the same as the data type of its
argument.
Example 15-19. $COMP Routine
INT
i;
INT(32) j;
i := $COMP(i);
j := $COMP(j);
HP pTAL Reference Manual—523746-006
15 -32
Built-In Routines
$COUNTDUPS
$COUNTDUPS
$COUNTDUPS returns the number of consecutive words, starting at the beginning of a
buffer, that are equal to the first word in the buffer.
$COUNTDUPS
scraddr
(
)
duplicationcount
,
maxwords
,
;
VST614.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
srcaddr
input,output
EXTADDR:variable
an address. Starting at srcaddr, $COUNTDUPS scans 16-bit words until it
encounters two adjacent words that are not equal. At the end of the operation,
srcaddr points to the word that differs from the first word and which,
therefore, terminated the scan. If there are no duplicates in the buffer,
srcaddr points immediately after the last two words it compared—that is, at
the first word $COUNTDUPS did not examine.
maxwords
input,output
uINT:variable
the maximum number of 16-bit words to scan at srcaddr. At the end of the
operation, maxwords contains:
•
•
0 if $COUNTDUPS scanned the entire buffer.
The number of words $COUNTDUPS did not scan because it found a
nonduplicate pair.
maxwords must be an INT variable; it cannot be a STRING, UNSIGNED, or
USE variable or a bit field.
HP pTAL Reference Manual—523746-006
15 -33
Built-In Routines
$DBL
duplicationcount
input,output
uINT:variable
holds an initial value. At the end of the operation, duplicationcount
contains its original value plus the number of duplicate words found by
$COUNTDUPS.
duplicationcount must be an INT variable; it cannot be a STRING,
UNSIGNED, or USE variable or a bit field.
$COUNTDUPS scans a buffer from left to right until it encounters two adjacent unequal
words or until it reads maxwords words.
Example 15-20. $COUNTDUPS Routine
LITERAL
INT .EXT
INT
INT
buffersize = 100;
buffer[ 0:buffersize-1 ];
maxwords;
duplication_count;
maxwords := maxbuff;
$COUNTDUPS(@buffer, maxwords, duplication_count);
$DBL
$DBL converts its argument to an INT(32) value.
$DBL
expression
(
)
VST078.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes, if expression is a fixed
value
expression
is an expression whose value is an INT, INT(32), FIXED, REAL, REAL(64),
UNSIGNED(1-16), UNSIGNED(17-31), EXTADDR, or PROCADDR value.
HP pTAL Reference Manual—523746-006
15 -34
Built-In Routines
$DBLL
Example 15-21. $DBL Routine
INT .EXT i;
EXTADDR e;
INT(32) j;
j
j
j
j
j
:=
:=
:=
:=
:=
$DBL(e);
$DBL(@i);
$DBL(i);
$DBL(@j);
$DBL(@e);
!
!
!
!
!
OK: e is type EXTADDR
OK: @i is type EXTADDR
OK: i is type INT
ERROR: @j is type WADDR
ERROR: @e is type WADDR
$DBLL
$DBLL converts to INT values an INT(32) value.
DBLL
int-expression
(
,
int-expression
)
VST079.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
int-expression
is an INT expression.
To form the INT(32) value, $DBLL places the first int-expression in the high-order
16 bits and the second int-expression in the low-order 16 bits.
Example 15-22. $DBLL Routine
INT first_int, second_int;
INT(32) some_double;
INT .EXT p;
! 32-bit simple pointer
some_double := $DBLL (first_int, second_int);
! Return INT(32) value
@p := ($DBLL (2, 7)) '<<' 1;
! Return 32-bit address in
! user code segment
HP pTAL Reference Manual—523746-006
15 -35
Built-In Routines
$DBLR
$DBLR
$DBLR converts its argument to an INT(32) value and rounds the result.
$DBLR
expression
(
)
VST080.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an INT, INT(32), FIXED, REAL, or REAL(64) expression.
If expression is too large to be represented by a 32-bit two’s complement integer,
$DBLR traps if overflow traps are enabled (see Section 13, Hardware Indicators);
otherwise, $DBLR ignores the problem.
Example 15-23. $DBLR Routine
REAL r2 := 1.5e0;
INT(32) b32;
REAL realnum := 123.456E0;
INT(32) dblnum;
b32 := $DBLR (r2);
dblnum := $DBLR (realnum);
! Return 2d
! Return 123D
$DFIX
$DFIX converts an INT(32) value to a FIXED(fpoint ) value.
$DFIX
(
dbl-expression
fpoint
,
)
VST081.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
HP pTAL Reference Manual—523746-006
15 -36
Built-In Routines
$EFLT
dbl-expression
is an INT(32) expression.
fpoint
is a value in the range -19 through +19 that specifies the position of the implied
decimal point in the result. A positive fpoint specifies the number of decimal
places to the right of the decimal. A negative fpoint specifies the number of
integer places to the left of the decimal point.
$DFIX converts an INT(32) expression to a FIXED(fpoint ) expression by performing
the equivalent of a signed right shift of 32 positions from the left 32 bits into the right 32
bits of a quadrupleword unit.
Example 15-24. $DFIX Routine
FIXED(2) fixnum;
INT(32) dblnum := -125D;
fixnum := $DFIX (dblnum, 2);
! Return -1.25
$EFLT
$EFLT converts its argument to a REAL(64) value.
$EFLT
expression
(
)
VST082.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an INT, INT(32), FIXED(fpoint ), REAL, or REAL(64) expression.
If a FIXED expression has a nonzero fpoint, the compiler multiplies or divides the
result by the appropriate power of ten.
Example 15-25. $EFLT Routine
REAL(64) dbrlnum;
FIXED(3) fixnum := 12345.678F;
dbrlnum := $EFLT (fixnum);
! Return 12345678L-3
HP pTAL Reference Manual—523746-006
15 -37
Built-In Routines
$EFLTR
$EFLTR
$EFLTR converts its argument to a REAL(64) value and rounds the result.
$EFLTR
(
expression
)
VST083.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an INT, INT(32), FIXED(fpoint ), REAL, or REAL(64) expression.
If a FIXED expression has a nonzero fpoint, the compiler multiplies or divides the
result by the appropriate power of ten.
Example 15-26. $EFLTR Routine
REAL(64) rndnum;
FIXED(3) fixnum := 12345.678F;
rndnum := $EFLTR (fixnum);
! Return rounded REAL(64) value
$EFLTR
$EFLTR converts an expression to a REAL(64) value and rounds the result.
$EFLTR
(
expression
)
VST083.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an INT, INT(32), FIXED(fpoint ), REAL, or REAL(64) expression.
HP pTAL Reference Manual—523746-006
15 -38
Built-In Routines
$EXCHANGE
If a FIXED expression has a nonzero fpoint, the compiler multiplies or divides the
result by the appropriate power of ten.
Example 15-27. $EFLTR Routine
REAL(64) rndnum;
FIXED(3) fixnum := 12345.678F;
rndnum := $EFLTR (fixnum);
! Return rounded REAL(64) value
$EXCHANGE
$EXCHANGE exchanges the values of two variables of the same data type.
$EXCHANGE
(
var1
,
var2
)
;
VST615.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
var1
input,output
anytype: var
a variable whose contents are exchanged with var2.
var2
input,output
anytype: var
a variable whose contents are exchanged with var1.
var1 and var2 must meet the following requirements:
•
•
•
•
•
var1 and var2 must both be INT variables or both be INT(32) variables.
Neither var1 nor var2 can be a structure, but they can be fields of structures.
Neither var1 nor var2 can be STRING, UNSIGNED, or USE variables, nor can
they be bit strings.
var1, var2, or both can be array elements.
If var1 or var2 names an entire array, $EXCHANGE exchanges element 0 of
the array.
HP pTAL Reference Manual—523746-006
15 -39
Built-In Routines
$EXECUTEIO
$EXECUTEIO
Note. The EpTAL compiler does not support this procedure.
$EXECUTEIO executes an I/O operation.
$EXECUTEIO
lacsubcommand
channel-status
channel
(
rdstdevstatus
,
)
lprmcommand
,
,
,
;
VST616.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
channel
input
uINT:value
is the channel number to which the I/O is initialized.lprmcommand
input
uINT:value
is the load parameter.
lacsubcommand
input
sINT:value
is the load address and the command word.
rdstdevstatus
output
uINT:variable
is the controller and device status.
HP pTAL Reference Manual—523746-006
15 -40
Built-In Routines
$EXTADDR_TO_BADDR
channel-status
output
sINT:variable
See the system description manual for your system for details.
Example 15-28. $EXECUTEIO Routine
INT
INT
INT
INT
INT
channel;
lprm_command;
lac_subcommand;
rdst_dev_status;
channel_status;
$EXECUTEIO (channel, lprm_command, lac_subcommand,
rdst_dev_status, channel_status);
$EXTADDR_TO_BADDR
$EXTADDR_TO_BADDR converts an EXTADDR address to a BADDR address.
$EXTADDR_TO_BADDR
(
expression
)
VST686.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is an EXTADDR address.
Example 15-29. $EXTADDR_TO_BADDR Routine
PROC p(x);
STRING .EXT x;
BEGIN
STRING .j;
@j := $EXTADDR_TO_BADDR(@x);
@j := $EXTADDR_TO_BADDR(x);
END;
! ERROR: x is STRING,
! not EXTADDR
HP pTAL Reference Manual—523746-006
15 -41
Built-In Routines
$EXTADDR_TO_WADDR
$EXTADDR_TO_WADDR
$EXTADDR_TO_WADDR converts an EXTADDR address to an WADDR address.
$EXTADDR_TO_WADDR
expression
(
)
VST687.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is an EXTADDR address.
Example 15-30. $EXTADDR_TO_WADDR Routine
PROC p(x);
INT .EXT x;
BEGIN
INT .j;
@j := $EXTADDR_TO_WADDR(@x);
@j := $EXTADDR_TO_WADDR(x);
END;
! ERROR: x is INT, not EXTADDR
$FILL8, $FILL16, and $FILL32
$FILL8, $FILL16, and $FILL32 fill an array or structure with repetitions of an 8-bit,
16-bit, or 32-bit value, respectively (sometimes called a “smear” operation).
$FILL8
CALL
$FILL16
$FILL32
(
area-to-fill
,
repetitions
,
value
)
VST688.vsd
HP pTAL Reference Manual—523746-006
15 -42
Built-In Routines
$FILL8, $FILL16, and $FILL32
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
area-to-fill
is a variable of any data type. The address of area-to-fill specifies the
beginning of the area to fill.
repetitions
is an INT expression whose value specifies the number of times to write.
value
is an expression whose value is a STRING value for $FILL8, to an INT value for
$FILL16, and to an INT(32) value for $FILL32.
$FILL16 and $FILL32 cause an alignment trap if area-to-fill is not aligned to at
least a 2-byte boundary.
$FILL32 performance is significantly degraded if area-to-fill is not aligned to at
least a 4-byte boundary.
None of the fill procedures ($FILL8, $FILL16, $FILL32) perform bounds-checking on
their parameters. If you write more bytes than the size of area-to-fill, the results
are undefined. You might overwrite other data in your program with no immediate error,
or you might cause any of several addressing errors, such as attempting to write in an
area for which you do not have write permission, attempting to write in an unmapped
page, and so forth.
Example 15-31. $FILL8 Procedure
PROC a MAIN;
BEGIN
STRUCT s(s_t);
...
CALL $FILL8(s, $LEN(s), 0);
END;
HP pTAL Reference Manual—523746-006
15 -43
Built-In Routines
$FIX
$FIX
$FIX converts its argument to a FIXED value.
$FIX
expression
(
)
VST084.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an INT, INT(32), FIXED, REAL, or REAL(64) expression.
If expression is too large in magnitude to be represented by a 64-bit two’s
complement integer, $FIX traps if overflow traps are enabled (see Section 13,
Hardware Indicators); otherwise, $FIX ignores the problem.
Example 15-32. $FIX Routine
FIXED fixnum;
INT intnum := 5;
fixnum := $FIX (intnum);
! Return 5F
$FIXD
$FIXD converts a FIXED value to an INT(32) value.
$FIXD
fixed-expression
(
)
VST085.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
HP pTAL Reference Manual—523746-006
15 -44
Built-In Routines
$FIXEDTOASCII
fixed-expression
is a FIXED expression, which $FIXD treats as a FIXED expression, ignoring any
implied decimal point.
If the result cannot be represented in a signed doubleword, $FIXD traps if overflow
traps are enabled (see Section 13, Hardware Indicators); otherwise, $FIXD ignores the
problem.
Example 15-33. $FIXD Routine
INT(32) dblnum;
FIXED fixnum := 1234F;
dblnum := $FIXD (fixnum);
! Return 1234D
$FIXEDTOASCII
$FIXEDTOASCII converts the absolute value of a FIXED value to an ASCII value.
$FIXEDTOASCII
maxdigits
(
)
,
qvalue
bufferaddr
,
;
VST617.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
qvalue
input
FIXED(*):value
is a quadrupleword integer value to convert to ASCII digits.
bufferaddr
input
BADDR:value
is the byte address at which to write the ASCII digits.
maxdigits
input
uINT:value
is the maximum number of ASCII digits to write at bufferaddr.
HP pTAL Reference Manual—523746-006
15 -45
Built-In Routines
$FIXEDTOASCIIRESIDUE
If $FIXEDTOASCII converts maxdigits bytes but leading digits in qvalue are not
converted, and $OVERFLOW can be checked, $FIXEDTOASCII sets $OVERFLOW;
otherwise, it resets $OVERFLOW.
Example 15-34. $FIXEDTOASCII Routine
LITERAL
FIXED
STRING
buffer_len = 100;
val;
.buffer[ 0:buffer_len - 1 ];
$FIXEDTOASCII(val, @buffer, buffer_len);
$FIXEDTOASCIIRESIDUE
$FIXEDTOASCIIRESIDUE converts the absolute value of a FIXED value to an ASCII
value and returns the value of the residue.
$FIXEDTOASCIIRESIDUE
,
maxdigits
,
(
,
qvalue
qresidue
)
bufferaddr
;
VST618.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
qvalue
input
FIXED(*):value
is a quadrupleword integer value to convert to ASCII digits.
bufferaddr
input
BADDR:value
is the byte address at which to write the ASCII digits.
maxdigits
input
uINT:value
is the maximum number of ASCII digits to write at bufferaddr.
HP pTAL Reference Manual—523746-006
15 -46
Built-In Routines
$FIXI
qresidue
output
FIXED(*):variable
holds any of the original value that was not converted because maxdigits
bytes were converted without converting all of qvalue.
$FIXEDTOASCIIRESIDUE returns in qresidue any portion of qvalue that it does
not convert because maxdigits digits were written but qvalue was not fully
converted.
If $FIXEDTOASCIIRESIDUE converts maxdigits bytes but leading digits in qvalue
are not converted, and $OVERFLOW can be checked, $FIXEDTOASCIIRESIDUEI
sets $OVERFLOW; otherwise, it resets $OVERFLOW.
Example 15-35. $FIXEDTOASCIIRESIDUE Routine
LITERAL
FIXED
STRING
FIXED
buffer_len = 100;
val;
.buffer[ 0:buffer_len - 1 ];
residue;
$FIXEDTOASCIIRESIDUE(val, @buffer, buffer_len, residue);
$FIXI
$FIXI converts a FIXED value to a signed INT value.
$FIXI
fixed-expression
(
)
VST086.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
fixed-expression
is a FIXED expression, which $FIXI treats as a FIXED expression, ignoring any
implied decimal point.
If the result cannot be represented in a signed 16-bit integer, $FIXI traps if overflow
traps are enabled (see Section 13, Hardware Indicators); otherwise, $FIXI ignores the
problem.
HP pTAL Reference Manual—523746-006
15 -47
Built-In Routines
$FIXL
Example 15-36. $FIXI Routine
INT intnum;
FIXED fixnum := %177777F;
intnum := $FIXI (fixnum);
! Return -1
$FIXL
$FIXL converts a FIXED value to an unsigned INT value.
$FIXL
fixed-expression
(
)
VST087.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
fixed-expression
is a FIXED expression, which $FIXL treats as a FIXED expression, ignoring any
implied decimal point.
If the result cannot be represented in an unsigned 16-bit integer, $FIXL traps if
overflow traps are enabled (see Section 13, Hardware Indicators); otherwise, $FIXL
ignores the problem.
Example 15-37. $FIXL Routine
INT intnum;
FIXED fixnum := 32767F;
intnum := $FIXL (fixnum);
! Return 32,767
$FIXR
$FIXR converts its argument to a FIXED value and rounds the result.
$FIXR
(
expression
)
VST088.vsd
HP pTAL Reference Manual—523746-006
15 -48
Built-In Routines
$FLT
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
expression
is an INT, INT(32), FIXED, REAL, or REAL(64) expression.
If expression is too large in magnitude to be represented by a 64-bit two’s
complement integer, $FIXR traps if overflow traps are enabled (see Section 13,
Hardware Indicators); otherwise, $FIXR ignores the problem.
Example 15-38. $FIXR Routine
FIXED rfixnum;
REAL(64) bigrealnum := -1.5L0;
FIXED rndfnum;
REAL realnum := 123.456E0;
rfixnum := $FIXR (bigrealnum);
rndfnum := $FIXR (realnum);
! Return -1F
! Return 123F
$FLT
$FLT converts its argument to a REAL value.
$FLT
expression
(
)
VST089.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an INT, INT(32), FIXED(fpoint ), REAL, or REAL(64) expression
If a FIXED expression has a nonzero fpoint, the compiler multiplies or divides the
result by the appropriate power of ten.
HP pTAL Reference Manual—523746-006
15 -49
Built-In Routines
$FLTR
Example 15-39. $FLT Routine
REAL realnum;
INT(32) dblnum := 147D;
realnum := $FLT (dblnum);
! Return 147E0
$FLTR
$FLTR converts its argument to a REAL value and rounds the result.
$FLTR
expression
(
)
VST090.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
expression
is an INT, INT(32), FIXED(fpoint ), REAL, or REAL(64) expression
If a FIXED expression has a nonzero fpoint, the compiler multiplies or divides the
result by the appropriate power of ten.
Example 15-40. $FLTR Routine
REAL rrlnum;
INT(32) dblnum := 147D;
rrlnum := $FLTR (dblnum);
! Return rounded REAL value
HP pTAL Reference Manual—523746-006
15 -50
Built-In Routines
$FREEZE
$FREEZE
Note.
•
•
The EpTAL compiler does not support this procedure. Use $TRIGGER on page 15-88
instead. (The EpTAL compiler does allow $FREEZE as a DEFINE name.)
Execution does not return from this call.
$FREEZE halts the processor in which its process is running and any other processors
on the same node that have FREEZE enabled.
$FREEZE
VST619.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
$HALT
Note.
•
•
The EpTAL compiler does not support this procedure. Use $TRIGGER on page 15-88
instead. (The EpTAL compiler does allow $HALT as a DEFINE name.)
Execution does not return from this call.
$HALT halts the processor in which its process is running.
$HALT
VST620.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
HP pTAL Reference Manual—523746-006
15 -51
Built-In Routines
$HIGH
$HIGH
$HIGH converts the high-order (leftmost) 16 bits of an INT(32) or EXTADDR value to
an INT value.
dbl-expression
(
$HIGH
)
VST091.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
dbl-expression
is an expression whose value is INT(32) or EXTADDR.
$HIGH returns the high-order 16 bits of dbl-expression and preserves the sign bit.
$HIGH does not cause overflow.
Example 15-41. $HIGH Routine
INT
a;INT(32)
INT .EXT c;
EXTADDR d;
a
a
a
a
a
:=
:=
:=
:=
:=
$HIGH(b);
$HIGH(@c);
$HIGH(@b);
$HIGH(c);
$HIGH(d);
!
!
!
!
!
b;
OK: b is INT(32)
OK: @c is EXTADDR
ERROR: @b is WADDR
ERROR: c is INT
OK: d is EXTADDR
$IFIX
$IFIX converts a signed INT value to a FIXED(fpoint ) value.
$IFIX
(
int-expression
,
fpoint
)
VST092.vsd
HP pTAL Reference Manual—523746-006
15 -52
Built-In Routines
$INT
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
int-expression
is a signed INT expression.
fpoint
is a value in the range -19 through +19 that specifies the position of the implied
decimal point in the result. A positive fpoint specifies the number of decimal
places to the right of the decimal. A negative fpoint specifies the number of
integer places to the left of the decimal point.
When $IFIX converts the signed INT expression to a FIXED value, it performs the
equivalent of a signed right shift of 48 positions in a quadrupleword unit.
In Example 15-42 on page 15-53, $IFIX returns a FIXED(2) value from a signed INT
expression and an fpoint of 2.
Example 15-42. $IFIX Routine
FIXED(2) fixnum;
INT intnum := 12345;
fixnum := $IFIX (intnum, 2);
! Return 123.45
$INT
$INT converts its argument to an INT value.
$INT
expression
(
)
VST093.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
HP pTAL Reference Manual—523746-006
15 -53
Built-In Routines
$INT_OV
expression
is an expression whose value is an INT, INT(32), UNSIGNED(1-16),
UNSIGNED(17-31), FIXED, REAL, REAL(64), SGBADDR, SGWADDR,
SGXBADDR, SGXWADDR, or EXTADDR value.
If expression is not a FIXED, REAL, or REAL(64) value, $INT returns the low-order
(rightmost) 16 bits of expression. $INT never causes overflow. $INT does not
explicitly maintain the sign of expression. In Example 15-43 on page 15-54, $INT
returns -1 although the argument to $INT is a positive number.
Example 15-43. $INT Routine
INT i;
i := $INT(%HFFFFFF%D);
If the value of the expression in Example 15-43 on page 15-54 is a FIXED, REAL, or
REAL(64) value, $INT returns the result of converting expression arithmetically to an
INT value—$INT does not just truncate an expression. If the converted value of
expression is too large to fit in 16 bits, an exception trap occurs.
For details on SG and SGX variables, see Section 3, Data Representation.
Example 15-44. $INT Routine
PROC p;
BEGIN
INT .SG a;
SGXBADDR b;
INT i;
INT .EXT e;
i :=
i :=
i :=
i :=
i :=
i :=
i :=
END;
$INT(a);
$INT(@a);
$INT(b);
$INT(i);
$INT(@b);
$INT(@i);
$INT(@e);
!
!
!
!
!
!
!
OK: a is INT
OK: @a is SGWADDR
OK: b is SGXBADDR
OK: i is INT
ERROR: @b is WADDR
ERROR: @i is WADDR
OK: @e is EXTADDR
$INT_OV
Note. $INT_OV is supported in the D40 and later product versions.
$INT_OV converts its argument to an INT value and sets $OVERFLOW in some
cases.
$INT_OV
(
expression
)
VST689.vsd
HP pTAL Reference Manual—523746-006
15 -54
Built-In Routines
$INTERROGATEHIO
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
expression
is an expression whose value is an INT, INT(32), UNSIGNED(1-31), FIXED, REAL,
REAL(64), SGBADDR, SGWADDR, SGXBADDR, SGXWADDR, or EXTADDR
value.
If the data type of its argument is an INT(32) value greater than 32767 or less than
-32768, $INT_OV traps if overflow traps are enabled (see Section 13, Hardware
Indicators); otherwise, $INT_OV ignores the problem.
Example 15-45. Difference Between $INT and $INT_OV
INT i;
INT(32) j
INT(32) k
:= 32767;
:= 32768;
i := $INT(j);
IF $OVERFLOW THEN
i := $INT(k);
IF $OVERFLOW THEN
i := $INT_OV(j);
IF $OVERFLOW THEN
i := $INT_OV(k);
IF $OVERFLOW THEN
...
!
!
!
!
...
! $OVERFLOW is false
...
! $OVERFLOW is true
...
INT never
$OVERFLOW
INT never
$OVERFLOW
sets overflow
is false
sets overflow
is false
$INTERROGATEHIO
Note. The EpTAL compiler does not support this procedure.
$INTERROGATEHIO stores cause and status information from a high-priority I/O
interrupt, which the operating system uses to reset the interrupt.
$INTERROGATEHIO
,
)
ric-int-cause
(
,
select
rist-int-cause
rank-channel
,
,
channel-status
;
VST643.vsd
HP pTAL Reference Manual—523746-006
15 -55
Built-In Routines
$INTERROGATEHIO
pTAL privileged procedure
No
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
select
output
uINT:variable
is an integer variable that is always set to 0.
rank-channel
output
uINT:variable
is an integer variable that is always set to 0.
ric-int-cause
output
uINT:variable
is the read interrupt cause received from the controller holding the completed
I/O.
rist-int-cause
output
uINT:variable
is the read interrupt status received from the controller holding the completed
I/O.
channel-status
output
uINT:variable
is an integer variable that holds the status returned by the controller.
Example 15-46. $INTERROGATEHIO Routine
INT
INT
INT
INT
INT
select;
rank_channel;
ric_interrupt_status;
rist_interrupt_cause;
channel_status;
$INTERROGATEHIO(select, rank_channel, ric_interrupt_status,
rist_interrupt_status, channel_status);
HP pTAL Reference Manual—523746-006
15 -56
Built-In Routines
$INTERROGATEIO
$INTERROGATEIO
Note. The EpTAL compiler does not support this procedure.
$INTERROGATEIO stores cause and status information from an I/O interrupt, which
the operating system uses to reset the interrupt.
$INTERROGATEIO
,
ric-int-cause
)
(
,
select
rank-channel
,
rist-int-cause
,
channel-status
;
VST644.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
select
output
sINT:variable
is an integer variable that is always set to 0.
rank-channel
output
sINT:variable
is an integer variable that is always set to 0.
ric-int-cause
output
sINT:variable
is the read interrupt cause received from the controller holding the completed
I/O.
rist-int-cause
output
sINT:variable
is the read interrupt status received from the controller holding the completed
I/O.
HP pTAL Reference Manual—523746-006
15 -57
Built-In Routines
$INTR
channel-status
output
sINT:variable
is an integer variable that holds the status returned by the controller.
Example 15-47. $INTERROGATEIO Routine
INT
INT
INT
INT
INT
select;
rank_channel;
ric_interrupt_status;
rist_interrupt_cause;
channel_status;
$INTERROGATEIO(select, rank_channel, ric_interrupt_status,
rist_interrupt_status, channel_status);
$INTR
$INTR converts:
•
•
The low-order 16 bits of an INT, INT(32), or FIXED value to an INT value
A REAL or REAL(64) value to a rounded INT value
$INTR
expression
(
)
VST094.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
expression
is an INT, INT(32), FIXED, REAL, or REAL(64) expression.
If expression is type INT, INT(32) or FIXED, $INTR returns the low-order (least
significant) 16 bits and does not explicitly maintain the sign. No overflow occurs.
If expression is type REAL or REAL(64), $INTR returns a fully converted and
rounded INT value, not a truncation. If the converted value of expression is too
large to be represented by a 16-bit two’s complement integer, an overflow trap occurs.
HP pTAL Reference Manual—523746-006
15 -58
Built-In Routines
$LEN
Example 15-48. $INTR Routine
INT rndnum;
REAL realnum := 12345E-2;
rndnum := $INTR (realnum);
! Return 123
$LEN
$LEN returns an INT value that is the length, in bytes, of a variable.
$LEN
variable
(
)
VST096.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
variable
is the identifier of a simple variable, array element, pointer, structure, or structure
data item.
The compiler reports an error if you apply the $LEN routine to a structure that consists
of an odd number of bytes, exclusive of a pad byte.
You can avoid this error by using one of the following solutions:
•
•
Declare explicitly a 1-byte filler item at the end of structures that consist of an odd
number of bytes.
Use $BITLENGTH on page 15-28 instead of $LEN.
The compiler reports an error if you apply $LEN to an UNSIGNED variable or structure
field. Use $BITLENGTH to obtain the length of an UNSIGNED variable or structure.
Example 15-49. $LEN Routine
INT b;
INT a [0:11];
b := $LEN (a);
! Return 2
HP pTAL Reference Manual—523746-006
15 -59
Built-In Routines
$LFIX
Example 15-50. $LEN Routine
INT s_len;
STRUCT .s[0:99];
BEGIN
INT(32) array[0:2];
END;
s_len := $LEN (s);
! Return 12
Example 15-51. $LEN Routine
INT array_length;
INT(32) array[0:2];
array_length := $LEN (array) * $OCCURS (array);
! Return 12, the length of the entire array in bytes
$LFIX
$LFIX converts an unsigned INT value to a FIXED(fpoint ) value.
$LFIX
(
int-expression
fpoint
,
)
VST097.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
int-expression
is an unsigned INT expression.
fpoint
is a value in the range -19 through +19 that specifies the position of the implied
decimal point in the result. A positive fpoint specifies the number of decimal
places to the right of the decimal. A negative fpoint specifies the number of
integer places to the left of the decimal point.
$LFIX places the INT value in the low-order (least significant) word of the
quadrupleword and sets the three high-order (most significant) words to 0.
HP pTAL Reference Manual—523746-006
15 -60
Built-In Routines
$LMAX
Example 15-52. $LFIX Routine
FIXED(2) fixnum;
INT intnum := 125;
fixnum := $LFIX (intnum, 2);
! Return 1.25
$LMAX
$LMAX returns the maximum of two unsigned INT values.
(
$LMAX
int-expression
int-expression
,
)
VST098.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
int-expression
is an unsigned INT expression.
Example 15-53. $LMAX Routine
INT intval := 3;
max := $LMAX (intval, 5);
! Return 5
$LMIN
$LMIN returns the minimum of two unsigned INT values.
$LMIN
(
int-expression
int-expression
,
)
VST099.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
HP pTAL Reference Manual—523746-006
15 -61
Built-In Routines
$LOCATESPTHDR
int-expression
is an unsigned INT expression.
Example 15-54. $LMIN Routine
INT intval := 3;
min := $LMIN (intval, 5);
! Return 3
$LOCATESPTHDR
Note. The EpTAL compiler does not support this procedure.
$LOCATESPTHDR returns the address of the Segment Page Table (SPT).
$LOCATESPTHDR
sptbase
)
(
headersize
,
virtaddr
,
;
VST645.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
Yes
Sets $OVERFLOW
No
headersize
input
uINT:value
is the unsigned byte offset from the beginning of the SPT to the beginning of
the header. Because the SPT header always precedes the SPT, headersize
is subtracted from the address of the SPT to obtain the address of the start of
the header.
virtaddr
input
EXTADDR:value
is the address of the SPT.
sptbase
output
EXTADDR:variable
is the address of the segment-page-table header associated with virtaddr.
HP pTAL Reference Manual—523746-006
15 -62
Built-In Routines
$LOCKPAGE
$LOCATESPTHDR returns in sptbase the address of the segment-page table for the
address in virtaddr.
Example 15-55. $LOCATESPTHDR Routine
INT
headersize;
EXTADDR addr;
EXTADDR seg_page_table_base;
$LOCATESPTHDR(headersize, addr, seg_page_table_base);
$LOCKPAGE
Note. The EpTAL compiler does not support this procedure.
$LOCKPAGE locks one page of memory.
(
$LOCKPAGE
virtaddr
)
,
only-if-locked
lock-count
,
;
VST646.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
Yes
Sets $OVERFLOW
No
only-if-locked
input
sINT:value
is an INT value. If only-if-locked is greater than or equal to zero, the
page will always be locked. If only-if-locked is less than zero, the page
will be locked (that is, lock count will be incremented) only if it is already
locked.
lock-count
input
sINT:value
is the total number of bytes to lock in the page.
HP pTAL Reference Manual—523746-006
15 -63
Built-In Routines
$MAX
virtaddr
input
EXTADDR:value
is the beginning virtual address to lock. $LOCKPAGE calculates the page
associated with virtaddr.
Example 15-56. $LOCKPAGE Routine
INT
only_if_locked;
INT
lock_count;
EXTADDR virtaddr;
$LOCKPAGE(only_if_locked, lock_count, virtaddr);
$MAX
$MAX returns the maximum of two signed values.
$MAX
expression
(
,
expression
)
VST100.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is a signed INT, INT(32), FIXED(fpoint ), REAL, or REAL(64) expression. Both
expressions must be of the same data type.
Example 15-57. $MAX Routine
REAL realval := -3E0;
max := $MAX (realval, 5E0);
! Return 5E0
$MIN
$MIN returns the minimum of two signed values.
$MIN
(
expression
,
expression
)
VST101.vsd
HP pTAL Reference Manual—523746-006
15 -64
Built-In Routines
$MOVEANDCXSUMBYTES
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an INT, INT(32), FIXED(fpoint ), REAL, or REAL(64) expression. Both
expressions must be of the same data type.
Example 15-58. $MIN Routine
FIXED fixval := -3F;
min := $MIN (fixval, 5F);
! Return -3F
$MOVEANDCXSUMBYTES
$MOVEANDCXSUMBYTES moves a specified number of bytes from one memory
location to another and computes a checksum (bytewise exclusive “or”) on the bytes
moved.
$MOVEANDCXSUMBYTES
destaddr
srcaddr
,
(
,
checksum
,
count
)
;
VST647.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
checksum
input,output
uINT:variable
contains an initial value for the checksum. When $MOVEANDCXSUMBYTES
completes, checksum contains the newly computed value.
HP pTAL Reference Manual—523746-006
15 -65
Built-In Routines
$MOVEANDCXSUMBYTES
destaddr
input,output
EXTADDR:variable
is the address to which $MOVEANDCXSUMBYTES moves data. When
$MOVEANDCXSUMBYTES completes, destaddr points to the memory
location following the last byte written.
srcaddr
input,output
EXTADDR:variable
is the address from which bytes are read. When $MOVEANDCXSUMBYTES
completes, srcaddr points to the memory location following the last byte
read.
count
input
uINT:value
is the number of bytes to move.
$MOVEANDCXSUMBYTES transfers count bytes from srcaddr to destaddr and
computes a checksum (bytewise exclusive “or”) on the data moved. When
$MOVEANDCXSUMBYTES completes, srcaddr points to the immediate right of the
last byte read, destaddr points to the immediate right of the last byte written, and
checksum holds the newly computed checksum.
$MOVEANDCXSUMBYTES does not ensure that the source and destination buffers
do not overlap.
Example 15-59. $MOVEANDCXSUMBYTES Routine
INT
INT
.EXT
INT
.EXT
INT(32)
checksum;
source;
dest;
count;
checksum := 0;
$MOVEANDCXSUMBYTES(checksum, @dest, @source, count);
HP pTAL Reference Manual—523746-006
15 -66
Built-In Routines
$MOVENONDUP
$MOVENONDUP
$MOVENONDUP moves words from one location to another until it encounters two
adjacent identical words.
$MOVENONDUP
maxwords
,
(
lastword
destaddr
,
)
;
srcaddr
,
VST648.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
destaddr
input,output
EXTADDR:variable
is the address to which words are moved. When $MOVENONDUP completes,
destaddr is the address after which $MOVENONDUP stored the last byte.
srcaddr
input,output
EXTADDR:variable
is the address from which 16-bit words are moved. When $MOVENONDUP
completes, srcaddr is the address after which $MOVENONDUP read the
last byte it moved.
maxwords
input,output
sINT:variable
is the maximum number of 16-bit words to move. When $MOVENONDUP
completes, maxwords is the number of words not moved because
$MOVENONDUP found a duplicate, or, if a duplicate was not found,
maxwords is zero.
lastword
input,output
uINT:variable
holds the 16-bit word against which the first word at srcaddr is compared.
When $MOVENONDUP completes, lastword contains the last word moved.
HP pTAL Reference Manual—523746-006
15 -67
Built-In Routines
$NUMERIC
Example 15-60. $MOVENONDUP Routine
INT .EXT source;
INT .EXT destination;
INT
maxword;
INT
latestword;
$MOVENONDUP(@destination, @source, maxword, latestword);
$NUMERIC
$NUMERIC tests the right byte of an INT value for the presence of a numeric
character.
$NUMERIC
(
int-expression
)
;
VST102.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
int-expression
is an INT expression.
$NUMERIC inspects bits <8:15> of int-expression and ignores bits <0:7>. It tests
for a numeric character according to the criterion:
int-expression >= "0" AND int-expression <= "9"
If a numeric character occurs, $NUMERIC sets the condition code to CCL (condition
code less than). If you plan to test the condition code, do so before an arithmetic
operation or assignment occurs.
If the character passes the test, $NUMERIC returns a -1 (true); otherwise, it returns a 0
(false).
int-expression can include STRING and UNSIGNED(1-16) operands, as
described in “Expression Arguments” at the beginning of this section.
Example 15-61. $NUMERIC Routine
STRING char;
IF $NUMERIC (char) THEN ... ;
! Test for numeric character
HP pTAL Reference Manual—523746-006
15 -68
Built-In Routines
$OCCURS
$OCCURS
$OCCURS returns an INT value that is the number of elements in an array.
$OCCURS
(
variable
)
VST103.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
variable
is the name of a variable, array, structure, or structure field. variable cannot be
the name of a structure template.
If identifier is the identifier of an explicitly declared array—that is, it is not a
reference parameter—and identifier is the unindexed name of the array, $OCCURS
returns the number of array elements specified in the array’s declaration; otherwise,
$OCCURS returns 1.
Table 15-14. $OCCURS for Nonstructure Arrays
$OCCURS Argument
Example
$OCCURS Returns
Entire array
INT a[0:9];
$OCCURS (a);
10
Value parameter or simple variable
INT a;
$OCCURS (a);
1
Reference parameter or pointer
INT .a;
$OCCURS (a);
1
Array element using constant index
INT a[0:9];
$OCCURS (a[3]);
1
Array element using expression in index
INT a[0:9];
$OCCURS (a[j]);
1
HP pTAL Reference Manual—523746-006
15 -69
Built-In Routines
$OCCURS
Table 15-15. $OCCURS for Structure Arrays and Arrays Within Structures
$OCCURS
Returns
$OCCURS Argument
Example
Unindexed structure array or
substructure array
STRUCT s [0:9];
BEGIN
STRUCT
BEGIN
INT
END;
END;
or
an element of a structure array or
substructure array,
or
an array that is a field within a
structure or substructure
$OCCURS
$OCCURS
$OCCURS
$OCCURS
$OCCURS
$OCCURS
Entire structure
STRUCT s;
BEGIN
INT f;
END;
or
nonarray field of a structure or
substructure
10
1
8
1
5
1
(s);
(a[7]);
(a[7].t);
(a[7].t[3]);
(a[7].t[3].i);
(a[7].t[3].i[v]);
1
1
$OCCURS (s);
$OCCURS (s.f);
Structure template
STRUCT s;
BEGIN
INT f[0:9];
END;
Compile-time err
10
1
$OCCURS (s);
$OCCURS (s.f);
$OCCURS (s.f[5]);
Example 15-62. $OCCURS Routine With Nonstructure Arrays
PROC p(x, y);
INT x,
.y;
BEGIN
INT a[0:9];
INT i;
INT .r;
i :=
i :=
i :=
i :=
i :=
i :=
i :=
END;
$OCCURS(a);
$OCCURS(i);
$OCCURS(x);
$OCCURS(a[3]);
$OCCURS(a[i]);
$OCCURS(r);
$OCCURS(y);
!
!
!
!
!
!
!
OK: a is an entire array
OK: $OCCURS returns 1
OK: $OCCURS returns 1
WARNING: $OCCURS returns
WARNING: $OCCURS returns
WARNING: $OCCURS returns
WARNING: $OCCURS returns
HP pTAL Reference Manual—523746-006
15 -70
1
1
1
1
Built-In Routines
$OFFSET
Example 15-63. $OCCURS Routine With Structure Arrays
INT i;
STRUCT s[0:9];
BEGINSTRUCT t[0:7];
BEGIN
INT i[0:4];
INT f;
END;
END;
i
i
i
i
i
i
i
:=
:=
:=
:=
:=
:=
:=
$OCCURS(s);
$OCCURS(s[7].t);
$OCCURS(s[7].t[3].i);
$OCCURS(s[7].t[3].f);
$OCCURS(s[7]);
$OCCURS(s[7].t[3]);
$OCCURS(s[7].t[3].i[v]);
!
!
!
!
!
!
!
OK: s is an entire array
OK: t is an entire array
OK: i is an entire array
OK: $OCCURS returns 1
WARNING: $OCCURS returns 1
WARNING: $OCCURS returns 1
WARNING: $OCCURS returns 1
Example 15-64. $OCCURS Routine With Template Structure Arrays
INT i;
STRUCT s(*);
BEGIN
INT f[0:9];
END;
i := $OCCURS(s);
i := $OCCURS(s.f);
i := $OCCURS(s.f[5]);
! ERROR: Template structure not OK
! OK: f is an array
! WARNING: $OCCURS returns 1
$OFFSET
$OFFSET returns an INT value that is the offset, in bytes, of a structure item from the
beginning of the structure.
$OFFSET
(
variable
)
VST104.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
HP pTAL Reference Manual—523746-006
15 -71
Built-In Routines
$OFFSET
variable
is the fully qualified identifier of a structure field.
The compiler reports an error for the following uses of $OFFSET:
•
•
•
•
$OFFSET applied to an UNSIGNED field. Use $BITOFFSET instead of $OFFSET.
$OFFSET applied to an item that is not a field in a structure.
$OFFSET applied to a structure array whose lower bound is nonzero; however,
$OFFSET applied to a substructure array whose lower bound is nonzero returns
the appropriate offset.
$OFFSET for which the result would be greater than 216-1.
Example 15-65. $OFFSET Routine
STRUCT a;
BEGIN
INT array[0:40];
STRUCT ab[0:9];
BEGIN
! Lots of declarations
END;
END;
INT c;
! Some code
c := $OFFSET (a.ab[2]);
! Return offset of third
! occurrence of substructure
Example 15-66. $OFFSET Routine
STRUCT .tt;
BEGIN
INT
i;
INT(32) d;
STRING s;
END;
STRUCT .st;
BEGIN
INT i;
INT j;
INT .st_ptr(tt);
END;
! Declare structure pointer
! that points to structure tt
INT x;
x := $OFFSET (st.j);
x := $OFFSET (tt.s);
x := $OFFSET (st.st_ptr.s);
! x gets 2
! x gets 6
! x gets 6
HP pTAL Reference Manual—523746-006
15 -72
Built-In Routines
$OPTIONAL
Example 15-67. $OFFSET Routine Applied to a Template Structure
INT x;
STRUCT st[-1:1];
BEGIN
INT item;
FIXED(2) price;
END;
x := $OFFSET (st[-1].item);
!x gets -10
$OPTIONAL
$OPTIONAL controls whether a given parameter or parameter pair is passed to a
VARIABLE procedure or EXTENSIBLE procedure.
$OPTIONAL
(
cond-expression
,
param
)
param-pair
VST213.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
cond-expression
is a conditional expression. If cond-expression is true, param or param-pair
is passed. If cond-expression is false, param (or param-pair ) is not
passed.
param
is an a variable identifier or an expression that defines an actual parameter to pass
to a formal parameter declared in the called procedure if cond-expression is
true.
HP pTAL Reference Manual—523746-006
15 -73
Built-In Routines
$OPTIONAL
param-pair
is an actual parameter pair to pass to a formal parameter pair declared in the
called procedure if cond-expression is true. param-pair has the form:
string
:
length
VST039.vsd
string
is the identifier of a STRING array or simple pointer declared inside or outside
a structure.
length
is an INT expression that specifies the length, in bytes, of string.
A call to a VARIABLE or EXTENSIBLE procedure can omit some or all parameters.
$OPTIONAL lets your program pass a parameter (or parameter-pair) based on a
condition at execution time. $OPTIONAL is evaluated as follows each time the
encompassing CALL statement is executed:
•
•
If cond-expression is true, the parameter is passed; $PARAM, if present, is set
to true for the corresponding formal parameter.
If cond-expression is false, the parameter is not passed; $PARAM, if present,
is set to false for the corresponding formal parameter.
A called procedure cannot distinguish between a parameter that is passed
conditionally and one that is passed unconditionally. Passing parameters conditionally,
however, is slower than passing them unconditionally. In the first case, the
EXTENSIBLE mask is computed at execution time; in the second case, the mask is
computed at compilation time.
Example 15-68. Parameters Passed Conditionally and Unconditionally
PROC p1 (i) EXTENSIBLE;
INT i;
BEGIN
! Lots of code
END;
PROC p2;
BEGIN
INT n := 1;
CALL p1 ($OPTIONAL (n > 0, n) );
CALL p1 (n);
END;
! These two calls are
! indistinguishable
HP pTAL Reference Manual—523746-006
15 -74
Built-In Routines
$OPTIONAL
Example 15-69. Parameters Omitted Conditionally and Unconditionally
PROC p1 (i) EXTENSIBLE;
INT i;
BEGIN
! Lots of code
END;
PROC p2;
BEGIN
INT n := 1;
CALL p1 ($OPTIONAL (n < 0, n) );
CALL p1 ( );
END;
! These two calls are
! indistinguishable
Example 15-70. Parameters Passed Conditionally
PROC p1 (str:len, b) EXTENSIBLE;
STRING .str;
INT len;
INT b;
BEGIN
! Lots of code
END;
PROC p2;
BEGIN
STRING .s[0:79];
INT i:= 1;
INT j:= 1;
CALL p1 ($OPTIONAL (i < 9, s:i),
$OPTIONAL (j > 2, j) );
END;
! Pass s:i if i < 9
! Pass j if j > 2
You can use $OPTIONAL when one procedure provides a front-end interface for
another procedure that does the actual work, as Example 15-71 on page 15-75 shows.
Example 15-71. $OPTIONAL Routine for a Front-End Interface (page 1 of 2)
PROC p1 (i, j) EXTENSIBLE;
INT .i;
INT .j;
BEGIN
! Lots of code
END;
HP pTAL Reference Manual—523746-006
15 -75
Built-In Routines
$OVERFLOW
Example 15-71. $OPTIONAL Routine for a Front-End Interface (page 2 of 2)
PROC p2 (p, q) EXTENSIBLE;
INT .p;
INT .q;
BEGIN
! Lots of code
CALL p1 ($OPTIONAL ($PARAM (p), p ),
$OPTIONAL ($PARAM (q), q ));
! Lots of code
END;
$OVERFLOW
$OVERFLOW returns a value indicating whether an overflow occurred during certain
arithmetic operations.
$OVERFLOW
VST105.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
$OVERFLOW indicates whether an overflow occurred. You can test $OVERFLOW
only if overflow traps are disabled and only following an assignment statement in which
the final operator executed on the right side of the assignment is one $FIX of a REAL
or REAL(64) value of the following operators or built-in routines:
•
•
•
•
•
•
•
•
•
•
•
•
Negate (unary -), +, -, *, /,’/’
$DBL of an INT, FIXED, REAL, or REAL(64) value
$FLTR of a REAL(64) value
$FIX of a REAL or REAL(64) value
$FIXD
$FIXI
$FIXL
$FIXR of a REAL or REAL(64) value
$INT of a FIXED, REAL, or REAL(64) value
$INT of a FIXED, REAL, or REAL(64) value
$INTR of a FIXED, REAL, or REAL(64) value
$SCALE, for which: 1 <= exponent <= 4
HP pTAL Reference Manual—523746-006
15 -76
Built-In Routines
$PARAM
Example 15-72. $OVERFLOW Routine
i := i + 1;
IF $OVERFLOW THEN ...
For more information about overflow, see Section 13, Hardware Indicators.
$PARAM
$PARAM checks for the presence or absence of an actual parameter in the call that
called the current procedure or subprocedure.
$PARAM
(
formal-param
)
VST106.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
formal-param
is the identifier of a formal parameter as specified in the procedure or
subprocedure declaration.
If the actual parameter corresponding to formal-param is present in the CALL
statement, $PARAM returns 1 (not -1 as other Boolean operations do). If the actual
parameter is absent from the CALL statement, $PARAM returns 0.
Only a VARIABLE procedure or subprocedure or an EXTENSIBLE procedure can use
$PARAM. If such a procedure or subprocedure has required parameters, it must check
for the presence or absence of each required parameter in CALL statements. The
procedure or subprocedure can also use $PARAM to check for optional parameters.
Example 15-73. $PARAM Routine
PROC var_proc (buffer,length,key) VARIABLE;
INT .buffer, length, ! Required parameters
key;
! Optional parameter
BEGIN
...
IF NOT $PARAM (buffer) OR NOT $PARAM (length) THEN RETURN;
! Return 1 or 0 for each required parameter
IF $PARAM (key) THEN ... ;
! Return 1 if optional parameter is present
END;
HP pTAL Reference Manual—523746-006
15 -77
Built-In Routines
$POINT
$POINT
$POINT returns the fpoint value (as an integer) of a FIXED expression.
$POINT
fixed-expression
(
)
VST107.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
fixed-expression
is a FIXED expression.
The compiler emits no instructions when evaluating fixed-expression ; therefore,
fixed-expression cannot call a routine and cannot be an assignment expression.
Example 15-74. $POINT Routine
FIXED(3) result;
FIXED(3) a;
FIXED(3) b;
result := $SCALE (a, $POINT (b)) / b;
! Return fpoint of FIXED expression & scale value by that factor
$PROCADDR
$PROCADDR converts an INT(32) value to a PROCADDR address.
(
$PROCADDR
identifier
)
VST031.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
HP pTAL Reference Manual—523746-006
15 -78
Built-In Routines
$READBASELIMIT
identifier
is either a procedure address (that is, @procedure-name ) or an INT(32)
expression.
$READBASELIMIT
Note. The EpTAL compiler does not support this procedure.
$READBASELIMIT returns the base and limit of the current extended segment.
$READBASELIMIT
(
xbase
,
xlimit
)
VST649.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
xbase
INT(32):variable
is the base address of the current extended segment.
xlimit
output
INT(32):variable
is the limit of the current extended segment.
Consult the system description manual for your system for the format in which the base
and limit values are returned.
Example 15-75. $READBASELIMIT Routine
INT(32) xbase;
INT(32) xlimit;
$READBASELIMIT(xbase, xlimit);
HP pTAL Reference Manual—523746-006
15 -79
Built-In Routines
$READCLOCK
$READCLOCK
$READCLOCK returns the current setting of the system clock as a FIXED value.
$READCLOCK
VST108.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
Example 15-76. $READCLOCK Routine
FIXED the_time;
the_time := $READCLOCK;
! Return current clock time
$READSPT
Note. The EpTAL compiler does not support this procedure.
$READSPT returns (copies) an entry from the Segment Page Table (SPT).
$READSPT
(
virtaddr
sptentryaddr
,
)
VST650.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
Yes
Sets $OVERFLOW
No
virtaddr
input
EXTADDR:value
is the virtual address of the SPT entry to copy.
HP pTAL Reference Manual—523746-006
15 -80
Built-In Routines
$READTIME
sptentryaddr
output
EXTADDR:variable
is the address at which $READSPT stores the SPT entry.
Example 15-77. $READSPT Routine
EXTADDR virtual_addr;
INT .EXT spt_entry(spt_template) := spt_entry_addr;
$READSPT(virtual_addr, @spt_entry);
$READTIME
$READTIME returns the number of microseconds since the last cold load.
Note. $READTIME is not affected by the TACL command SETTIME; therefore, $READTIME
does not always return the value [JULIANTIMESTAMP(0) - JULIANTIMESTAMP(1)].
For a description of the SETTIME command, see the TACL Reference Manual. For a
description of the JULIANTIMESTAMP function, see the Guardian Procedure Calls Reference
Manual.
$READTIME
VST651.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
Example 15-78. $READTIME Routine
FIXED time_now;
time_now := $READTIME;
HP pTAL Reference Manual—523746-006
15 -81
Built-In Routines
$SCALE
$SCALE
$SCALE moves the position of the implied fixed-point (decimal point) by changing a
FIXED(fpoint ) value.
$SCALE
(
fixed-expression
,
scale
)
VST110.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
fixed-expression
is the FIXED expression whose implied decimal point is to be changed.
scale
is an INT constant in the range -19 to +19 that specifies the number of positions to
move the implied decimal point with respect to the least significant digit. If scale
is negative, the implied decimal point moves to the left; if scale is positive, the
implied decimal point moves to the right.
$SCALE adjusts the implied decimal point of the stored FIXED value by multiplying or
dividing the value by 10 to the scale power. Some precision might be lost with
negative scale values.
If the result of the scale operation exceeds the range of a FIXED expression, $SCALE
traps if overflow traps are enabled (see Section 13, Hardware Indicators); otherwise,
$SCALE ignores the problem.
Example 15-79. $SCALE Routine
FIXED(3) a := 9.123F;
FIXED(7) result;
result := $SCALE (a, 4);
! Return FIXED(7) value from
! FIXED(3) value
To retain precision when you divide operands that have nonzero fpoint settings, use
the $SCALE built-in routine to scale up the fpoint of the dividend by a factor equal
to the fpoint of the divisor, as in Example 15-80 on page 15-83.
HP pTAL Reference Manual—523746-006
15 -82
Built-In Routines
$SGBADDR_TO_EXTADDR
Example 15-80. Using the $SCALE Routine to Maintain Precision
FIXED(3) num, a, b;
! fpoint of 3
num := $SCALE (a,3) / b;
! Scale a to FIXED(6); result is a
! FIXED(3) value
$SGBADDR_TO_EXTADDR
$SGBADDR_TO_EXTADDR converts an SGBADDR or SGXBADDR address to an
EXTADDR address.
$SGBADDR_TO_EXTADDR
(
expression
)
VST603.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is an SGBADDR or SGXBADDR address.
$SGBADDR_TO_EXTADDR returns expression converted to an EXTADDR
address.
Example 15-81. $SGBADDR_TO_EXTADDR Routine
STRING .SG s;
INT
.EXT i;
INT
j;
@i := $SGBADDR_TO_EXTADDR(@s[j]);
!??: OK if @s[j] is at an
! even-byte offset;
! otherwise, @i is undefined.
$SGBADDR_TO_SGWADDR
$SGBADDR_TO_SGWADDR converts an SGBADDR or SGXBADDR address to an
SGWADDR address.
$SGBADDR_TO_SGWADDR
(
expression
)
VST604.vsd
HP pTAL Reference Manual—523746-006
15 -83
Built-In Routines
$SGWADDR_TO_EXTADDR
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is an SGBADDR or SGXBADDR address.
$SGBADDR_TO_SGWADDR returns expression converted to an SGWADDR address.
The result is undefined if the least significant bit of expression is 1.
Example 15-82. $SGBADDR_TO_SGWADDR Routine
STRING .SG s;
INT
.SG i;
INT
j;
@i := $SGBADDR_TO_SGWADDR(@s[j]);
!??: OK if @s[j] is at an
! even-byte offset;
! otherwise, @i is undefined.
$SGWADDR_TO_EXTADDR
$SGWADDR_TO_EXTADDR converts an SGWADDR or SGXWADDR address to an
EXTADDR address.
$SGWADDR_TO_EXTADDR
(
expression
)
VST605.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is n SGWADDR or SGXWADDR address.
$SGWADDR_TO_EXTADDR returns expression converted to an EXTADDR
address.
HP pTAL Reference Manual—523746-006
15 -84
Built-In Routines
$SGWADDR_TO_SGBADDR
Example 15-83. $SGWADDR_TO_EXTADDR Routine
STRING .EXT s;
INT
.SG i;
@s := $SGWADDR_TO_EXTADDR(@i);
$SGWADDR_TO_SGBADDR
$SGWADDR_TO_SGBADDR converts an SGWADDR or SGXWADDR address to an
SGBADDR address.
$SGWADDR_TO_SGBADDR
(
expression
)
VST690.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is an SGWADDR or SGXWADDR address.
If expression is not an address in the lower half of the 64K word segment, the
address returned by $SGWADDR_TO_SGBADDR is undefined.
Example 15-84. $SGWADDR_TO_SGBADDR Routine
STRING .SG s;
INT
.SG i;
@s := $SGWADDR_TO_SGBADDR(@i); !OK: OK if i is in the
! lower half of system globals
$SPECIAL
$SPECIAL tests the right byte of an INT value for the presence of an ASCII special
(nonalphanumeric) character (see Table 2-1 on page 2-2).
$SPECIAL
(
int-expression
)
VST111.vsd
HP pTAL Reference Manual—523746-006
15 -85
Built-In Routines
$STACK_ALLOCATE
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
int-expression
is an INT expression.
$SPECIAL inspects bits <8:15> of the int-expression and ignores bits <0:7>.
$SPECIAL (int-expression ) has the same value as:
NOT $NUMERIC(int-expression ) AND NOT $ALPHABETIC(int-expression )
If the character passes the test, $SPECIAL returns a -1 (true); otherwise, $SPECIAL
returns a 0 (false).
int-expression can include STRING and UNSIGNED(1-16) operands (see
Expressions as Parameters on page 15-3).
In Example 15-85 on page 15-86, $SPECIAL tests for the presence of a special
character in a STRING argument, which the system places in the right byte of a word
and treats as an INT value.
Example 15-85. $SPECIAL Routine
STRING char;
IF $SPECIAL (char) THEN ... ;
! Test for special character
$STACK_ALLOCATE
Note. The pTAL and EpTAL compilers behave differently.
$STACK_ALLOCATE allocates a block of memory on the stack and returns the
address of the block.
$STACK_ALLOCATE
(
size
)
VST032.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
HP pTAL Reference Manual—523746-006
15 -86
Built-In Routines
$STACK_ALLOCATE
size
is an INT expression that specifies the number of bytes to allocate. size is an
unsigned value from 0 through 65534.
Difference between pTAL and EpTAL compilers:
pTAL Compiler
EpTAL Compiler
If size is not an integral multiple of 8,
$STACK_ALLOCATE rounds size up to
the next integral multiple of 8.
If size is not an integral multiple of 32,
$STACK_ALLOCATE rounds size up to
the next integral multiple of 32.
The returned value is aligned to an 8-byte
boundary.
The returned value is aligned to a 32-byte
boundary.
Blocks returned by multiple calls to $STACK_ALLOCATE are not necessarily
contiguous.
$STACK_ALLOCATE returns a WADDR address, which is the lowest address in the
allocated memory.
$STACK_ALLOCATE does not clear the allocated data area.
$STACK_ALLOCATE does not return error conditions, but stack overflow can occur
within $STACK_ALLOCATE or on a subsequent procedure call from within the
procedure that calls $STACK_ALLOCATE.
When a procedure or routine returns to its caller, the system deallocates all memory
allocated by $STACK_ALLOCATE within that procedure.
pTAL does not support calls to $STACK_ALLOCATE from subprocedures and reports
a syntax error if it encounters one. From within a subprocedure, however, you can
reference data in a block allocated in the encompassing procedure.
Example 15-86. $STACK_ALLOCATE Routine
INT .p(template);
INT(32) .a;
INT(32) i32;
...
@p := $STACK_ALLOCATE($LEN(template));
@a := $STACK_ALLOCATE($LEN(i32)* 10);
For more information about $STACK_ALLOCATE, see the pTAL Conversion Guide.
HP pTAL Reference Manual—523746-006
15 -87
Built-In Routines
$TRIGGER
$TRIGGER
Note.
•
•
The pTAL compiler does not support this routine.
Execution does not return from this call.
$TRIGGER replaces $FREEZE on page 15-51 and $HALT on page 15-51, which are
available only for code generated for the TNS/R architecture.
$TRIGGER
(
op
)
VST060.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
op
is an INT(32) value.
Example 15-87. $TRIGGER Routine
INT(32) op;
$TRIGGER (op); ! or
call $TRIGGER (op);
$TYPE
$TYPE returns an INT value that represents the data type of a variable.
$TYPE
(
variable
)
VST112.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
HP pTAL Reference Manual—523746-006
15 -88
Built-In Routines
$UDBL
variable
is the identifier of a simple variable, array, simple pointer, structure, structure data
item, or structure pointer.
$TYPE returns an INT value that has a meaning as follows:
Value
Meaning
Value
Meaning
0
Undefined
5
REAL
1
STRING
6
REAL(64)
2
INT
7
Substructure
3
INT(32)
8
Structure
4
FIXED
9
UNSIGNED
For a structure pointer, $TYPE returns the value 8, regardless of whether the structure
pointer points to a structure or to a substructure.
You can use $TYPE in LITERAL expressions and global initializations, because
$TYPE always returns a constant value.
Example 15-88. $TYPE Routine
REAL(64) var1;
INT type1;
type1 := $TYPE (var1);
! Return 6 for REAL(64)
$UDBL
$UDBL converts an unsigned INT value to an INT(32) value.
$UDBL
int-expression
(
)
VST113.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
int-expression
is an unsigned INT expression.
$UDBL places the INT value in the low-order 16 bits of an INT(32) variable and sets
the high-order 16 bits to 0.
HP pTAL Reference Manual—523746-006
15 -89
Built-In Routines
$UDIVREM16
Example 15-89. $UDBL Routine
INT a16 := -1;s
INT(32) a32;
a32 := $UDBL (a16);
! Return 65535D
$UDIVREM16
$UDIVREM16 divides an INT(32) dividend by an INT divisor to produce an INT
quotient and INT remainder.
$UDIVREM16
quotient
(
dividend
remainder
,
divisor
,
)
,
;
VST653.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes, if the divisor is 0 or the
quotient is too large
dividend
input
INT(32):value
divisor
input
sINT:value
quotient
output
sINT:variable
remainder
output
sINT:variable
The compiler checks the following conditions during compilation:
•
If the value of divisor is a constant value of zero, the compiler reports an error
that division by zero is not valid:
$UDIVREM16(dividend, 2 / 2 - 1, quot, rem);
HP pTAL Reference Manual—523746-006
15 -90
! Report error
Built-In Routines
•
$UDIVREM32
If both dividend and divisor have constant values whose unsigned quotient is
greater than 16 bits, the compiler reports overflow:
INT quot, rem;
$UDIVREM16(65536 * 1024, 256, quot, rem);
•
! Report error
If both dividend and divisor are constants, and you test $OVERFLOW
following the call to $UDIVREM16, the compiler reports a warning that overflow
cannot occur:
$UDIVREM16(32767, 256, quot, rem);
IF $OVERFLOW THEN ...
! Report warning
If the compiler reports an error because overflow occurs for constant dividend and
constant divisor, it does not report a warning if you test $OVERFLOW in the following
IF statement:
$UDIVREM16(65536 * 1024, 256, quot, rem);
IF $OVERFLOW THEN....
! Report error
! No warning or error
Example 15-90. $UDIVREM16 Routine
INT(32)
INT
INT
INT
dividend;
divisor;
quotient;
remainder;
$UDIVREM16(dividend, divisor, quotient, remainder);
$UDIVREM32
$UDIVREM32 divides an INT(32) dividend by an INT divisor to produce an INT(32)
quotient and INT remainder.
$UDIVREM32
quotient
(
dividend
remainder
,
,
)
divisor
,
;
VST654.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes, if and only if the divisor is 0
dividend
input
INT(32):value
HP pTAL Reference Manual—523746-006
15 -91
Built-In Routines
$UDIVREM32
divisor
input
sINT:value
quotient
output
INT(32):variable
remainder
output
sINT:variable
The compiler checks the following conditions during compilation:
•
If the value of divisor is a constant value of zero, the compiler reports an error
that division by zero is not valid:
$UDIVREM32(dividend, 2 / 2 - 1, quot, rem);
•
! Report error
If both dividend and divisor are constants, and you test $OVERFLOW
following the call to $UDIVREM32, the compiler reports a warning that overflow
cannot occur:
$UDIVREM32(32767, 256, quot, rem);
IF $OVERFLOW THEN ...
! Report warning
If the compiler reports an error because overflow occurs for constant dividend and
constant divisor, it does not report a warning if you test $OVERFLOW in the following
IF statement:
$UDIVREM32(65536 * 1024, 256, quot, rem);
IF $OVERFLOW THEN....
! Report error
! No warning or error
Example 15-91. $UDIVREM32 Routine
INT(32)
INT
INT(32)
INT
dividend;
divisor;
quotient;
remainder;
$UDIVREM32(dividend, divisor, quotient, remainder);
HP pTAL Reference Manual—523746-006
15 -92
Built-In Routines
$UNLOCKPAGE
$UNLOCKPAGE
Note. The EpTAL compiler does not support this procedure.
$UNLOCKPAGE unlocks one page of memory..
unlockcount
(
$UNLOCKPAGE
virtaddr
,
)
;
VST655.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
unlockcount
input
sINT:value
is the total number of bytes to unlock in the page.
virtaddr
input
EXTADDR:value
is the beginning virtual address to unlock. $UNLOCKPAGE calculates the page
associated with virtaddr.
Example 15-92. $UNLOCKPAGE Routine
INT
EXTADDR
unlockcount;
addr;
$UNLOCKPAGE(unlockcount, addr);
$WADDR_TO_BADDR
$WADDR_TO_BADDR converts a WADDR address to a BADDR address.
$WADDR_TO_BADDR
(
expression
)
VST691.vsd
HP pTAL Reference Manual—523746-006
15 -93
Built-In Routines
$WADDR_TO_EXTADDR
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is a WADDR address.
Example 15-93. $WADDR_TO_BADDR Routine
STRING .s;
INT
t;
@s := $WADDR_TO_BADDR(@t);
! @t is a WADDR address
$WADDR_TO_EXTADDR
$WADDR_TO_EXTADDR converts a WADDR address to an EXTADDR address.
$WADDR_TO_EXTADDR
(
expression
)
VST692.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
expression
is an expression whose value is a WADDR address.
Example 15-94. $WADDR_TO_EXTADDR Routine
STRING .EXT s;
INT
t;
@s := $WADDR_TO_EXTADDR(@t);
! @t is a WADDR address
HP pTAL Reference Manual—523746-006
15 -94
Built-In Routines
$WRITEPTE
$WRITEPTE
Note. The EpTAL compiler does not support this procedure.
$WRITEPTE writes a segment-page-table entry.
$WRITEPTE
abs
)
(
ptetag
,
pageframe
,
:
VST656.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
Yes
Sets $OVERFLOW
No
ptetag
input
uINT:value
are the page attribute bits associated with pageframe.
pageframe
input
INT(32):value
is the frame number of the physical frame associated with abs.
abs
input
EXTADDR:value
is the virtual address to which $WRITEPTE maps pageframe.
Example 15-95. $WRITEPTE Routine
INT
INT(32)
EXTADDR
ptetag;
pageframe;
abs;
$WRITEPTE(ptetag, pageframe, abs);
HP pTAL Reference Manual—523746-006
15 -95
Built-In Routines
$XADR
$XADR
$XADR converts a standard address to an EXTADDR address.
$XADR
(
variable
)
VST115.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
variable
is a variable that has a standard address.
$XADR returns an EXTADDR address. If the argument to $XADR is not a variable, the
compiler reports an error.
$XADR returns an absolute extended EXTADDR address in absolute segment 1 if
variable is a system global address (an SGBADDR, SGWADDR, SGXBADDR, or
SGXWADDR address).
Variable can be the name of a pointer preceded by an “@” operator. In this case,
$XADR returns the absolute address of the pointer, as in the following example.
Example 15-96. $XADR Routine
PROC p;
BEGIN
INT .p;
INT .EXT e;
...
@e := $XADR(@p);
...
END;
HP pTAL Reference Manual—523746-006
15 -96
16
Compiling and Linking pTAL
Programs
Input to the compiler is a source file containing pTAL source text (such as data
declarations, statements, compiler directives, and comments).
Output from the compiler is a linkfile consisting of relocatable code and data blocks.
To produce an executable pTAL program, link one or more linkfiles into a single loadfile
(see Figure 16-1 on page 16-1).
Figure 16-1. Compiling and Linking pTAL Programs
pTAL Source File 1
pTAL Source File 2
Compiler
Compiler
Nonexecutable
Object File 1
Nonexecutable
Object File 2
...
pTAL Source File n
Compiler
...
Nonexecutable
Object File n
Linker
Executable
Object File
VST699.vsd
HP pTAL Reference Manual—523746-006
16- 1
Compiling and Linking pTAL Programs
Compiling Source Files
Topics:
•
•
•
•
•
•
Compiling Source Files on page 16-2
Linking Object Files on page 16-7
Creating a Dynamic Linked Library (DLL) on page 16-12
Compiling With Global Data Blocks on page 16-12
Compiling With Saved Global Data on page 16-17
Using the Code Coverage Tool on page 16-17
Note. The remainder of this section applies only to Guardian platforms. To compile and link
pTAL programs on Windows platforms, see Section 18, pTAL Cross Compiler.
Compiling Source Files
The compiler reads input files, produces output files, and uses swap files and
temporary files as needed. On Guardian platforms, you use HP TACL commands to
compile source files. The compiler accepts information you specify in HP TACL
commands (DEFINE, PARAM, and ASSIGN) if you issue them before you run the
compiler. For a summary of HP TACL commands, see Appendix B, Disk File Names
and HP TACL Commands.
Example 16-1. Compiler Command Lines
ptal / in test, out $s.#test, nowait/ testobj; symbols
eptal / in test, out $s.#test, nowait/ testobj; symbols
The compiler reads input only from a single edit-format disk file. You can use the
SOURCE on page 17-60 in this input file to read code from other source files during
compilation. The input file and code read from other source files comprise a
compilation unit.
In general, the compiler opens each source file as it needs the source file and keeps
the source file open until the end of the compilation. This behavior ensures that the
contents of the file cannot change between the time the compiler reads the file and
creates a listing. You can open a source file for read access, but generally not for write
access, while the source file is compiling.
When the number of files read exceeds the maximum number of files that Guardian
allows to be open, the compiler closes the least recently used file (unless that file is the
primary source file, which is always kept open) in order to continue to open and read
source files.
If you edit a file before the compiler creates an output listing, the source code in the
listing will not match the code in the source file. The compiler reports a warning if it
HP pTAL Reference Manual—523746-006
16- 2
Compiling and Linking pTAL Programs
Input Files
discovers that part of a source file has changed. Do not alter the source files until the
compilation ends.
Topics:
•
•
•
•
Input Files on page 16-3
Output Files on page 16-3
Running the Compiler on page 16-4
Completion Codes Returned by the Compiler on page 16-6
Input Files
The compiler reads input only from an edit-format disk file up to a maximum of 132
characters for each record, ignoring characters after the 132nd (and issuing a warning
for each such line). The compiler does not read input from a terminal or from any other
source or file format.
Output Files
You can direct list output from the compiler to any of the following types of files:
•
•
•
•
•
•
•
•
Spooler
Entry-sequenced file
Relative file
Terminal
Process
Printer
Edit-format file
HP TACL variable
If you direct output to a disk file that does not exist, the compiler creates an edit-format
file and writes the compiler listing to the newly created file.
If you direct output to an edit-format file that already exists, the compiler removes the
existing file from your current compilation and creates a new file using the file name
you specified.
Difference between pTAL and EpTAL compilers:
pTAL Compiler
EpTAL Compiler
On Guardian platforms, object files have the
file code 700
On Guardian platforms, object files have the
file code 800
HP pTAL Reference Manual—523746-006
16- 3
Compiling and Linking pTAL Programs
Running the Compiler
Running the Compiler
To run the compiler on Guardian platforms, issue a compilation command at the
HP TACL prompt. Options that you can specify in the compilation command are:
•
•
•
•
IN File Option on page 16-4
OUT File Option on page 16-4
HP TACL Run Options on page 16-5
Target File Option on page 16-6
You can include one or more compiler directives in the compilation command (see
Compilation Command on page 17-1).
IN File Option
The IN file is the primary source file. You can specify a file name or a DEFINE as
described in Appendix B, Disk File Names and HP TACL Commands. In this example,
the IN file is mysource.
pTAL /IN mysource/ myobject
EpTAL /IN mysource/ myobject
The IN file must be an edit-format disk file. The compiler reads the file as 132-byte
records.
OUT File Option
The OUT file receives the compiler listings. The OUT file can be any of the files listed
in Output Files on page 16-3.
In an unstructured disk file, each record has 132 characters; partial lines are filled with
blanks through column 132. You can specify a file name or a DEFINE name. The OUT
file is often a spooler location, such as $s.#lists in the following example:
PTAL /IN mysource, OUT $s.#lists/ myobject
EPTAL /IN mysource, OUT $s.#lists/ myobject
If you omit OUT and the HP TACL product is in interactive mode, the listings go to the
home terminal. In noninteractive mode, the listings go to the current HP TACL OUT file:
PTAL /IN mysource/ myobject
EPTAL /IN mysource/ myobject
HP pTAL Reference Manual—523746-006
16- 4
Compiling and Linking pTAL Programs
Running the Compiler
HP TACL Run Options
You can include one or more HP TACL run options in the compilation command, such
as:
•
•
•
•
•
A process name
A CPU number
A priority level
The NOWAIT option
A swap volume
For example, you can specify CPU 3 and NOWAIT when you run the compiler:
pTAL /IN mysource, CPU 3, NOWAIT/ myobject
EpTAL /IN mysource, CPU 3, NOWAIT/ myobject
For information about HP TACL run options, see the RUN command in the TACL
Reference Manual.
By default, the compiler and its processes can run at a high PIN. If your compilation
accesses files on systems running C-series software, you must run the compiler at a
low PIN.
To run the compiler at a low PIN, set HIGHPIN OFF, as shown in the following
HP TACL command:
SET HIGHPIN OFF
When you set HIGHPIN OFF in the HP TACL program, the program runs all processes
at a low PIN except processes that explicitly specify the HIGHPIN ON option when the
process is created.
To ensure that the compiler runs at a low PIN without affecting other processes, specify
the run command’s HIGHPIN OFF option, as in the following example:
PTAL / HIGHPIN OFF .../ ...
EPTAL / HIGHPIN OFF .../ ...
HP pTAL Reference Manual—523746-006
16- 5
Compiling and Linking pTAL Programs
Completion Codes Returned by the Compiler
Target File Option
The target file is the disk file that is to receive the object code. You can specify a file
name or a DEFINE name as described in Appendix B, Disk File Names and HP TACL
Commands.
These examples write the object code to a disk file named myobject:
pTAL /IN mysource/ myobject
EpTAL /IN mysource/ myobject
If you omit the target file, the compiler creates a file named object on your current
default subvolume.
If an existing file has the name object or the name you specify, and the existing file
has the correct filecode (700 for the pTAL compiler, 800 for EpTAL compiler), the
compiler overwrites the existing file. (The compiler overwrites the existing file by
purging it and then creating a new file that has the same name and filecode.)
If the compiler cannot purge the existing file, the compiler creates a file named
ZZPTnnnn, where nnnn is a different number each time.
Completion Codes Returned by the Compiler
When the compiler compiles a source file, it either completes the compilation normally
or stops abnormally. It then returns a process-completion code to the HP TACL product
indicating the status of the compilation.
Table 16-1. Completion Codes
Code
Termination
Meaning
0
Normal
The compiler found no errors or unsuppressed warnings in the
source file. (Warnings suppressed by the NOWARN directive do
not count.) The object file is complete and valid (unless a SYNTAX
directive suppressed its creation).
1
Normal
The compiler found at least one unsuppressed warning. (Warnings
suppressed by the NOWARN directive have no effect.) The object
file is complete and valid (unless a SYNTAX directive suppressed
its creation).
2
Normal
The compiler found at least one compilation error and did not
create an object file, but completed processing the source.
3
Abnormal
The compiler exhausted an internal resource such as symbol table
space or could not access an external resource such as a file. The
compiler did not create an object file.
8
Normal
The compiler could not use the object file name you specified, so it
chose the name reported in the summary. The object file is
complete and valid.
HP pTAL Reference Manual—523746-006
16- 6
Compiling and Linking pTAL Programs
Linking Object Files
Linking Object Files
The linker links one or more linkfiles to produce either a loadfile or another linkfile.
The compiler and compiler directives you use determine the linker you must use and
the kind of executable object code that is produced:
Compiler
Compiler Directive
Linker
Object Code
EpTAL
CALL_SHARED (default)
eld
PIC
CALL_SHARED
ld
PIC
NOCALL_SHARED (default)
nld
Non-PIC
NOCALL_SHARED (error)
pTAL
The linker can also strip nonessential information from an object file and modify the
object file’s process attributes (such as HIGHPIN). For more information, see:
•
•
•
eld Manual
ld Manual
nld Manual
The simplest cases are:
•
•
On TNS/E, use the EpTAL compiler and the eld utility to create an object file that
executes on TNS/E (see Figure 16-2 on page 16-8).
On TNS/R, use the pTAL compiler and either the ld or nld utility to create an
object file that executes on TNS/R (see Figure 16-3 on page 16-9).
Also, TNS allows you to create object files that execute on TNS/R. Use the TAL
compiler and Binder on TNS and the Accelerator (AXCEL) on either TNS or TNS/R to
create an object file that executes on TNS/R (see Figure 16-4 on page 16-10). (In this
case, you begin with TAL source code rather than pTAL source code.)
You can input some kinds of loadfiles to the Accelerator (AXCEL) and the Object Code
Accelerator (OCA) to produce hybrid loadfiles (see Figure 16-5 on page 16-11).
You cannot link PIC and non-PIC object files into a single object file.
HP pTAL Reference Manual—523746-006
16- 7
Compiling and Linking pTAL Programs
Linking Object Files
Figure 16-2. Creating a Loadfile on TNS/E for TNS/E
pTAL Source Code
EpTAL Compiler
TNS/E Nonexecutable
Object Code (PIC)
eld
TNS/E Executable
Object Code (PIC)
VST045.vsd
The source code can be in one or more files. From each source code file, the compiler generates a single
nonexecutable object code file. Input these object code files to the linker to produce a single loadfile. (See
Figure 16-1 on page 16-1.)
HP pTAL Reference Manual—523746-006
16- 8
Compiling and Linking pTAL Programs
Linking Object Files
Figure 16-3. Creating Loadfiles on TNS/R for TNS/R
pTAL Source Code
pTAL Compiler
NOCALL_SHARED
directive (default)
CALL_SHARED
directive
TNS/R Nonexecutable
Object Code (non-PIC)
TNS/R Nonexecutable
Object Code (PIC)
nld
ld
TNS/R Executable
Object Code (non-PIC)
TNS/R Executable
Object Code (PIC)
VST054.vsd
The source code can be in one or more files. From each source code file, the compiler generates a single
nonexecutable object code file.
If you compile multiple source files, either compile all of them using the CALL_SHARED directive or all of them
without using the CALL_SHARED directive (you cannot link PIC and non-PIC object files into a single object file).
Input these object code files to the appropriate linker to produce a single loadfile. (See Figure 16-1 on page 16-1.)
HP pTAL Reference Manual—523746-006
16- 9
Compiling and Linking pTAL Programs
Linking Object Files
Figure 16-4. Creating a Loadfile on TNS for TNS/R
TNS
TAL Source Code
TAL Compiler
TNS Nonexecutable
Object Code (non-PIC)
Binder
TNS Executable Object
Code (non-PIC)
TNS/R
AXCEL
TNS & TNS/R
Executable
Object Code (non-PIC)
VST824.vsd
The source code can be in one or more files. From each source code file, the compiler generates a single
nonexecutable object code file. Input these object code files to Binder to produce a single loadfile. (Figure 16-1 on
page 16-1 illustrates this concept, but uses a linker instead of Binder.)
HP pTAL Reference Manual—523746-006
16 -10
Compiling and Linking pTAL Programs
Linking Object Files
As Figure 16-4 on page 16-10 shows, the Accelerator (AXCEL) is available on both
TNS/R and TNS processors; therefore, you can do either of the following:
•
•
Accelerate your TNS executable object code while it is on a TNS processor and
then move the resulting executable object code to a TNS/R processor.
Move your TNS executable object code to a TNS/R processor and then accelerate
it.
In both cases, the resulting executable object code executes only on TNS/R
processors.
Figure 16-5. Producing Hybrid Loadfiles
TNS Executable Object
Code (non-PIC)
AXCEL
TNS & TNS/R
Executable
Object Code (non-PIC)
OCA
OCA
TNS & TNS/R & TNS/E
Executable Object Code
(PIC)
TNS & TNS/E
Executable Object Code
(PIC)
VST044.vsd
AXCEL is available on TNS/E, TNS/R, and TNS processors.
OCA is available on TNS/E and TNS/R processors.
Non-PIC hybrid loadfiles run on the TNS/R architecture. PIC hybrid loadfiles run on the
TNS/E architecture.
HP pTAL Reference Manual—523746-006
16 -11
Compiling and Linking pTAL Programs
Creating a Dynamic Linked Library (DLL)
Creating a Dynamic Linked Library (DLL)
To create a dynamic-link library (DLL) from pTAL source files, compile the pTAL source
files by using the CALL_SHARED directive (in the Guardian environment) or the
-call_shared flag (in the Windows environment), and then use ld or eld to link the
pTAL source files through the -shared option.
The compiler does not automatically export program names. You must specify
-export_all or -export to the linker.
Compiling With Global Data Blocks
When you compile modules of a program separately or link pTAL code with code
written in other languages, the linking process relocates some of your global data.
Topics:
•
•
•
•
Declaring Global Data on page 16-12
Allocating Global Data Blocks on page 16-15
Address Assignments on page 16-15
Sharing Global Data Blocks on page 16-16
Declaring Global Data
You can declare blocked and unblocked global data (variables, LITERALs, and
DEFINEs).
Blocked global data declarations are those appearing within BLOCK declarations.
BLOCK declarations let you group global data declarations into named or private
blocks. Named blocks are shareable among all compilation units in a program. The
private block is private to the current compilation unit. If you include a BLOCK
declaration in a compilation unit, you must assign an identifier to the compilation unit
by using a NAME declaration.
Unblocked global data declarations are those appearing outside a BLOCK declaration.
Such declarations are also relocatable and shareable among all compilation units in a
program.
If you do not use the BLOCKGLOBALS directive, then all separate compilations must
specify exactly the same list of unblocked global data declarations.
If present in a compilation unit, global declarations must appear in the following order:
1.
2.
3.
4.
NAME declaration
Unblocked global data declarations
BLOCK declarations
PROC declarations
HP pTAL Reference Manual—523746-006
16 -12
Compiling and Linking pTAL Programs
Declaring Global Data
Topics:
•
•
•
•
Naming Compilation Units on page 16-13
Declaring Named Data Blocks on page 16-13
Declaring Private Data Blocks on page 16-14
Declaring Unblocked Data on page 16-14
Naming Compilation Units
To assign an identifier to a compilation unit, specify the NAME declaration as the first
declaration in the compilation unit. (If no BLOCK declaration appears in the compilation
unit, you need not include the NAME declaration.) In the NAME declaration, specify
an identifier that is unique among all BLOCK and NAME declarations in the target file.
Example 16-2. Naming a Compilation Unit
NAME input_module;
! Name the compilation unit
Declaring Named Data Blocks
A named data block is a global data block that is shareable among all compilation units
in a program. You can include any number of named data blocks in a compilation unit.
To declare a named data block:
•
•
Put a NAME declaration in the compilation (see Naming Compilation Units on
page 16-13).
Specify an identifier in the BLOCK declaration that is unique among all BLOCK and
NAME declarations in the target file.
Example 16-3. Declaring a Named Data Block
BLOCK globals;
! Declare named data block
INT .vol_array[0:7];
! Declare global data
INT .out_array[0:34];
DEFINE xaddr = INT(32)#;
END BLOCK;
A variable declared in a named data block can have the same name as the data block.
Modules written in pTAL can share global variables with modules written in HP C by
placing each shared variable in its own block and giving the variable and the block the
same name.
Example 16-4. Data Block and Variable With the Same Name
BLOCK c_var;
INT c_var;
END BLOCK;
HP pTAL Reference Manual—523746-006
16 -13
Compiling and Linking pTAL Programs
Declaring Global Data
Declaring Private Data Blocks
A private data block is a global data block that is shareable only among the procedures
within a compilation unit. You can include only one private data block in a compilation
unit. The private data block inherits the identifier you specify in the NAME declaration;
therefore, the NAME declarations in all compilations that you use to assemble an
executable program must have unique names. To declare a private global data block,
specify the PRIVATE option of the BLOCK declaration.
Example 16-5. Declaring a Private Data Block
BLOCK PRIVATE;
INT term_num;
LITERAL msg_buf = 79;
END BLOCK;
! Declare private global data block
! Declare global data
Declaring Unblocked Data
Place all unblocked global declarations (those not contained in BLOCK declarations)
before the first BLOCK declaration. Unblocked declarations are relocatable and
shareable among all compilation units in a program. The linking name of the private
data block is derived from the NAME declaration.
Example 16-6. Declaring Unblocked Data
INT a;
INT .b[0:9];
INT .EXT c[0:14];
LITERAL limit = 32;
The compiler places unblocked data declarations in implicit primary data blocks,
created as follows:
1. When you use named blocks, private blocks, or the BLOCKGLOBALS directive,
each data item becomes its own block. All the other unblocked data items are
grouped into a block named _GLOBAL and $_GLOBAL.
2. Each block so created is split into two blocks to separate “large” data from “small”
data. “Large” data means arrays or structures declared with “.” or “.EXT” notation.
“Small” data is everything else. When both blocks exist, the “large” data block has
a $ in front of its name.
For example, if you have the following global data declarations:
INT x;
INT .y;
INT .z [0:113]
Variables x and y are placed in the block named _GLOBAL, and z is placed in the
block named $_GLOBAL.
HP pTAL Reference Manual—523746-006
16 -14
Compiling and Linking pTAL Programs
Allocating Global Data Blocks
Named data blocks are split the same way. For example:
BLOCK blk;
INT x;
INT .y;
INT .ext z [0:99];
END BLOCK;
Two data blocks are created. Variables x and y are placed in the block named BLK
and z is placed in the block named $BLK.
You can link object files compiled with and without template blocks with no loss of
information.
A referral structure and the structure layout to which it refers can appear in different
data blocks. The structure layout must appear first.
In all other cases, a data declaration and any data to which it refers must appear in the
same data block. The following declarations, for example, must appear in the same
data block:
INT var;
INT .ptr := @var;
! Declare var
! Declare ptr by referring to var
If the reference is not in the same block, the compiler issues an error message.
Allocating Global Data Blocks
When you compile a program, the compiler constructs relocatable blocks of code and
data that are linked into the object file. The compiler:
•
•
Allocates each read-only array in its own data block in the code segment of the
object file
Allocates all other variables in relocatable global data blocks in the data segment
(except LITERALs and DEFINEs, which require no storage space)
Data is divided between “large” and “small” data sections.
The compiler associates the symbol information for the allocated variables with that
data block. The compiler also associates the symbol information for any LITERALs,
DEFINEs, or read-only arrays declared in that data block, but allocates 0 words of
storage for such declarations.
Address Assignments
The compiler assigns each direct variable and each pointer an offset from the
beginning of the encompassing global data block. Within the data block, it allocates
storage for each data declaration according to its data type and size.
HP pTAL Reference Manual—523746-006
16 -15
Compiling and Linking pTAL Programs
Sharing Global Data Blocks
Sharing Global Data Blocks
Because the length of any shared data block must match in all compilation units, it is
recommended that you declare all shareable global data in one source file. You can
then share that global data block with other source files as follows:
1. In the source file that declares the data block, specify the SECTION directive at the
beginning of the data block to assign a section name to the data block. The
SECTION directive remains active until another SECTION directive or the end of
the source file occurs:
NAME calc_unit;
?SECTION unblocked_globals ! Name first section
LITERAL true
= -1,
! Implicit data block
false = 0;
STRING read_only_array = 'P' := [ " ","COBOL", "FORTRAN",
"PASCAL", "pTAL"];
?SECTION default
BLOCK default_vol;
INT .vol_array [0:7],
.out_array [0:34];
END BLOCK;
! Name second section
! Declare named block
?SECTION msglits
BLOCK msg_literals;
LITERAL msg_eof
= 0,
msg_open = 1,
msg_read = 2;
END BLOCK;
! Name third section
! Declare named block
! End msglits section
?SECTION end_of_data_sections
2. In each source file that needs to include the sections, specify the file name and the
section names in a SOURCE directive:
NAME input_file;
?SOURCE calcsrc(unblocked_globals)
?SOURCE calcsrc(default)
! Specify implicit block
! Specify named block
3. If you then change any declaration within a data block that has a section name,
you must recompile all source files that include SOURCE directives listing the
changed data block.
HP pTAL Reference Manual—523746-006
16 -16
Compiling and Linking pTAL Programs
Compiling With Saved Global Data
Compiling With Saved Global Data
Note. This topic applies only to the pTAL compiler. If you are using the EpTAL compiler, see
Migrating from TNS/R to TNS/E on page 17-11.
During program development or maintenance, you often need to change procedural
code or data without changing the global declarations. You can save the global data in
a file during a compilation session and then use the saved global data during a
subsequent compilation. You can shorten the compile time by not compiling global
declarations each time. For more information, see Saving and Using Global Data
Declarations on page 17-8.
Using the Code Coverage Tool
The Code Coverage Tool evaluates the code coverage provided by application test
cases. The tool uses information provided by a specially-instrumented object file to
produce a report that indicates which functions and blocks were executed, and how
many times each was executed.
Using the Code Coverage Tool requires a special compilation to produce an object file
containing the required instrumentation. To create such an object file, specify the
CODECOV directive in the compiler command line.
Note. The Code Coverage Tool is intended for data generation and collection in a test
environment only. The use of instrumented object code is not recommended for production
environments. Applications compiled with code coverage instrumentation will experience
greatly reduced performance.
For details on using the Code Coverage Tool, see the Code Coverage Tool Reference
Manual.
HP pTAL Reference Manual—523746-006
16 -17
Compiling and Linking pTAL Programs
HP pTAL Reference Manual—523746-006
16 -18
Using the Code Coverage Tool
17
Compiler Directives
Topics:
•
•
•
•
•
•
•
Specifying Compiler Directives on page 17-1
File Names as Compiler Directive Arguments on page 17-3
(Guardian platforms only)
Directive Stacks on page 17-4
Toggles on page 17-5
Saving and Using Global Data Declarations on page 17-8
Summary of Compiler Directives on page 17-13
Topics for individual compiler directives, beginning with ASSERTION on
page 17-19
Specifying Compiler Directives
You can specify compiler directives either in the compilation command or in a directive
line in the source code, unless otherwise specified. The compiler interprets and
processes each directive at the point of occurrence.
Topics:
•
•
Compilation Command on page 17-1
Directive Line on page 17-2
Compilation Command
compilation-command
;
directive
,
VST063.vsd
compilation-command
is as described in Running the Compiler on page 16-4.
HP pTAL Reference Manual—523746-006
17- 1
Compiler Directives
Directive Line
directive
is a directive listed in Table 17-1 on page 17-14 or Table 17-2 on page 17-17,
except the following, which can appear only in the source file (see Directive Line
on page 17-2):
•
•
•
•
•
•
•
ASSERTION on page 17-19
BEGINCOMPILATION on page 17-20 (not recommended)
ENDIF on page 17-29
IF and IFNOT on page 17-39
PAGE on page 17-51
SECTION on page 17-57
SOURCE on page 17-60
Example 17-1. Compilation Commands With Compiler Directives
EPTAL /IN mysrc, OUT $s.#lists/ myobj; NOMAP, NOLIST
pTAL /IN mysrc, OUT $s.#lists/ myobj; NOMAP, NOLIST
Directive Line
The general form of a directive line is:
?
directive
,
VST120.vsd
?
indicates a directive line, and can appear only in column 1.
directive
is a directive listed in Table 17-1 on page 17-14 or Table 17-2 on page 17-17,
except OPTIMIZEFILE, which can appear only in the command line (see
Compilation Command on page 17-1).
HP pTAL Reference Manual—523746-006
17- 2
Compiler Directives
File Names as Compiler Directive Arguments
Rules for directive lines:
•
•
•
•
Begin each directive line by specifying ? in column 1. (? is not part of the directive
name.)
Place the name of the directive and its arguments on the same line unless the
directive description says you can use continuation lines.
Do not put extra characters (such as semicolons) at the end of a directive line.
Do not use an equal sign (=) in the directive unless the directive’s syntax includes
one (as in ASSERTION on page 17-19).
Rules for continuation lines:
•
Begin each continuation line by specifying ? in column 1.
?NOLIST, SYMBOLS, NOMAP, GMAP
?INNERLIST
•
Place the opening parenthesis of the argument list on the same line as the
directive name.
?NOLIST, SOURCE $SYSTEM.SYSTEM.EXTDECS (
? process_getinfo_,
? process_stop_)
File Names as Compiler Directive Arguments
Note. This topic applies only to Guardian platforms, not Windows platforms.
The following directives accept Disk File Names on page B-1, DEFINE names, and
ASSIGN names as arguments:
•
•
•
•
ERRORFILE on page 17-30
SAVEGLOBALS on page 17-56 (not recommended)
SOURCE on page 17-60
USEGLOBALS on page 17-69 (not recommended)
A DEFINE name or an ASSIGN name is considered a logical file name (see Logical
File Names on page B-4). The directives listed above accept a logical file name in
place of a file name.
You can specify partial file names. If you specify a partial file name, the compiler uses
default values as described in Partial File Names on page B-3.
For the USEGLOBALS directive (not recommended) and the SOURCE and directive,
the compiler can use the node (system), volume, and subvolume specified in ASSIGN
SSV commands, as in Example 17-3 on page 17-7.
HP pTAL Reference Manual—523746-006
17- 3
Compiler Directives
Directive Stacks
Directive Stacks
Each of these directives has a compile-time directive stack onto which you can push,
and from which you can pop, directive settings:
•
•
•
•
•
•
•
•
•
CHECKSHIFTCOUNT on page 17-23
DEFEXPAND on page 17-26
DO_TNS_SYNTAX on page 17-28
GP_OK on page 17-38
INNERLIST on page 17-42
LIST on page 17-44
MAP on page 17-45
OVERFLOW_TRAPS on page 17-49
REFALIGNED on page 17-53
Each directive stack is 31 levels deep.
Topics:
•
•
•
Pushing Directive Settings on page 17-4
Popping Directive Settings on page 17-4
Example on page 17-5
Pushing Directive Settings
When you push the current directive setting onto a directive stack, the current directive
setting of the source file remains unchanged until you specify a new directive setting.
To push a directive setting onto a directive stack, specify the directive name prefixed by
PUSH. For example, to push the current setting of the LIST directive onto the LIST
directive stack, specify PUSHLIST. The other values in the directive stack move down
one level. If a value is pushed off the bottom of the directive stack, that value is lost. No
diagnostic message is issued if too many items are pushed onto the stack.
Popping Directive Settings
To restore the top value from a directive stack as the current setting from the source
file, specify the directive name prefixed by POP. For example, to restore the top value
off the LIST directive stack, specify POPLIST. The remaining values in the directive
stack move up one level, and the vacated level at the bottom of the stack is set to the
off state. No diagnostic message is issued if too many items are popped from the
stack.
HP pTAL Reference Manual—523746-006
17- 4
Compiler Directives
Example
Example
In Example 17-2 on page 17-5:
1. LIST is the default setting for the source file.
2. PUSHLIST pushes the LIST directive setting onto the LIST directive stack.
3. NOLIST suppresses listing of procedures included by the SOURCE directive.
4. POPLIST pops the top value from the LIST directive stack and restores LIST as
the current setting for the remainder of the source file.
Example 17-2. Pushing and Popping a Directive Stack
! LIST is the default setting for the source file
?PUSHLIST, NOLIST, SOURCE $SYSTEM.SYSTEM.EXTDECS (
? PROCESS_GETINFO_, FILE_OPEN_, WRITEREADX, READX)
?POPLIST
Toggles
Toggles allow these directives to effect conditional compilation:
Directive
Description
DEFINETOG
Specifies toggles without changing their settings. If DEFINETOG is
specifying a toggle for the first time, its setting is off.
SETTOG
Specifies toggles and turns them on
RESETTOG
Specifies toggles and turns them off
IF and IFNOT
Begin conditional compilation, based on the value of a specified toggle
ENDIF
Ends conditional compilation
Topics:
•
•
•
Named Toggles on page 17-6
Numeric Toggles on page 17-6
Examples on page 17-6
HP pTAL Reference Manual—523746-006
17- 5
Compiler Directives
Named Toggles
Named Toggles
Before you use a named toggle in an IF or IFNOT directive, you must specify that
name in a DEFINETOG, SETTOG, or RESETTOG directive. Which of these directives
you use depends on whether you want the setting of the toggle to be unchanged,
turned on, or turned off.
Setting
Directive
New Toggle
Specified Existing Toggle
DEFINETOG
Off
Unchanged
SETTOG
On
On
RESETTOG
Off
Off
You can use DEFINETOG if you are not sure the toggles were created earlier in the
compilation, possibly in a file that you included by using a SOURCE directive. If you
specify toggles that already exist, DEFINETOG does not change their settings (as
SETTOG and RESETTOG do).
Numeric Toggles
The numeric toggles are 1 through 15. All other toggles (including 16, 17, and so on)
are considered named toggles.
You can use a numeric toggle in an IF or IFNOT directive even if that toggle has not
been specified in a DEFINETOG, SETTOG, or RESETTOG directive.
By default, all numeric toggles not turned on by SETTOG are turned off. To turn off
numeric toggles turned on by SETTOG, use RESETTOG.
Examples
•
•
•
•
•
Example 17-3, DEFINETOG, IF, and ENDIF Directives, on page 17-7
Example 17-4, DEFINETOG, IFNOT, and ENDIF Directives Directive, on page 17-7
Example 17-5, SETTOG, IF, and ENDIF Directives, on page 17-7
Example 17-6, SETTOG, IFNOT, and ENDIF Directives, on page 17-7
Example 17-7, SETTOG, RESETTOG, IF, and ENDIF Directives, on page 17-8
HP pTAL Reference Manual—523746-006
17- 6
Compiler Directives
Examples
Example 17-3. DEFINETOG, IF, and ENDIF Directives
?DEFINETOG scanner
...
! Define toggle
?IF scanner
PROC skipped;
BEGIN
...
END;
?ENDIF scanner
! Test toggle for on state
! Find it off, skip procedure
! End of skipped procedure
Example 17-4. DEFINETOG, IFNOT, and ENDIF Directives Directive
?DEFINETOG emitter
...
! Define toggle
?IFNOT emitter
! Test toggle for off state
PROC kept;
BEGIN
...
END;
?ENDIF emitter
! Find it off, compile procedure
! End of compiled procedure
Example 17-5. SETTOG, IF, and ENDIF Directives
?SETTOG keep
...
! Create & turn on toggle
?IF keep
PROC kept;
BEGIN
...
END;
?ENDIF keep
! Test toggle for on state
! Find it on, compile procedure
! End of compiled procedure
Example 17-6. SETTOG, IFNOT, and ENDIF Directives
?SETTOG (done, nested)
?IFNOT done
PROC skipped;
BEGIN
...
END;
?ENDIF done
! Create & turn on toggles
! Test toggle for off state
! Find it on, skip procedure
! End of skipped procedure
HP pTAL Reference Manual—523746-006
17- 7
Compiler Directives
Saving and Using Global Data Declarations
Example 17-7. SETTOG, RESETTOG, IF, and ENDIF Directives
?SETTOG (versn1, versn2, 7, 4, 11)
?SETTOG versn3
?RESETTOG (versn2, 7)
! Turn on toggles
! Turn on toggle
! Turn off toggles
...
?IF versn2
PROC version_2;
BEGIN
...
END;
?ENDIF versn2
! Test toggle for on state
! Find it off,
! skip procedure
! End of skipped procedure
Saving and Using Global Data Declarations
For the pTAL compiler, these directives allow you to compile and initialize global data
declarations in one compilation and use them in subsequent compilations:
Directive
Description
SAVEGLOBALS
Saves global data declarations and initial values in one file
USEGLOBALS
Reads global data declarations and initial values saved in a file
BEGINCOMPILATION
Marks the point in the source file where compilation is to begin if
the USEGLOBALS directive is active
Note.
The EpTAL compiler does not accept the SAVEGLOBALS or USEGLOBALS directive.
The EpTAL compiler ignores the BEGINCOMPILATION directive.
•
•
Topics:
•
•
•
•
Saving Global Data Declarations on page 17-9
Retrieving Global Data Declarations on page 17-9
Examples on page 17-10
Migrating from TNS/R to TNS/E on page 17-11
Terms used in the following topics:
Term
Meaning
SAVEGLOBALS compilation
The compilation for which you specify SAVEGLOBALS
SAVEGLOBALS compilation file
The source file for the SAVEGLOBALS compilation
USEGLOBALS compilation
The compilation for which you specify USEGLOBALS
USEGLOBALS compilation file
The source file for the USEGLOBALS compilation
HP pTAL Reference Manual—523746-006
17- 8
Compiler Directives
Saving Global Data Declarations
Saving Global Data Declarations
When you compile with SAVEGLOBALS, the compiler saves the global data
declarations—global data identifiers and their attributes (such as data type and kind of
variable initialization)—in a file whose file code is 701.
If you make no changes in the global data declarations, you can use the saved
declarations in subsequent USEGLOBALS compilations, reducing their compilation
time.
SAVEGLOBALS does not save FORWARD procedure declarations or EXTERNAL
procedure declarations. You must recompile these declarations in the USEGLOBALS
compilation.
When you use the following directives in the SAVEGLOBALS compilation, they affect
subsequent USEGLOBALS compilations as follows:
Directive in
SAVEGLOBALS
Compilation
Effect in Subsequent USEGLOBALS Compilations
SYNTAX
Negates the need for using the USEGLOBALS compilation because no
object file was produced by the SAVEGLOBALS compilation
PRINTSYM
Continues to print symbols in the listing
SYMBOLS
Continues to make symbols available for all data blocks that had
symbols during the SAVEGLOBALS compilation
You must use the same version of the compiler for the SAVEGLOBALS compilation
and the USEGLOBALS compilation; otherwise, an error occurs in the USEGLOBALS
compilation.
Whenever you switch to a new version of the compiler, you must recompile the source
code using SAVEGLOBALS to create a new global declarations file.
Retrieving Global Data Declarations
After a SAVEGLOBALS compilation completes successfully, you can specify the
following directives in a USEGLOBALS compilation to retrieve the global data
declarations and initializations:
Directive in
USEGLOBALS
Compilation
USEGLOBALS
BEGINCOMPILATION
Effect in Same USEGLOBALS Compilation
•
•
Retrieves global data declarations
Suppresses compilation of text lines and SOURCE directives
(but not other directives) until BEGINCOMPILATION appears
Begins compilation of text lines and SOURCE directives
HP pTAL Reference Manual—523746-006
17- 9
Compiler Directives
Examples
Caution. Be sure the global data declarations in both the SAVEGLOBALS and USEGLOBALS
compilations are identical. If you include new or changed global data declarations anywhere in
the USEGLOBALS source file, results are unpredictable.
The USEGLOBALS compilation terminates if the global declarations file:
•
•
Cannot be found or opened by the compiler
Was created using a different version of the compiler
Examples
The source file in Example 17-8 on page 17-10 (MYPROG) is compiled in examples
Example 17-9 on page 17-10 through Example 17-12 on page 17-11, which show how
the SAVEGLOBALS, USEGLOBALS, BEGINCOMPILATION, and SYNTAX directives
interact.
Example 17-8. MYPROG Source File for Example 17-9 Through Example 17-12
Source File MYPROG
! Source file MYPROG
! Unless USEGLOBALS is active, compile the entire source file.
?SOURCE SHARGLOB
?BEGINCOMPILATION
! When USEGLOBALS is active, compile
! following code
?PUSHLIST, NOLIST, SOURCE $system.system.extdecs
?POPLIST
PROC my_first_proc;
BEGIN
...
END;
PROC my_last_proc;
BEGIN
...
END;
File of Shared Global Data, SHARGLOB
?SOURCE glbfile1 (section1, section2)
?SOURCE moreglbs
INT ignore_me1;
INT ignore_me2;
The compilation command in Example 17-9 on page 17-10 compiles myprog (the
source file in Example 17-8) and saves global data declarations and data initializations.
Example 17-9. Saving Global Data Declarations and Data Initializations
pTAL /IN myprog/ myobj; SAVEGLOBALS ptalsym
HP pTAL Reference Manual—523746-006
17 -10
Compiler Directives
Migrating from TNS/R to TNS/E
A USEGLOBALS compilation (Example 17-10 on page 17-11) then produces object file
newobj and retrieves global data declarations and initialization from ptalsym and
global initializations from myobj. When USEGLOBALS is active, the compiler ignores
text lines and SOURCE directives until BEGINCOMPILATION appears in the source
file.
Example 17-10. Retrieving Global Data Declarations and Data Initializations
pTAL /IN myprog/ newobj; USEGLOBALS ptalsymj
You can check the syntax of global data declarations before saving them, as in
Example 17-11 on page 17-11.
Example 17-11. Checking the Syntax of Global Data Declarations
pTAL /IN myprog/; SAVEGLOBALS ptalsym, SYNTAX
After you correct any errors, you can recompile myprog as in Example 17-12 on
page 17-11.
Example 17-12. Recompiling MYPROG After Correcting Errors
pTAL /IN myprog/; USEGLOBALS ptalsym
Migrating from TNS/R to TNS/E
The EpTAL compiler does not accept the SAVEGLOBALS and USEGLOBALS
directives.
To migrate a pTAL program that uses SAVEGLOBALS and USEGLOBALS from TNS/R
to TNS/E:
1. Remove SAVEGLOBALS from the SAVEGLOBALS compilation command line.
2. Compile the file from Step 1 using the EpTAL compiler, omitting SAVEGLOBALS
from the compilation command.
3. Remove USEGLOBALS from each USEGLOBALS compilation command line.
You can leave BEGINCOMPILATION in this file. The EpTAL compiler ignores
BEGINCOMPILATION, and you need BEGINCOMPILATION if you want to compile
the same files using the pTAL compiler.
4. Compile each file from Step 3 using the EpTAL compiler, omitting USEGLOBALS
from each compilation command.
If all files compile without errors, the migration is done. (To compile the same files
using the pTAL compiler, specify SAVEGLOBALS in the SAVEGLOBALS compilation
command and USEGLOBALS in each USEGLOBALS compilation command.)
HP pTAL Reference Manual—523746-006
17 -11
Compiler Directives
Migrating from TNS/R to TNS/E
If some files do not compile successfully because of missing global data declarations,
the source code files were not set up correctly and you must modify one or more of
them.
For example:
1. Suppose that the original SAVEGLOBALS compilation source file is COMP1 in
Example 17-13 on page 17-12.
Example 17-13. Original SAVEGLOBALS Compilation Source File
! COMP1
?FIELDALIGN (SHARED2)
name x;
?source FILE1
?source FILE2
...
?source FILEn
int i1
struct s(*);
begin
...
end;
! All other common declarations and directives in the
! compilation ...
! End of global declarations
?BEGINCOMPILATION
! All nonglobal declarations,
! including procedure declarations
! End of COMP1
2. Extract all directives and declarations from the beginning of COMP1 to (but not
including) BEGINCOMPILATION. Put them in a new source file called GLOBALS
(see Example 17-14 on page 17-12).
Example 17-14. New GLOBALS Source File (page 1 of 2)
! GLOBALS
?FIELDALIGN (SHARED2)
name x;
?source FILE1
?source FILE2
...
?source FILEn
int i1
HP pTAL Reference Manual—523746-006
17 -12
Compiler Directives
Summary of Compiler Directives
Example 17-14. New GLOBALS Source File (page 2 of 2)
struct s(*);
begin
...
end;
! All other common declarations and directives in the
! compilation
! End of GLOBALS
3. Use a SOURCE directive to include GLOBALS in COMP1 (as in Example 17-15 on
page 17-13).
Example 17-15. Corrected SAVEGLOBALS Compilation Source File
! COMP1
?source GLOBALS
! End of global declarations
?BEGINCOMPILATION
! All other non-global declarations,
! including procedure declarations ...
! End of COMP1
4. In each file that depended on the global data declarations file that the original
COMP1 produced:
•
Use a SOURCE directive to include GLOBALS.
The SOURCE directive must appear before any other declarations and must
be immediately followed by the BEGINCOMPILATION directive.
•
After the BEGINCOMPILATION directive, specify any additional directives that
were originally specified in the compilation command.
Summary of Compiler Directives
Table 17-1 on page 17-14 summarizes directives by categories, which are:
•
•
•
•
•
•
Compiler input on page 17-14
Compiler listing on page 17-14
Diagnostics on page 17-15
Object-file content on page 17-16
Conditional compilation on page 17-17
Run-time environment on page 17-17
Table 17-2 on page 17-17 lists directives by name in alphabetical order.
HP pTAL Reference Manual—523746-006
17 -13
Compiler Directives
Summary of Compiler Directives
Table 17-1. Compiler Directives by Category (page 1 of 4)
Category
Directive
Operation
Compiler
input
BEGINCOMPILATION 1
Marks the point in the source file where
compilation is to begin if the USEGLOBALS
directive is active
COLUMNS
Treats as comments any text that appears
beyond the specified column
SAVEGLOBALS2
Saves global data declarations and initial
values in a file for subsequent use
SECTION
Names a section of the source file
SOURCE
Reads source code from another input file
USEGLOBALS2
Reads global data declarations and initial
values from a file
DEFEXPAND
Expands DEFINEs in the compiler listing
FMAP
Lists the file map in the compiler listing
GMAP
Lists the global map in the compiler listing
INNERLIST
Lists mnemonics after each source statement
LINES
Skips to the top of form after a specified
number of lines if the list file is a line printer or
a process
LIST
Lists the source code
MAP
Lists the identifier map
PAGE
Sets the string to be printed as part of the
heading for each page. Each subsequent
PAGE prints the heading and causes a page
eject.
PRINTSYM
Lists symbols in the compiler listing
SUPPRESS
Suppresses all listings but the header,
diagnostics, and trailer
Compiler
listing
1. The EpTAL compiler ignores this directive.
2. The EpTAL compiler does not accept this directive.
3. The pTAL and EpTAL compilers treat this directive differently.
HP pTAL Reference Manual—523746-006
17 -14
Compiler Directives
Summary of Compiler Directives
Table 17-1. Compiler Directives by Category (page 2 of 4)
Category
Directive
Operation
Diagnostics
ERRORFILE
Writes error and warning messages to an error
file
ERRORS
Terminates compilation after the specified
number of error messages
DO_TNS_SYNTAX
Issues warnings for pTAL constructs that are
not valid in TAL
INVALID_FOR_PTAL
Causes errors for TAL constructs that are not
valid in pTAL
WARN
Suppresses compiler warnings
1. The EpTAL compiler ignores this directive.
2. The EpTAL compiler does not accept this directive.
3. The pTAL and EpTAL compilers treat this directive differently.
HP pTAL Reference Manual—523746-006
17 -15
Compiler Directives
Summary of Compiler Directives
Table 17-1. Compiler Directives by Category (page 3 of 4)
Category
Directive
Operation
Object-file
content
ASSERTION
Conditionally executes a debugging procedure
BLOCKGLOBALS
Determines how the compiler allocates global
data that is not declared within the scope of a
named data block or the private data block
CALL_SHARED 3
Generates shared code (PIC)
CHECKSHIFTCOUNT
Causes overflow traps for invalid bit-shift
operations
CODECOV
Generates instrumented object code for use
by the Code Coverage Tool
EXPORT_GLOBALS
Exports globals
FIELDALIGN
Specifies the default memory alignment for
structures
GLOBALIZED
Generates preemptable object code for use
when building DLLs that require such code
GP_OK1
Generates code that has GP-relative
addressing
OPTIMIZE
Sets the object code’s default optimization
level
OPTIMIZEFILE
Sets the optimization level for individual
procedures and subprocedures
OVERFLOW_TRAPS3
Controls whether overflow traps are enabled
REFALIGNED
Specifies the default memory alignment for
pointers to nonstructure items and procedure
reference pointers
ROUND
Rounds FIXED values assigned to FIXED
variables with smaller fpoint values
SRL1
Generates code that can be included in a user
library
SYNTAX
Checks the syntax, suppressing the object
code
1. The EpTAL compiler ignores this directive.
2. The EpTAL compiler does not accept this directive.
3. The pTAL and EpTAL compilers treat this directive differently.
HP pTAL Reference Manual—523746-006
17 -16
Compiler Directives
Summary of Compiler Directives
Table 17-1. Compiler Directives by Category (page 4 of 4)
Category
Directive
Operation
Conditional
compilation
DEFINETOG
Defines toggles without changing their settings
ENDIF
Identifies the end of code that is to be
conditionally compiled
IF and IFNOT
Identifies the beginning of code that is to be
conditionally compiled
RESETTOG
Turns toggles off
SETTOG
Turns toggles on
TARGET3
Specifies the architecture on which the
program will run
SYMBOLS
Generates a symbol table for a symbolic
debugger
Run-time
environmen
t
1. The EpTAL compiler ignores this directive.
2. The EpTAL compiler does not accept this directive.
3. The pTAL and EpTAL compilers treat this directive differently.
Table 17-2. Compiler Directives by Name (page 1 of 3)
Directive
Operation
ASSERTION
Conditionally executes a debugging procedure
BEGINCOMPILATION1
Marks the point in the source file where compilation is to begin if
the USEGLOBALS directive is active
BLOCKGLOBALS
Determines how the compiler allocates global data that is not
declared within the scope of a named data block or the private
data block
CALL_SHARED 3
Generates shared code (PIC)
CHECKSHIFTCOUNT
Causes overflow traps for invalid bit-shift operations
CODECOV
Generates instrumented object code for use by the Code
Coverate Tool
COLUMNS
Treats as comments any text that appears beyond the specified
column
DEFEXPAND
Expands DEFINEs in the compiler listing
DEFINETOG
Defines toggles without changing their settings
DO_TNS_SYNTAX
Issues warnings for pTAL constructs that are not valid in TAL
ENDIF
Identifies the end of code that is to be conditionally compiled
ERRORFILE
Writes error and warning messages to an error file
1. The EpTAL compiler ignores this directive.
2. The EpTAL compiler does not accept this directive.
3. The pTAL and EpTAL compilers treat this directive differently.
HP pTAL Reference Manual—523746-006
17 -17
Compiler Directives
Summary of Compiler Directives
Table 17-2. Compiler Directives by Name (page 2 of 3)
Directive
Operation
ERRORS
Terminates compilation after the specified number of error
messages
EXPORT_GLOBALS
Exports globals
FIELDALIGN
Specifies the default memory alignment for structures
FMAP
Lists the file map in the compiler listing
GLOBALIZED
Generates preemptable object code for use when building DLLs
that require such code
GMAP
Lists the global map in the compiler listing
GP_OK1
Generates code that has GP-relative addressing
IF and IFNOT
Identifies the beginning of code that is to be conditionally
compiled
INNERLIST
Lists mnemonics after each source statement
INVALID_FOR_PTAL
Causes errors for TAL constructs that are not valid in pTAL
LINES
Specifies the maximum number of output lines per page if the
list file is a line printer or a process
LIST
Lists the source code
MAP
Lists the identifier map
OPTIMIZE
Sets the object code’s default optimization level
OPTIMIZEFILE
Sets the optimization level for individual procedures and
subprocedures
OVERFLOW_TRAPS3
Controls whether overflow traps are enabled.
PAGE
Sets the string to be printed as part of the heading for each
page. Each subsequent PAGE prints the heading and causes a
page eject.
PRINTSYM
Lists symbols in the compiler listing
REFALIGNED
Specifies the default alignment for pointers to nonstructure items
and procedure reference pointers
RESETTOG
Turns off toggles
ROUND
Rounds FIXED values assigned to FIXED variables with smaller
fpoint values
SAVEGLOBALS2
Saves global data declarations and initial values in a file for
subsequent use
SECTION
Names a section of the source file
SETTOG
Turns on toggles
1. The EpTAL compiler ignores this directive.
2. The EpTAL compiler does not accept this directive.
3. The pTAL and EpTAL compilers treat this directive differently.
HP pTAL Reference Manual—523746-006
17 -18
Compiler Directives
ASSERTION
Table 17-2. Compiler Directives by Name (page 3 of 3)
Directive
Operation
SOURCE
Reads source code from another input file
SRL1
Generates code that can be included in a user library
SUPPRESS
Suppresses all listings but the header, diagnostics, and trailer
SYMBOLS
Generates a symbol table for a symbolic debugger
SYNTAX
Checks the syntax, suppressing the object code
TARGET3
Specifies the architecture on which the program will run
USEGLOBALS2
Reads global data declarations and initial values from a file
WARN
Suppresses compiler warnings
1. The EpTAL compiler ignores this directive.
2. The EpTAL compiler does not accept this directive.
3. The pTAL and EpTAL compilers treat this directive differently.
Note. In the following directive topics, “Default:” identifies the default for the compiler directive
itself, not for its optional parameter(s). This default applies if a program does not contain the
compiler directive at all.
ASSERTION
ASSERTION executes a procedure when the condition specified in the active ASSERT
statement is true.
assertion-level
ASSERTION
,
=
procedure-name
VST123.vsd
assertion-level
is an unsigned decimal constant in the range 0 through 32,767.
procedure-name
is the name of the procedure to execute if both:
•
•
The condition defined in the active ASSERT statement is true.
assertion-level is less than the assert-level in the active ASSERT
statement.
This procedure must not have parameters.
HP pTAL Reference Manual—523746-006
17 -19
Compiler Directives
Default:
BEGINCOMPILATION
None
Placement:
•
•
Scope:
Applies until another ASSERTION overrides it
Dependencies:
Has no effect without the ASSERT statement
References:
ASSERT on page 12-3
Anywhere in the source file (not in the compilation command)
Must be the last directive on the directive line
ASSERT on page 12-3 explains how to use the ASSERTION directive and the
ASSERT statement together.
BEGINCOMPILATION
Note. The EpTAL compiler ignores this directive. See Migrating from TNS/R to TNS/E on
page 17-11.
BEGINCOMPILATION marks the point in the source file where:
•
•
The information saved by the SAVEGLOBALS operation ends
Compilation is to begin if the USEGLOBALS directive is active.
BEGINCOMPILATION
VST991.vsd
Default:
Placement:
None
•
•
Scope:
Dependencies:
Can appear only once in a compilation unit
Applies to all source code that follows it in the compilation unit
•
•
•
References:
In the source file between the last global data declaration and the
first procedure declaration, including any EXTERNAL and
FORWARD declarations
•
•
Has no effect without the USEGLOBALS directive
If you specify either SAVEGLOBALS or USEGLOBALS, your
compilation unit must have exactly one BEGINCOMPILATION
directive
Interacts with SAVEGLOBALS and USEGLOBALS (see Saving and
Using Global Data Declarations on page 17-8)
SAVEGLOBALS on page 17-56
USEGLOBALS on page 17-69
HP pTAL Reference Manual—523746-006
17 -20
Compiler Directives
BLOCKGLOBALS
BLOCKGLOBALS
BLOCKGLOBALS determines how the compiler allocates global data that is not
declared within the scope of a named data block or the private data block.
BLOCKGLOBALS
VST658.vsd
Default:
The compiler allocates data items in the _GLOBAL and $_GLOBAL data
blocks
Placement:
Before the first data declaration in a compilation
Scope:
Applies to the compilation unit
Dependencies:
None
If you specify BLOCKGLOBALS, the compiler allocates its own data block for each
global variable that is not declared in the scope of a named data block or the private
data block. The name of the data block is the same as the name of the variable
contained in the data block.
Table 17-3. Data Block Names
Declaration
Without BLOCKGLOBALS
With BLOCKGLOBALS
INT a;
_GLOBAL
A
INT .a;
_GLOBAL
A
INT .EXT a;
_GLOBAL
A
INT a[0:9]
_GLOBAL
A
STRUCT a;
BEGIN
INT i;
END
_GLOBAL
A
int .ext a [0:9]
$_GLOBAL
A
struct .ext a;
begin
int i;
end;
$_GLOBAL
A
Separately compiled modules can share access to a data block only if both modules
allocate the block in the small data area or both modules allocate the block in the large
data area.
References to data in the small data area are faster than references to data in the
large data area.
All data blocks in a shared run-time library must be allocated in the large data area.
HP pTAL Reference Manual—523746-006
17 -21
Compiler Directives
CALL_SHARED
If the name of a variable is the same as the name of the data block in which the
variable is located, and the block only contains one variable, the compiler allocates the
data block in the small data area if the length of the block is eight or fewer bytes;
otherwise, the compiler allocates the data block in the large data area. (This is the
allocation strategy used by the native HP C compiler.)
The compiler does not allocate memory for LITERALs, DEFINEs, or templates and,
therefore, does not create an implicit global data block for these items.
CALL_SHARED
Note.
•
•
This directive is useful only for the pTAL compiler. The EpTAL compiler ignores it (and
issues a warning).
You cannot link PIC and non-PIC object files into a single object file.
CALL_SHARED
NOCALL_SHARED
VST036.vsd
CALL_SHARED
generates shared code (PIC), the only option for the EpTAL compiler.
NOCALL_SHARED
causes the pTAL compiler to generate nonshared code (non-PIC).
Default:
pTAL compiler:
NOCALL_SHARED
EpTAL compiler:
CALL_SHARED
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
•
•
References:
If both CALL_SHARED and NOCALL_SHARED appear in the same
compilation unit, the compiler uses the one that appears last
Do not use CALL_SHARED with GP_OK
GP_OK on page 17-38
HP pTAL Reference Manual—523746-006
17 -22
Compiler Directives
CHECKSHIFTCOUNT
CHECKSHIFTCOUNT
CHECKSHIFTCOUNT
NOCHECKSHIFTCOUNT
PUSHCHECKSHIFTCOUNT
POPCHECKSHIFTCOUNT
VST659.vsd
CHECKSHIFTCOUNT
generates code that causes an overflow trap if the number of positions in a bit-shift
operation is too large, as in:
INT j := 20;
INT i;
i := i << j;
(For more information about bit shifts, see Bit Shifts on page 5-33.)
NOCHECKSHIFTCOUNT
suppresses the generation of code that causes an overflow trap if the number of
positions in a bit-shift operation is too large.
Caution. If such a bit-shift operation occurs, subsequent program behavior is undefined.
PUSHCHECKSHIFTCOUNT
pushes the current setting (CHECKSHIFTCOUNT or NOCHECKSHIFTCOUNT)
onto the CHECKSHIFTCOUNT directive stack. Does not change the current
setting.
POPCHECKSHIFTCOUNT
pops the top value from the CHECKSHIFTCOUNT directive stack and changes the
current setting to that value.
For an explanation of directive stacks, see Directive Stacks on page 17-4.
Default:
NOCHECKSHIFTCOUNT
Placement:
Anywhere
Scope:
•
•
Dependencies:
CHECKSHIFTCOUNT applies to the shift operators that follow it
until it is overridden by NOCHECKSHIFTCOUNT
NOCHECKSHIFTCOUNT applies to the shift operators that follow it
until it is overridden by CHECKSHIFTCOUNT
None
HP pTAL Reference Manual—523746-006
17 -23
Compiler Directives
CODECOV
CODECOV
Note.
•
•
This directive can be used only with the EpTAL compiler.
Instrumented object code can result in greatly reduced performance. Therefore, the
CODECOV directive should be used only in a test environment.
CODECOV causes the compiler to generate instrumented object code for use by the
Code Coverage Tool. For detailed information about the Code Coverage Tool, see the
Code Coverage Tool Reference Manual.
CODECOV
VST834.vsd
Default:
No code coverage instrumentation in object code
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
None
COLUMNS
COLUMNS causes the compiler to treat any text beyond the specified column as
comments.
COLUMNS
columns-value
VST127.vsd
columns-value
is an unsigned decimal constant in the range 12 through 132, the column beyond
which the compiler is to treat text as comments.
If columns-value is smaller than 12 or larger than 132, the compiler issues an
error message.
HP pTAL Reference Manual—523746-006
17 -24
Compiler Directives
Default:
Placement:
COLUMNS
COLUMNS 132
•
•
Scope:
Anywhere, but if COLUMNS appears in the source code, it must be
the only directive on the directive line
Typically specified before any SECTION directive
Applies to all source code that follows it unless overridden by:
•
•
•
Another COLUMNS directive in the same source file (not
recommended)
A COLUMNS directive in a source file included by means of a
SOURCE directive
A COLUMNS directive in a section identified by a SECTION
directive
For details, see the explanation that follows this table.
Dependencies:
References:
None
•
•
SECTION on page 17-57
SOURCE on page 17-60
The columns-value active at any given time depends on the context, as follows:
•
•
•
•
•
•
The main input file initially has the columns-value set by the last COLUMNS
directive in the compilation command. If there was no COLUMNS directive in the
compilation command, the main input file initially has the default columns-value
of 132.
At each SOURCE directive, each included file initially has the columns-value
active when the SOURCE directive appeared.
At each SECTION directive, columns-value is set by the last COLUMNS
directive before the first SECTION directive in the included file. If there is no such
COLUMNS directive, each SECTION initially has the columns-value active at
the beginning of the included file.
Within a section, a COLUMNS directive sets the columns-value only until the
next COLUMNS or SECTION directive or the end of the file.
After a SOURCE directive completes execution (that is, after all sections listed in
the SOURCE directive are read or the end of the file is reached), the compiler
restores columns-value to what it was when the SOURCE directive appeared.
In all other cases, columns-value is set by the most recently processed
COLUMNS directive.
If a SOURCE directive lists sections, the compiler processes no source code outside
the listed sections except any COLUMNS directives that appear before the first
SECTION directive in the included file. For more information about including files or
sections, see SOURCE on page 17-60 and SECTION on page 17-57.
HP pTAL Reference Manual—523746-006
17 -25
Compiler Directives
DEFEXPAND
DEFEXPAND
DEFEXPAND
NODEFEXPAND
PUSHDEFEXPAND
POPDEFEXPAND
VST023.vsd
DEFEXPAND
expands DEFINEs in the compiler listing.
Note. MAP DEFINEs are available only on Guardian platforms.
NODEFEXPAND
suppresses the expansion of DEFINEs in the compiler listing.
PUSHDEFEXPAND
pushes the current setting (DEFEXPAND or NODEFEXPAND) onto the
DEFEXPAND directive stack. Does not change the current setting.
POPDEFEXPAND
pops the top value from the DEFEXPAND directive stack and changes the current
setting to that value.
For an explanation of directive stacks, see Directive Stacks on page 17-4.
Default:
NODEFEXPAND
Placement:
Anywhere
Scope:
•
•
Dependencies:
References:
DEFEXPAND applies to subsequent code it until it is overridden by
NODEFEXPAND
NODEFEXPAND applies to subsequent code until it is overridden by
DEFEXPAND
DEFEXPAND has no effect if NOLIST or SUPPRESS is active
•
•
LIST on page 17-44
SUPPRESS on page 17-65
In the DEFEXPAND listing, the DEFINE body appears on lines following the DEFINE
identifier. In the listing:
•
•
All letters are uppercase.
No comments, line boundaries, or extra blanks appear.
HP pTAL Reference Manual—523746-006
17 -26
Compiler Directives
•
•
DEFINETOG
The lexical level of the DEFINE appears in the left margin, starting at 1.
Parameters to the DEFINE appear as #n, where n is the sequence number of the
parameter, starting at 1.
Example 17-16. DEFEXPAND Directive
?DEFEXPAND
DEFINE increment (x) = x := x + 1#;
DEFINE decrement (y) = y := y - 1#;
! Other global data declarations
! List expanded DEFINEs
! Expanded DEFINE
! Expanded DEFINE
DEFINETOG
DEFINETOG specifies toggles for use in conditional compilation, without changing
their settings. If DEFINETOG is specifying a toggle for the first time, its setting is off.
DEFINETOG
toggle-name
toggle-number
,
(
toggle-name
)
toggle-number
,
VST212.vsd
toggle-name
is an identifier.
The EpTAL compiler allows toggle-name to be RISC1, _TNS_E_TARGET, or
TARGETSPECIFIED, as long as toggle-name does not change the value of
target in the IF, IFNOT, or ENDIF statement (see IF and IFNOT on page 17-39
and ENDIF on page 17-29).
toggle-number
is an unsigned decimal constant in the range 1 through 15. Leading zeros are
ignored.
HP pTAL Reference Manual—523746-006
17 -27
Compiler Directives
DO_TNS_SYNTAX
Default:
None
Placement:
•
•
With a parenthesized list, it can appear anywhere
Without a parenthesized list, it must be the last directive on the
directive line or compilation command line
Scope:
Applies to the compilation unit
Dependencies:
Interacts with:
•
•
•
•
•
SETTOG
RESETTOG
IF
IFNOT
ENDIF
See Toggles on page 17-5.
References:
•
•
•
•
ENDIF on page 17-29
IF and IFNOT on page 17-39
RESETTOG on page 17-54
SETTOG on page 17-58
DO_TNS_SYNTAX
DO_TNS_SYNTAX
NODO_TNS_SYNTAX
PUSHDO_TNS_SYNTAX
POPDO_TNS_SYNTAX
VST663.vsd
DO_TNS_SYNTAX
issues a warning for each occurrence of certain constructs that are valid in pTAL
but not in TAL (for these constructs, see the pTAL Conversion Guide).
NODO_TNS_SYNTAX
suppresses warnings for each occurrence of a construct that is valid in pTAL but
not in TAL.
PUSHTNS_SYNTAX
pushes the current setting (DOTNS_SYNTAX or NODOTNS_SYNTAX) onto the
DOTNS_SYNTAX directive stack. Does not change the current setting.
HP pTAL Reference Manual—523746-006
17 -28
Compiler Directives
ENDIF
POPTNS_SYNTAX
pops the top value from the DOTNS_SYNTAX directive stack and changes the
current setting to that value.
Default:
NODO_TNS_SYNTAX
Placement:
•
•
Scope:
Applies to the compilation unit
Dependencies:
None
References:
TARGET on page 17-68
Can appear only once in a compilation
Must precede any TARGET directive and any nondirective lines
ENDIF
ENDIF identifies the end of code that is to be conditionally compiled.
toggle-name
ENDIF
toggle-number
target
pTAL
VST693.vsd
toggle-name
is an identifier that was used as a toggle-name in an earlier IF or IFNOT
directive.
toggle-number
is an unsigned decimal constant in the range 1 through 15 that was used as a
toggle-name in an earlier IF or IFNOT directive. Leading zeros are ignored.
target
is as defined in IF and IFNOT on page 17-39.
pTAL
identifies the end of code that is to be compiled by the pTAL or EpTAL compiler but
not by the TAL compiler:
Compiler
IF pTAL
IFNOT pTAL
pTAL or EpTAL
True
False
TAL
False
True
HP pTAL Reference Manual—523746-006
17 -29
Compiler Directives
Default:
ERRORFILE
None
Placement:
•
•
Anywhere in the source file (not in the compilation command)
Must be the only directive on the directive line
Scope:
Everything between ENDIF and the most recently compiled IF or IFNOT
directive that specifies the same toggle, target, or keyword
Dependencies:
Interacts with:
•
•
•
•
•
•
DEFINETOG
SETTOG
RESETTOG
IF
IFNOT
TARGET
See Toggles on page 17-5.
References:
•
•
•
•
•
DEFINETOG on page 17-27
IF and IFNOT on page 17-39
RESETTOG on page 17-54
SETTOG on page 17-58
TARGET on page 17-68
ERRORFILE
ERRORFILE writes compilation errors and warnings to an error file so you can use the
HP TACL FIXERRS macro (available only on Guardian platforms) to view the
diagnostic messages in one PS Text Edit window and correct the source file in another
window.
file-name
ERRORFILE
define-name
assign-name
VST137.vsd
file-name
is the name of either:
•
•
An existing error file created by ERRORFILE. Such a file has file code 106 (an
entry-sequenced disk file used only with the HP TACL FIXERRS macro). The
compiler purges any data in it before logging errors and warnings.
A new error file to be created by ERRORFILE if errors occur.
If a file with the same name exists but the file code is not 106, the compiler
terminates compilation to prevent overwriting the file.
HP pTAL Reference Manual—523746-006
17 -30
Compiler Directives
ERRORFILE
You can specify partial file names as described in Partial File Names on page B-3.
The compiler uses the current default volume and subvolume names as needed.
For this directive, the compiler does not use HP TACL ASSIGN SSV information
(available only on Guardian platforms) to complete the file name.
define-name
is the name of a MAP DEFINE that refers to an error file.
Note. MAP DEFINEs are available only on Guardian platforms.
assign-name
is a logical file name you have equated with an error file by issuing an ASSIGN
command.
Default:
Placement:
None
•
•
In the compilation command or in the source code before any
declarations
Can appear only once in a compilation unit
Scope:
Applies to the compilation unit
Dependencies:
None
The compiler writes a header record to the error file and then writes a record for each
error or warning. Each record contains information such as:
•
•
The location of the error or warning—source file name, edit line number, and
column number
The message text of the error or warning
At the end of the compilation, the compiler prints the complete name of the error file in
the trailer message of the compilation listing.
HP pTAL Reference Manual—523746-006
17 -31
Compiler Directives
ERRORFILE
After the compiler logs messages to the error file, you can call the HP TACL FIXERRS
macro and correct the source file. FIXERRS uses the PS Text Edit ANYHOW option to
open the source file in a two-window session. One window displays a diagnostic
message. The other window displays the source code to which the message applies. If
you have write access to the file, you can correct the source code. If you have only
read access, you can view the source code, but you cannot correct it.
Initially, the edit cursor is located in the source code at the first diagnostic. To move the
cursor to the next or previous diagnostic, use the PS Text Edit NEXTERR or
PREVERR command.
The HP TACL command for calling FIXERRS is:
FIXERRS
error-file
;
tedit-cmds
VST211.vsd
error-file
is the name of the error file specified in the ERRORFILE directive.
tedit-cmds
is any PS Text Edit commands that are allowed on the PS Text Edit run line.
Example 17-17 on page 17-32 issues an HP TACL DEFINE command that calls
FIXERRS and defines PS Text Edit function keys for NEXTERR and PREVERR.
Example 17-17. FIXERRS Macro
[#DEF MYFIXERRS MACRO |BODY|
FIXERRS %1%; SET <F9>, NEXTERR; SET <SF9>, PREVERR
]
Example 17-18. ERRORFILE Directive
! MYSOURCE file
?ERRORFILE myerrors
! Compiler reports errors and warnings
! to the file myerrors
!Global declarations
HP pTAL Reference Manual—523746-006
17 -32
Compiler Directives
ERRORS
ERRORS
ERRORS sets the maximum number of error messages to allow before the compiler
terminates the compilation.
num-messages
ERRORS
=
VST138.vsd
num-messages
is an unsigned decimal constant in the range 0 through 32,767 that represents the
maximum number of error messages to allow before the compilation terminates.
Default:
Unlimited number of errors
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
None
A single error can cause many error messages. The compiler counts each error
message separately. If the compiler’s count exceeds the maximum you specify, the
compiler terminates the compilation. (Warning messages do not affect the count.)
Example 17-19. ERRORS Directive
! MYSOURCE file
?ERRORS 10
!Global declarations
! Stop compiling when 10 errors are found
EXPORT_GLOBALS
EXPORT_GLOBALS
NOEXPORT_GLOBALS
PUSHEXPORT_GLOBALS
POPEXPORT_GLOBALS
VST662.vsd
HP pTAL Reference Manual—523746-006
17 -33
Compiler Directives
EXPORT_GLOBALS
EXPORT_GLOBALS
causes the compiler to define (rather than only declare) global data blocks,
allocating space for them and (optionally) giving them initial values, and causes the
linker to include in the program file all global data blocks declared up to the next
occurrence of NOEXPORT_GLOBALS or through the last declared global data
block, whichever is first.
NOEXPORT_GLOBALS
causes the compiler to declare (rather than define) global data blocks.
PUSHEXPORT_GLOBALS
pushes the current setting (EXPORT_GLOBALS or NOEXPORT_GLOBALS) onto
the EXPORT_GLOBALS directive stack. Does not change the current setting.
POPEXPORT_GLOBALS
pops the top value from the EXPORT_GLOBALS directive stack and changes the
current setting to that value.
Default:
Placement:
Scope:
Dependencies:
EXPORT_GLOBALS
•
•
•
Applies to the compilation unit, except that NOEXPORT_GLOBALS
does not affect a compilation’s private data block, which is always
exported
•
•
References:
Can appear any number of times in a compilation unit
Must appear before the first procedure is compiled
Cannot appear within BLOCK declarations
•
•
•
You must specify NOEXPORT_GLOBALS when declaring a data
block that belongs to an SRL
In a compilation that includes USEGLOBALS, the compiler exports
the data blocks declared in the USEGLOBALS declarations file only
if EXPORT_GLOBALS is active when the compiler encounters the
BEGINCOMPILATION directive.
BEGINCOMPILATION on page 17-20
SRL on page 17-65
USEGLOBALS on page 17-69
You can export only whole data blocks. You cannot export individual variables declared
within a data block.
The compiler exports initialization values for variables that specify them. If a data block
is not being exported, the compiler ignores any specified initial values within the block.
You must export every data block in at least one compilation.
HP pTAL Reference Manual—523746-006
17 -34
Compiler Directives
FIELDALIGN
FIELDALIGN
FIELDALIGN specifies the default alignment for structures.
(
FIELDALIGN
SHARED2
)
SHARED8
PLATFORM
AUTO
NODEFAULT
VST660.vsd
SHARED2
specifies that the base of the structure and each field in the structure must begin at
an even-byte address except STRING fields. For more information, see SHARED2
on page 9-6.
SHARED8
specifies that the offset of each field in the structure from the base of the structure
must be begin at an address that is an integral multiple of the width of the field. For
more information, see SHARED8 on page 9-6.
AUTO
specifies that the structure and the fields of the structure be aligned according to
the optimal alignment for the architecture on which the program will run (this is not
the same behavior as the AUTO attribute has in the native mode HP C compiler).
For more information, see AUTO on page 9-7.
PLATFORM
specifies that the structure and the fields of the structure must begin at addresses
that are consistent across all languages on the same architecture. For more
information, see PLATFORM on page 9-7.
NODEFAULT
specifies that every structure declaration must include a FIELDALIGN Clause on
page 9-20.
Default:
FIELDALIGN AUTO
Placement:
•
•
Scope:
Applies to the compilation unit
Dependencies:
None
Can appear only once in a compilation unit
Must precede all declarations of data, blocks, and procedures
HP pTAL Reference Manual—523746-006
17 -35
Compiler Directives
FMAP
FMAP
FMAP
NOFMAP
VST141.vsd
FMAP
lists the file map in the compiler listing.
NOFMAP
suppresses the file map in the compiler listing.
Default:
NOFMAP
Placement:
Anywhere, any number of times. The last FMAP or NOFMAP in the
compilation unit determines whether the compiler lists the file map.
Scope:
Applies to the compilation unit
Dependencies:
FMAP has no effect if either NOLIST or SUPPRESS is active
References:
•
•
LIST on page 17-44
SUPPRESS on page 17-65
The file map:
•
•
•
Appears after the map of global identifiers in the compilation listing
Starts with the first file that the compiler encounters and includes each file
introduced by SOURCE directives and (on Guardian platforms) HP TACL ASSIGN
and DEFINE commands
Shows the complete name of each file and the date and time when the file was last
modified
GLOBALIZED
Note. This directive is valid only with the EpTAL compiler.
The GLOBALIZED directive directs the compiler to generate preemptable object code.
Preemptable object code allows named references in a DLL to resolve to externallydefined code and data items instead of to the DLL’s own internally-defined code and
data items. You must specify the GLOBALIZED directive when compiling code that will
be linked into a globalized DLL. By default, the compiler generates non-preemptable
object code. Non-preemptable code is more efficient than preemptable code and
HP pTAL Reference Manual—523746-006
17 -36
Compiler Directives
GMAP
results in faster compilation and execution, so you should specify GLOBALIZED only
when required.
GLOBALIZED
VST835.vsd
Default:
Generate non-preemptable object code
Placement:
On the command line
Scope:
Applies to the compilation unit
Dependencies:
None
GMAP
GMAP
NOGMAP
VST142.vsd
GMAP
lists the global map in the compiler listing.
NOGMAP
suppresses the global map in the compiler listing.
Default:
GMAP
Placement:
Anywhere, any number of times. The last GMAP or NOGMAP in the
compilation unit determines whether the compiler lists the global map.
Scope:
Applies to the compilation unit
Dependencies:
References:
•
•
•
•
•
GMAP has no effect if NOLIST, NOMAP, or SUPPRESS is active
NOGMAP suppresses the global map even if MAP is active
LIST on page 17-44
MAP on page 17-45
SUPPRESS on page 17-65
The global map:
•
•
Appears at the end of the compilation listing
Lists all identifiers in the compilation unit and tells what kind of objects they are,
including identifier class and type
HP pTAL Reference Manual—523746-006
17 -37
Compiler Directives
GP_OK
GP_OK
Note. The EpTAL compiler ignores these directives.
GP_OK
NOGP_OK
PUSHGP_OK
POPGP_OK
VST661.vsd
GP_OK
causes the pTAL compiler to generate code that has GP-relative addressing
(“small” data).
NOGP_OK
suppresses the generation of code that has GP-relative addressing. (This is the
only option for the EpTAL compiler.)
PUSHGP_OK
pushes the current setting (GP_OK or NOGP_OK) onto the GP_OK directive
stack. Does not change the current setting.
POPGP_OK
pops the top value from the GP_OK directive stack and changes the current setting
to that value.
For an explanation of directive stacks, see Directive Stacks on page 17-4.
Default:
Placement:
Scope:
pTAL compiler:
GP_OK
EpTAL compiler:
NOGP_OK
Anywhere except inside a data block or inside a procedure declaration
•
•
GP_OK applies to subsequent code it until it is overridden by
NOGP_OK
NOGP_OK applies to subsequent code until it is overridden by
GP_OK
Dependencies:
Do not use GP_OK with CALL_SHARED
References:
CALL_SHARED on page 17-22
A pTAL program that references data in a shared run-time library (SRL) must specify
NOGP_OK when it declares a data block that belongs to a shared run-time library. This
HP pTAL Reference Manual—523746-006
17 -38
Compiler Directives
IF and IFNOT
behavior prevents the pTAL compiler from using GP-relative addressing for references
to data in an SRL.
Example 17-20. GP_OK, NOGP_OK, PUSHGP_OK, and POPGP_OK Directive
?PUSHGP_OK
?NOGP_OK
?NOEXPORT_GLOBALS
BLOCK a_block;
...
END BLOCK;
?EXPORT_GLOBALS
?POPGP_OK
IF and IFNOT
IF and IFNOT identify the beginning of code that is to be conditionally compiled.
IF
toggle-name
IFNOT
toggle-number
target
pTAL
VST694.vsd
toggle-name
was specified by one of the following:
•
•
•
DEFINETOG on page 17-27
SETTOG on page 17-58
RESETTOG on page 17-54
IF compiles the conditional code only if toggle-name is on.
IFNOT compiles the conditional code only if toggle-name is off.
The EpTAL compiler allows toggle-name to be RISC1, _TNS_E_TARGET, or
TARGETSPECIFIED, as long as toggle-name does not change the value of
target in the IF, IFNOT, or ENDIF statement.
toggle-number
is an unsigned decimal constant in the range 1 through 15. Leading zeros are
ignored.
IF compiles the conditional code only if toggle-name is on.
HP pTAL Reference Manual—523746-006
17 -39
Compiler Directives
IF and IFNOT
IFNOT compiles the conditional code only if toggle-name is off.
target
ANY
RISC1
TNS_ARCH
TNSR_ARCH
_TNS_E_TARGET
TARGETSPECIFIED
VST695.vsd
Compiler
pTAL
EpTAL
Implicitly Sets
•
•
•
•
Implicitly Resets
RISC1
TARGETSPECIFIED
_TNS_E_TARGET
_TNS_E_TARGET
TARGETSPECIFIED
RISC1
ANY
tests for a TARGET ANY directive in the current compilation.
RISC1
tests for a TARGET RISC1 directive in the current compilation.
TNS_ARCH
tests for a TARGET TNS_ARCH directive in the current compilation.
TNS_R_ARCH
tests for a TARGET TNS_R_ARCH directive in the current compilation.
_TNS_E_TARGET
tests for a TARGET _TNS_E_TARGET directive in the current compilation.
TARGETSPECIFIED
tests for a TARGET directive in the current compilation.
HP pTAL Reference Manual—523746-006
17 -40
Compiler Directives
IF and IFNOT
pTAL
identifies the beginning of code that is to be compiled by the pTAL or EpTAL
compiler but not by the TAL compiler:
Compiler
IF pTAL
IFNOT pTAL
pTAL or EpTAL
True
False
TAL
False
True
Default:
Placement:
None
•
•
Anywhere in the source file (not in the compilation command)
Must be the last directive on the directive line
Scope:
Everything between IF or IFNOT and the next ENDIF that specifies the
same toggle, target, or keyword
Dependencies:
Interacts with:
•
•
•
•
•
ENDIF
DEFINETOG
SETTOG
RESETTOG
TARGET
See Toggles on page 17-5.
References:
•
•
•
•
•
DEFINETOG on page 17-27
ENDIF on page 17-29
RESETTOG on page 17-54
SETTOG on page 17-58
TARGET on page 17-68
Example 17-21. IF Directive Without Matching ENDIF Directive
?RESETTOG flag ! Create & turn off flag
?IF flag
! Statements for true condition
! (skipped because flag is off)
?IFNOT flag
! Statements for false condition
! (also skipped, because no ENDIF appears for IF flag)
?ENDIF flag
If you insert an ENDIF for the IF in the code in Example 17-21 on page 17-41, as in
Example 17-22 on page 17-42, the compiler skips only the first part.
HP pTAL Reference Manual—523746-006
17 -41
Compiler Directives
INNERLIST
Example 17-22. IF Directive With Matching ENDIF Directive
?RESETTOG flag ! Create & turn off flag
?IF flag
! Statements for true condition
! (skipped because flag is off)
?ENDIF flag
! ENDIF stops the skipping of statements
?IFNOT flag
! Statements for false condition
! (compiled because ENDIF appears for IF flag)
?ENDIF flag
An asterisk (*) appears in column 11 of the listing for any statements not compiled
because of the IF or IFNOT directive.
INNERLIST
INNERLIST
NOINNERLIST
PUSHINNERLIST
POPINNERLIST
VST149.vsd
INNERLIST
lists mnemonics for each statement after that statement in the compiler listing.
NOINNERLIST
suppresses the mnemonics for each statement after that statement in the compiler
listing.
PUSHINNERLIST
pushes the current setting (INNERLIST or NOINNERLIST) onto the INNERLIST
directive stack. Does not change the current setting.
POPINNERLIST
pops the top value from the INNERLIST directive stack and changes the current
setting to that value.
For an explanation of directive stacks, see Directive Stacks on page 17-4.
HP pTAL Reference Manual—523746-006
17 -42
Compiler Directives
INVALID_FOR_PTAL
Default:
NOINNERLIST
Placement:
Anywhere
Scope:
•
•
Dependencies:
References:
INNERLIST applies to subsequent statements it until it is overridden
by NOINNERLIST
NOINNERLIST applies to subsequent statements until it is
overridden by INNERLIST
INNERLIST has no effect if NOLIST or SUPPRESS is active
•
•
LIST on page 17-44
SUPPRESS on page 17-65
Example 17-23. INNERLIST and NOINNERLIST Directives
PROC any;
BEGIN
INT x, y, z; ! No innerlisting here
! Statements that initialize variables
?INNERLIST
! Start innerlisting here
! Statements that manipulate variables
?NOINNERLIST
! Stop innerlisting here
END;
INVALID_FOR_PTAL
INVALID_FOR_PTAL forces the compiler to report an error message. Use it to identify
a TAL source file that the pTAL or EpTAL compiler must not compile.
INVALID_FOR_PTAL
VST701.vsd
Default:
None
Placement:
After IF or IFNOT and before ENDIF
Scope:
Applies to code between itself and ENDIF
Dependencies:
None
References:
•
•
IF and IFNOT on page 17-39
ENDIF on page 17-29
HP pTAL Reference Manual—523746-006
17 -43
Compiler Directives
LINES
LINES
LINES sets the maximum number of output lines per page if the list file is a line printer
or a process.
num-lines
LINES
=
VST154.vsd
num-lines
is an unsigned decimal constant in the range 10 through 32,767.
Default:
LINES 60
Placement:
Anywhere
Scope:
Applies until overridden by another LINES directive
Dependencies:
Has no effect if the list file is a terminal
LIST
LIST
NOLIST
PUSHLIST
POPLIST
VST155.vsd
LIST
lists the source code in the compiler listing.
NOLIST
suppresses the source code the compiler listing.
PUSHLIST
pushes the current setting (LIST or NOLIST) onto the LIST directive stack. Does
not change the current setting.
POPLIST
pops the top value from the LIST directive stack and changes the current setting to
that value.
HP pTAL Reference Manual—523746-006
17 -44
Compiler Directives
MAP
For an explanation of directive stacks, see Directive Stacks on page 17-4.
Default:
LIST
Placement:
Anywhere
Scope:
•
•
Dependencies:
LIST has no effect if SUPPRESS is active
References:
SUPPRESS on page 17-65
LIST applies to subsequent code it until it is overridden by NOLIST
NOLIST applies to subsequent code until it is overridden by LIST
Each line in the source listing consists of:
•
•
•
An edit file number
A lexical level:
Lexical Level
Meaning
0
Global level
1
Procedure level
2
Subprocedure level
A nesting level (only for BEGIN-END items such as structures, substructures, IF
statements, and CASE statements)
Example 17-24. Listing Source Code But Not System Declarations
?NOLIST, SOURCE $SYSTEM.SYSTEM.EXTDECS (
? PROCESS_GETINFO_, PROCESS_STOP_)
?LIST
MAP
MAP
NOMAP
PUSHMAP
POPMAP
VST157.vsd
MAP
lists identifier maps in the compiler listing.
NOMAP
suppresses identifier maps in the compiler listing.
HP pTAL Reference Manual—523746-006
17 -45
Compiler Directives
MAP
PUSHMAP
pushes the current setting (MAP or NOMAP) onto the MAP directive stack. Does
not change the current setting.
POPMAP
pops the top value from the MAP directive stack and changes the current setting to
that value.
For an explanation of directive stacks, see Directive Stacks on page 17-4.
Default:
MAP
Placement:
Anywhere
Scope:
•
•
Dependencies:
MAP has no effect if NOLIST or SUPPRESS is active
References:
MAP applies to subsequent code it until it is overridden by NOMAP
NOMAP applies to subsequent code until it is overridden by MAP
•
•
LIST on page 17-44
SUPPRESS on page 17-65
MAP lists:
•
•
•
Sublocal identifiers after each subprocedure
Local identifiers after each procedure
Global identifiers after the last procedure in the source program
Each identifier map includes:
Item
Identifier class
Type
Addressing mode
Possible Values
•
•
•
•
•
•
•
•
•
•
•
•
VAR
SUBPROC
ENTRY
LABEL
DEFINE
LITERAL
Data type
Structure
Substructure
Structure pointer
Direct
Indirect
Subprocedure, entry, or label offset
Text of LITERALs and DEFINEs
HP pTAL Reference Manual—523746-006
17 -46
Compiler Directives
OPTIMIZE
OPTIMIZE
level
OPTIMIZE
=
VST665.vsd
level
Level
Effect
0
Code is not optimized. Provided in case other optimization levels cause
errors or interfere with debugging. Supports symbolic debugging; data is
always in memory.
1
Code is optimized within statements and across statement boundaries. The
resulting code is more efficient than that produced by lower levels of
optimization and does not interfere with debugging.
2
Code is optimized within statements and across statement boundaries, and
the resulting code is more efficient than code produced by lower levels.
Note. If your program compiles successfully at level 0 but runs out of memory at level 1 or
2, either compile your program only at level 0 or split your program into smaller
subprograms and compile those at the same higher level.
Default:
OPTIMIZE 1
Placement:
Outside the boundary of a separately compiled program
Scope:
The optimization level active at the beginning of a separately compiled
program determines the level of optimization for that program and any
programs it contains
Dependencies:
None, but OPTIMIZEFILE can override OPTIMIZE in individual
procedures
References:
OPTIMIZEFILE on page 17-47
OPTIMIZEFILE
OPTIMIZEFILE sets the optimization level for individual procedures and
subprocedures.
OPTIMIZEFILE
filename
VST666.vsd
HP pTAL Reference Manual—523746-006
17 -47
Compiler Directives
OPTIMIZEFILE
filename
is an EDIT file on Guardian platforms and a text file on Windows platforms. Each
line of the file must have this syntax:
routine-name
optimize-level
comment
#
blank line
VST064.vsd
(See Example 17-25 on page 17-48.)
routine-name
is either a:
•
•
procedure name
subprocedure name of the form
procedure-name.subprocedure-name
Each routine-name in filename must appear only once in filename.
optimize-level
is an integer. If it is not 0, 1, or 2, the compiler ignores the line. optimizelevel must be preceded by white space and it can be followed by white
space.
comment
is any text.
Default:
The optimization level that OPTIMIZE specified
Placement:
Only in the compilation command (not in the source file)
Scope:
Applies to the compilation unit
Dependencies:
None
References:
OPTIMIZE on page 17-47
Example 17-25. File for OPTIMIZEFILE Directive
# This is the optimizefile for compilation xyz.
abc.sub 0
abc 2
def 1
HP pTAL Reference Manual—523746-006
17 -48
Compiler Directives
OVERFLOW_TRAPS
Difference between pTAL and EpTAL compilers:
pTAL Compiler
EpTAL Compiler
Does not issue warnings for errors in
filename
Issues a warning when filename :
•
•
•
•
•
Does not exist
Cannot be opened
Is not an EDIT file (Guardian operating
systems only)
Has the same routine-name on more
than one line
Has a line that:
°
°
°
°
Exceeds 511 characters (Windows
operating systems only)
Has a routine-name that does
not match any routine declaration in
the source file
Has an optimize-level other
than 0, 1, or 2
Has one or more characters other
than spaces or tabs:
°
°
°
Before routine-name
After optimize-level
Between routine-name and
optimize-level
OVERFLOW_TRAPS
OVERFLOW_TRAPS
NOOVERFLOW_TRAPS
PUSHOVERFLOW_TRAPS
POPOVERFLOW_TRAPS
VST697.vsd
OVERFLOW_TRAPS
enables overflow traps throughout the program.
NOOVERFLOW_TRAPS
disables overflow traps throughout the program, except where you specify an
overflow trapping procedure attribute or block attribute.
HP pTAL Reference Manual—523746-006
17 -49
Compiler Directives
OVERFLOW_TRAPS
PUSHOVERFLOW_TRAPS
pushes the current setting (OVERFLOW_TRAPS or NOOVERFLOW_TRAPS)
onto the OVERFLOW_TRAPS directive stack. Does not change the current
setting.
POPOVERFLOW_TRAPS
pops the top value from the OVERFLOW_TRAPS directive stack and changes the
current setting to that value.
For an explanation of directive stacks, see Directive Stacks on page 17-4.
Default:
pTAL compiler:
OVERFLOW_TRAPS
EpTAL compiler:
NOOVERFLOW_TRAPS
Placement:
Before or between procedure declarations
Scope:
From where the directive it occurs in the compilation until the directive is
overridden or the compilation ends, whichever occurs first
Dependencies:
OVERFLOW_TRAPS is overridden by:
•
•
NOOVERFLOW_TRAPS procedure attribute
DISABLE_OVERFLOW_TRAPS block attributes
NOOVERFLOW_TRAPS is overridden by:
•
•
References:
OVERFLOW_TRAPS procedure attribute
ENABLE_OVERFLOW_TRAPS block attributes
See Managing Overflow Traps on page 13-1
Example 17-26. OVERFLOW_TRAPS Compiler Directive
?OVERFLOW_TRAPS
! Correct
PROC p;
BEGIN
?NOOVERFLOW_TRAPS
...
END;
! Incorrect: OVERFLOW_TRAPS must appear
! between procedure declarations
?NOOVERFLOW_TRAPS
! Correct
PROC q;
BEGIN
...
END;
HP pTAL Reference Manual—523746-006
17 -50
Compiler Directives
PAGE
PAGE
The first PAGE sets the string to be printed as part of the heading for each page. Each
subsequent PAGE prints the heading and causes a page eject.
PAGE
"
heading-string
"
VST160.vsd
heading-string
is a character string of at most 122 characters. The default is an empty string.
Default:
LINES determines page ejects and no heading is printed
Placement:
Only in the source file (not in the compilation command)
Scope:
Applies until overridden by another PAGE directive
Dependencies:
•
•
References:
•
•
•
•
•
Has no effect if either:
°
°
NOLIST or SUPPRESS is active
The list file is a terminal
Interacts with SAVEGLOBALS and USEGLOBALS (see Saving and
Using Global Data Declarations on page 17-8)
LINES on page 17-44
LIST on page 17-44
SAVEGLOBALS on page 17-56
SUPPRESS on page 17-65
USEGLOBALS on page 17-69
Example 17-27. PAGE Directive
! MYSOURCE file
?PAGE "Here are global declarations for MYSOURCE"
! Global declarations
?PAGE "Here are procedure declarations for MYSOURCE"
! Procedure declarations
HP pTAL Reference Manual—523746-006
17 -51
Compiler Directives
PRINTSYM
PRINTSYM
PRINTSYM
NOPRINTSYM
VST162.vsd
PRINTSYM
lists symbols in the compiler listing.
NOPRINTSYM
suppresses symbols in the compiler listing.
Default:
PRINTSYM
Placement:
Anywhere
Scope:
•
•
Dependencies:
References:
•
•
•
•
•
•
PRINTSYM applies to subsequent declarations until overridden by
NOPRINTSYM
NOPRINTSYM applies to subsequent declarations until overridden
by PRINTSYM
PRINTSYM has no effect if NOLIST or SUPPRESS is active
PRINTSYM interacts with SAVEGLOBALS and USEGLOBALS (see
Saving Global Data Declarations on page 17-9)
LIST on page 17-44
SAVEGLOBALS on page 17-56
SUPPRESS on page 17-65
USEGLOBALS on page 17-69
You can use PRINTSYM and NOPRINTSYM to list individual symbols or groups of
symbols, such as global, local, or sublocal declarations.
Example 17-28. PRINTSYM Directive
?NOPRINTSYM
INT i;
INT j;
?PRINTSYM
INT k;
! Turn off symbol listing
! Turn on symbol listing
HP pTAL Reference Manual—523746-006
17 -52
Compiler Directives
REFALIGNED
REFALIGNED
REFALIGNED
(
2
)
8
PUSHREFALIGNED
POPREFALIGNED
VST669.vsd
REFALIGNED
specifies the default alignment for pointers to nonstructure data items and
procedure reference parameters.
PUSHREFALIGNED
pushes the current setting [REFALIGNED (2) or REFALIGNED (8)] onto the
REFALIGNED directive stack. Does not change the current setting.
POPREFALIGNED
pops the top value from the REFALIGNED directive stack and changes the current
setting to that value.
For an explanation of directive stacks, see Directive Stacks on page 17-4.
Default:
REFALIGNED 8
Placement:
Anywhere
Scope:
Applies to subsequent pointers to nonstructure data items and
procedure reference parameters until overridden by another REFALIGN
directive
Dependencies:
None
HP pTAL Reference Manual—523746-006
17 -53
Compiler Directives
RESETTOG
RESETTOG
RESETTOG turns off either specified toggles or all numeric toggles.
RESETTOG
toggle-name
toggle-number
,
(
toggle-name
)
toggle-number
,
VST164.vsd
toggle-name
is an identifier.
toggle-number
is an unsigned decimal constant in the range 1 through 15. Leading zeros are
ignored.
The EpTAL compiler allows toggle-name to be RISC1, _TNS_E_TARGET, or
TARGETSPECIFIED, as long as toggle-name does not change the value of
target in the IF, IFNOT, or ENDIF statement (see IF and IFNOT on page 17-39
and ENDIF on page 17-29).
RESETTOG with no arguments turns off all numeric toggles but does not affect named
toggles.
HP pTAL Reference Manual—523746-006
17 -54
Compiler Directives
ROUND
Default:
None
•
•
Placement:
With a parenthesized list, it can appear anywhere
Without a parenthesized list, it must be the last directive on the
directive line or compilation command line
Scope:
Applies to the compilation unit
Dependencies:
Interacts with:
•
•
•
•
•
DEFINETOG
SETTOG
IF
IFNOT
ENDIF
See Toggles on page 17-5.
•
•
•
•
References:
DEFINETOG on page 17-27
ENDIF on page 17-29
IF and IFNOT on page 17-39
SETTOG on page 17-58
ROUND
ROUND rounds FIXED values assigned to FIXED variables that have smaller fpoint
values than the values you are assigning.
ROUND
NOROUND
VST165.vsd
ROUND
turns on rounding. If the fpoint of the assignment value is greater than that of
the variable, ROUND first truncates the assignment value so that its fpoint is
one greater than that of the destination variable. The truncated assignment value is
then rounded away from zero as follows:
value
= (IF value < 0 THEN value − 5 ELSE value + 5) / 10
In other words, if the truncated assignment value is negative, 5 is subtracted; if
positive, 5 is added. Then, an integer division by 10 is performed, and the result is
truncated again, this time by a factor of 10. Thus, if the absolute value of the least
significant digit of the initially truncated assignment value is 5 or more, a 1 is added
to the absolute value of the final least significant digit.
HP pTAL Reference Manual—523746-006
17 -55
Compiler Directives
SAVEGLOBALS
NOROUND
turns off rounding. That is, rounding does not occur when a FIXED value is
assigned to a FIXED variable that has a smaller fpoint. If the fpoint of the
assignment value is greater than that of the variable, the assignment value is
truncated and some precision is lost.
Default:
NOROUND
Placement:
Anywhere
Scope:
•
•
Dependencies:
None
ROUND applies to subsequent code until overridden by NOROUND
NOROUND applies to subsequent code until overridden by ROUND
Example 17-29. ROUND Directive
?ROUND
! Request rounding
! Global declarations
PROC a;
BEGIN
FIXED(2) f1;
FIXED(3) f2;
f1 := f2;
END;
SAVEGLOBALS
Note. The EpTAL compiler does not accept this directive. See Migrating from TNS/R to TNS/E
on page 17-11.
SAVEGLOBALS saves all global data declarations in a file for use in subsequent
compilations that specify the USEGLOBALS directive.
SAVEGLOBALS
file-name
define-name
VST670.vsd
file-name
is the name of a disk file to which the compiler is to write the global data
declarations.
If file-name already exists, the compiler purges the existing file and creates an
unstructured global declarations file.
HP pTAL Reference Manual—523746-006
17 -56
Compiler Directives
SECTION
If the existing file is secured so that the compiler cannot purge it, the compilation
terminates.
The compiler uses the current default volume and subvolume names as needed
and lists the complete file name in the trailer message at the end of compilation.
For this directive, the compiler does not use HP TACL ASSIGN SSV information
(available only on Guardian platforms) to complete the file name.
define-name
is the name of a MAP DEFINE that refers to the disk file to which you want the
compiler to write the global data declarations.
Note. MAP DEFINEs are available only on Guardian platforms.
Default:
None
Placement:
Either in the compilation command or in the source code before any
global data declarations
Scope:
Applies to the compilation unit
Dependencies:
•
•
•
References:
•
•
•
•
•
If SAVEGLOBALS and USEGLOBALS appear in the same
compilation unit, the compiler uses only the one that appears first
The compilation unit must have exactly one BEGINCOMPILATION
directive
Interacts with the directives referenced in the next row (see Saving
and Using Global Data Declarations on page 17-8)
BEGINCOMPILATION on page 17-20
PRINTSYM on page 17-52
SYMBOLS on page 17-66
SYNTAX on page 17-67
USEGLOBALS on page 17-69
SECTION
SECTION gives a name to a section of a source file for use in a SOURCE directive.
SECTION
section-name
VST171.vsd
section-name
is an identifier.
HP pTAL Reference Manual—523746-006
17 -57
Compiler Directives
Default:
SETTOG
None
Placement:
•
•
Only in the source file (not in the compilation command)
Must be the only directive on the directive line
Scope:
Applies to subsequent code until another SECTION directive or the end
of the file, whichever is first
Dependencies:
Interacts with SOURCE (see Section Names on page 17-61)
References:
SOURCE on page 17-60
Example 17-30. SECTION Directive
APPLLIB File
! File ID APPLLIB
?SECTION sort_proc
PROC sort_on_key(key1, key2, key3, length);
INT .key1, .key2, .key3, length;
BEGIN
...
END;
?SECTION next_proc
SOURCE directive that includes section sort_proc of the preceding file:
?SOURCE appllib (sort_proc)
SETTOG
SETTOG turns on either specified toggles or all numeric toggles.
SETTOG
toggle-name
toggle-number
,
(
toggle-name
)
toggle-number
,
VST172.vsd
HP pTAL Reference Manual—523746-006
17 -58
Compiler Directives
SETTOG
toggle-name
is an identifier.
The EpTAL compiler allows toggle-name to be RISC1, _TNS_E_TARGET, or
TARGETSPECIFIED, as long as toggle-name does not change the value of
target in the IF, IFNOT, or ENDIF statement (see IF and IFNOT on page 17-39
and ENDIF on page 17-29).
toggle-number
is an unsigned decimal constant in the range 1 through 15. Leading zeros are
ignored.
SETTOG with no arguments turns on all numeric toggles but does not affect named
toggles.
Default:
Placement:
None
•
•
With a parenthesized list, it can appear anywhere
Without a parenthesized list, it must be the last directive on the
directive line or compilation command line
Scope:
Applies to the compilation unit
Dependencies:
Interacts with:
•
•
•
•
•
DEFINETOG
RESETTOG
IF
IFNOT
ENDIF
See Toggles on page 17-5.
References:
•
•
•
•
DEFINETOG on page 17-27
ENDIF on page 17-29
IF and IFNOT on page 17-39
RESETTOG on page 17-54
HP pTAL Reference Manual—523746-006
17 -59
Compiler Directives
SOURCE
SOURCE
SOURCE reads source code from another source file.
SOURCE
file-name
define-name
assign-name
(
section-name
)
,
VST173.vsd
file-name
is the name of a disk file from which the compiler is to read source code. On
Guardian platforms, the compiler uses HP TACL ASSIGN SSV information, if
specified, to complete the file name; otherwise, the compiler uses the current
default volume and subvolume names as needed.
define-name
is the name of a MAP DEFINE that refers to a disk file from which the compiler is
to read source code.
Note. MAP DEFINEs are available only on Guardian platforms.
assign-name
is a logical file name you have equated to a disk file (from which the compiler is to
read source code) by issuing an ASSIGN command.
section-name
is an identifier specified within the included file by a SECTION directive. If the
compiler does not find section-name in the specified file, it issues a warning.
The list of section names can extend to continuation lines.
HP pTAL Reference Manual—523746-006
17 -60
Compiler Directives
Default:
Section Names
None
Placement:
•
•
Scope:
Applies to the source file
Dependencies:
References:
•
•
•
•
•
•
•
•
•
Only in the source file (not in the compilation command)
Must be the last directive on the directive line
Interacts with COLUMNS
Interacts with SECTION (see Section Names on page 17-61)
Interacts with the directives referenced in the next row (see Effect of
Other Directives on page 17-62)
BEGINCOMPILATION on page 17-20
COLUMNS on page 17-24
LIST on page 17-44
SECTION on page 17-57
SUPPRESS on page 17-65
USEGLOBALS on page 17-69
Topics:
•
•
•
•
•
Section Names on page 17-61
Nesting Levels on page 17-62
Effect of Other Directives on page 17-62
Including System Procedure Declarations on page 17-63
Examples on page 17-64
Section Names
If you specify SOURCE with no section names, the compiler processes the specified
source file until the end of that file. The compiler treats any SECTION directives in the
source file as comments.
If you specify SOURCE with section names, the compiler processes the source file
until it reads all the specified sections. A section begins with a SECTION directive and
ends with another SECTION directive or the end of the file, whichever comes first.
The compiler reads the sections in order of appearance in the source file, not in the
order specified in the SOURCE directive. If you want the compiler to read sections in a
particular order, use a separate SOURCE directive for each section and place the
SOURCE directives in the desired order.
HP pTAL Reference Manual—523746-006
17 -61
Compiler Directives
Nesting Levels
Nesting Levels
You can nest SOURCE directives to a maximum of seven levels, not counting the
original outermost source file. For example, the deepest nesting allowed is as follows:
1.
2.
3.
4.
5.
6.
7.
The MAIN file F sources in file F1.
File F1 sources in file F2.
File F2 sources in file F3.
File F3 sources in file F4.
File F4 sources in file F5.
File F5 sources in file F6.
File F6 sources in file F7.
Effect of Other Directives
•
•
•
•
COLUMNS on page 17-62
LIST and NOSUPPRESS on page 17-62
NOLIST on page 17-63
USEGLOBALS and BEGINCOMPILATION (pTAL Compiler Only) on page 17-63
COLUMNS
If a SOURCE directive specifies sections of a file, the compiler honors all COLUMNS
directives in that file that precede the first section of that file. (The first section of the file
might not be the first section of the file that the SOURCE directive specifies.) The
compiler also honors COLUMN directives that appear in the sections that the SOURCE
directive specifies.
After a SOURCE directive completes execution, the value of COLUMNS is restored to
what it was before the SOURCE directive:
File1:
?COLUMNS 80
...
File2:
?COLUMNS 100
...
?SOURCE file1
! COLUMNS is restored to 100 at this point
LIST and NOSUPPRESS
If LIST and NOSUPPRESS are active after a SOURCE directive completes execution,
the compiler prints a line identifying the source file to which it reverts and begins
reading at the line following the SOURCE directive.
HP pTAL Reference Manual—523746-006
17 -62
Compiler Directives
Including System Procedure Declarations
NOLIST
You can precede SOURCE with NOLIST to suppress the listings of procedures to be
read in. Place NOLIST and SOURCE on the same line, because the line containing
NOLIST is not suppressed:
?PUSHLIST, NOLIST, SOURCE $src.current.routines
! Suppress listings, read in external declarations of routines
?POPLIST
USEGLOBALS and BEGINCOMPILATION (pTAL Compiler
Only)
If USEGLOBALS is active, the compiler ignores all SOURCE directives until it
encounters BEGINCOMPILATION. For more information about how these directives
interact, see Saving and Using Global Data Declarations on page 17-8.
Including System Procedure Declarations
You can use SOURCE directives to read in external declarations of system procedures
from the EXTDECS files. In these files, the procedure name and the corresponding
section name are the same. EXTDECS0 contains the current RVU of system
procedures.
In Example 17-31 on page 17-63, a SOURCE directive specifies the current version of
system procedures. A NOLIST directive suppresses the listings for the system
procedures. Place NOLIST and SOURCE on the same line, because the line
containing the NOLIST directive is not suppressed.
Example 17-31. SOURCE Directive Specifying System Procedure Declarations
?PUSHLIST, NOLIST, SOURCE $SYSTEM.SYSTEM.EXTDECS0 (
?
PROCESS_DEBUG_, PROCESS_STOP_)
! Suppress listings
! Read external declarations of current system procedures
?POPLIST
A procedure in the same source file can then call the procedures listed in the
preceding SOURCE directive, as in Example 17-32 on page 17-64.
HP pTAL Reference Manual—523746-006
17 -63
Compiler Directives
Examples
Example 17-32. Procedure That Calls Procedures Specified by SOURCE
Directive
PROC a MAIN;
BEGIN
INT x, y, z, error;
! Code for manipulating x, y, and z
IF x = 5 THEN CALL PROCESS_STOP_;
CALL PROCESS_DEBUG_;
END;
! Call procedures listed
! in SOURCE directive
Examples
The SOURCE directive in Example 17-33 on page 17-64 instructs the compiler to
process the file until an end of file occurs. (Any SECTION directives in the file
ROUTINES are treated as comments.)
Example 17-33. SOURCE Directive
?SOURCE $src.current.routines
This SOURCE directive in Example 17-34 on page 17-64 reads three sections from the
source file. It reads the files in the order in which they appear in the source file, not in
the order specified in the SOURCE directive. (The specified files appear in the source
file in the order sec3, sec2, and sec1, so they are read in that order.)
Example 17-34. SOURCE Directive
?SOURCE $src.current.routines (sec1, sec2, sec3)
Example 17-35 on page 17-64 shows how you can specify the order in which the
compiler is to read the sections, regardless of their order in the source file.
Example 17-35. SOURCE Directive
?SOURCE $src.current.routines (sec1)
?SOURCE $src.current.routines (sec2)
?SOURCE $src.current.routines (sec3)
HP pTAL Reference Manual—523746-006
17 -64
Compiler Directives
SRL
SRL
Note. The EpTAL compiler ignores this directive.
SRL causes the pTAL compiler to generate code that can be linked into a user library.
You must specify SRL to be able to link the object file created by the compilation into a
user library.
SRL
VST671.vsd
Default:
None
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
When declaring a data block that belongs to an SRL, you must specify
NOEXPORT_GLOBALS and NOGP_OK.
•
•
References:
EXPORT_GLOBALS on page 17-33
GP_OK on page 17-38
SUPPRESS
SUPPRESS
NOSUPPRESS
VST176.vsd
SUPPRESS
suppresses all compilation listings except the compiler leader text, diagnostic
messages, and the trailer text. (Does not alter the source code.)
NOSUPPRESS
allows all compilation listings.
HP pTAL Reference Manual—523746-006
17 -65
Compiler Directives
SYMBOLS
Default:
NOSUPPRESS
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
Overrides all the listing directives (referenced in the next row)
References:
•
•
•
•
•
•
•
•
DEFEXPAND on page 17-26
FMAP on page 17-36
GMAP on page 17-37
INNERLIST on page 17-42
LIST on page 17-44
MAP on page 17-45
PAGE on page 17-51
PRINTSYM on page 17-52
The compilation command in Example 17-36 on page 17-66 starts the compilation and
suppresses all source code listings and maps from printing in the compiler output.
Example 17-36. SUPPRESS Directive
PTAL /IN mysrc, OUT $s.#lists/ myobj;
SYMBOLS
SYMBOLS saves symbols in a symbol table in the object file, enabling you use a
symbolic debugger to debug the object file.
SYMBOLS
NOSYMBOLS
VST672.vsd
SYMBOLS
saves all symbols information.
NOSYMBOLS
saves information about:
•
•
•
Procedure memos
Global data block names
Line numbers
Does not save information about parameters, local variables, data types, and so
on.
HP pTAL Reference Manual—523746-006
17 -66
Compiler Directives
SYNTAX
Default:
NOSYMBOLS
Placement:
Before the first declaration in the compilation
Scope:
The last legally placed SYMBOLS or NOSYMBOLS applies to the
compilation unit
Dependencies:
Interacts with SAVEGLOBALS and USEGLOBALS (see Saving Global
Data Declarations on page 17-9)
•
•
References:
SAVEGLOBALS on page 17-56
USEGLOBALS on page 17-69
Note. These linker options discard information that SYMBOLS saves:
•
•
-x discards line number information.
-s discards information needed for future linking (use it only in building an executable file).
Usually you save symbols for the entire compilation by specifying SYMBOLS once at
the beginning of the compilation unit. The symbol table then contains all the symbols
generated by the source code.
Example 17-37. SYMBOLS Directive
! MYSOURCE file
?SYMBOLS ! Save symbols for compilation unit
! Declare global data
! Declare procedures
After debugging the program, you can use the linker to create a new, smaller object file
without symbols. The executable portion of the old object file remains intact, but you
dramatically reduce what you can do with a symbolic debugger.
nld -x -r oldobj -o newobj
ld -x -r oldobj -o newobj
eld -x -r oldobj -o newobj
Use the linker option -s when linking a loadfile, or use the strip utility after creating
the loadfile.
STRIP oldobj
SYNTAX
SYNTAX checks the syntax of the source text without producing an object file.
SYNTAX
VST178.vsd
HP pTAL Reference Manual—523746-006
17 -67
Compiler Directives
TARGET
Default:
The compiler produces an object file
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
Interacts with SAVEGLOBALS and USEGLOBALS (see Saving Global
Data Declarations on page 17-9)
References:
•
•
SAVEGLOBALS on page 17-56
USEGLOBALS on page 17-69
The compilation command in Example 17-38 on page 17-68 checks the syntax of
global data declarations in source file myprog and saves the declarations in file
ptalsym for use in subsequent compilations.
Example 17-38. SYNTAX Directive
pTAL /IN myprog/; SAVEGLOBALS ptalsym, SYNTAX
The compilation command in Example 17-39 on page 17-68 checks for the syntax of
the code or data in source file myprog. In this compilation, USEGLOBALS retrieves
global data declarations saved in the compilation shown in Example 17-38 on
page 17-68.
Example 17-39. SYNTAX Directive
pTAL /IN myprog/; USEGLOBALS ptalsym, SYNTAX
TARGET
TARGET specifies the architecture on which you will run the object file produced by the
current compilation.
TARGET
TNS_R_ARCH
_TNS_E_TARGET
RISC1
TNS_ARCH
T16
LIBERTY
ANY
VST673.vsd
HP pTAL Reference Manual—523746-006
17 -68
Compiler Directives
USEGLOBALS
RISC1
specifies the TNS/R architecture. This is the only option that the pTAL compiler
accepts. It is also the default for the pTAL compiler.
_TNS_E_TARGET
specifies the TNS/E architecture. This is the only option that the EpTAL compiler
accepts. It is also the default for the EpTAL compiler.
TNS_ARCH
specifies the TNS architecture. The compiler does not accept this option.
T16
specifies the T16 architecture. The compiler does not accept this option.
TNS_R_ARCH
LIBERTY
specifies the Liberty architecture. The compiler does not accept this option.
ANY
specifies any architecture. The compiler does not accept this option.
Default:
pTAL compiler:
TNS_R_ARCH
EpTAL compiler:
_TNS_E_TARGET
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
None
USEGLOBALS
Note. The EpTAL compiler does not accept this directive. See Migrating from TNS/R to TNS/E
on page 17-11.
USEGLOBALS reads global data declarations and initializations that were saved in a
file by SAVEGLOBALS during a previous compilation.
USEGLOBALS
file-name
define-name
VST674.vsd
HP pTAL Reference Manual—523746-006
17 -69
Compiler Directives
USEGLOBALS
file-name
is the name of the global declarations disk file created by SAVEGLOBALS in a
previous compilation.
On Guardian platforms, the compiler uses HP TACL ASSIGN SSV information, if
specified, to complete the file name; otherwise, the compiler uses the current
default volume and subvolume names as needed.
define-name
is the name of a MAP DEFINE that refers to the global declarations file.
Note. MAP DEFINEs are available only on Guardian platforms.
assign-name
is a logical file name you have equated to a disk file (that refers to the global
declarations file) by issuing an ASSIGN command.
Default:
None
Placement:
Either in the compilation command or in the source code before any
global data declarations
Scope:
Applies to the compilation unit
Dependencies:
•
•
•
•
References:
•
•
•
•
•
•
The compilation unit must have exactly one BEGINCOMPILATION
directive.
The compiler exports the data blocks declared in the USEGLOBALS
declarations file only if EXPORT_GLOBALS is active when the
compiler encounters the BEGINCOMPILATION directive.
A module that specifies USEGLOBALS can export a global data
block that was declared in the compilation that specified
SAVEGLOBALS only if the SAVEGLOBALS compilation exported
the data block.
Typically, a project that uses SAVEGLOBALS explicitly links globals
into the object file and specifies NOEXPORT_GLOBALS (the
default) for all individual compilations.
Interacts with the directives referenced in the next row (see Saving
and Using Global Data Declarations on page 17-8)
BEGINCOMPILATION on page 17-20
EXPORT_GLOBALS on page 17-33
PRINTSYM on page 17-52
SAVEGLOBALS on page 17-56
SYMBOLS on page 17-66
SYNTAX on page 17-67
HP pTAL Reference Manual—523746-006
17 -70
Compiler Directives
WARN
WARN
WARN
warning-number
NOWARN
VST675.vsd
WARN
prints specific (or all) warning messages in the compiler listing.
NOWARN
suppresses specific (or all) warning messages in the compiler listing.
warning-number
is the number of a warning message. The default is all warning messages.
If warning-number is outside the range of all pTAL warnings and all TAL
warnings, the compiler issues a warning. If warning-number is inside either
range but not assigned warning text, the compiler ignores the WARN directive. For
an explanation of how the compiler handles TAL warnings, see the pTAL
Conversion Guide.
Default:
WARN
Placement:
Anywhere
Scope:
Dependencies:
•
•
WARN applies to subsequent code until overridden by NOWARN
NOWARN applies to subsequent code until overridden by WARN;
however: To print selected warnings, you must specify WARN before
any NOWARN directives. If you specify NOWARN first, subsequent
WARN warning-number directives have no effect.
None
You can use NOWARN when a compilation produces a warning and you have
determined that no real problem exists. Before the source line that produces the
warning, specify NOWARN and the number of the warning you want suppressed.
Following that source line, specify a WARN directive.
If NOWARN is active, the compiler records the number of suppressed and
unsuppressed warnings. The compilation statistics at the end of the compiler listing
include the following counts:
Number of unsuppressed compiler warnings = count
Number of warnings suppressed by NOWARN = count
HP pTAL Reference Manual—523746-006
17 -71
Compiler Directives
WARN
Unsuppressed compiler warnings are compiler warnings that are not suppressed by
NOWARN directives. The summary does not report the location of the last compiler
warning.
If no compiler errors and no unsuppressed compiler warnings occur, the completion
code is zero.
The following directive specifies that the compiler does not print warning message 12:
?NOWARN 12
HP pTAL Reference Manual—523746-006
17 -72
18
pTAL Cross Compiler
The optional pTAL cross compiler runs on the PC platforms in Table 18-1 on
page 18-1.
Table 18-1. pTAL Cross Compiler Platforms
Windows Operating
System
Platform
PC
Guardian
Cross Compiler Name
NT 4.0
2000
XP
ETK1
TNS/R
NonStop pTAL
Yes
Yes
Yes
TNS/E2
NonStop pTAL
No
Yes
Yes
TNS/R3
ptal
Yes
Yes
Yes
TNS/E2
eptal
No
Yes
Yes
PC command line
1. HP Enterprise Toolkit—NonStop Edition
2. H06.01 and later RVUs
3. G06.14 and later RVUs
On all Windows platforms, valid pTAL cross compiler source files must have the
extension .tal.
The pTAL cross compiler allows you to:
•
Write, compile, and link NonStop RISC-based or Itanium-based server applications
(NonStop Guardian executable files, static libraries, user libraries, and DLLs) on
the PC and transfer them to the Guardian platform for use in production.
Object files built on the PC platform are functionally identical object files built in the
NonStop RISC-based or Itanium-based server platform.
•
•
•
Link pTAL, C/C++, and NMCOBOL or ECOBOL objects into a single object file.
When multiple RVUs are installed, use any installed RVUs of the cross compilers
and libraries. (Tools must come from the same RVU—HP does not test the
interactions of tools used in one RVU with tools from other RVUs.)
On the ETK platform, enter ADD, MODIFY, SET, and DELETE statements into a
TACL DEFINE file (see TACL DEFINE Tool (ETK) on page 18-7).
The pTAL cross compiler is delivered on a separate CD and is not available on the site
update tape (SUT).
HP pTAL Reference Manual—523746-006
18- 1
pTAL Cross Compiler
NonStop pTAL (ETK)
Topics:
•
•
•
•
•
•
NonStop pTAL (ETK) on page 18-2
pTAL or EpTAL (PC Command Line) on page 18-3
Compilation and Linking on page 18-5
Debugging on page 18-6
Tools and Utilities on page 18-6
Documentation on page 18-8
NonStop pTAL (ETK)
The optional pTAL cross compiler for use with the ETK, NonStop pTAL, is available for
TNS/R and TNS/E.
The ETK is a GUI-based extension package to Visual Studio .NET that provides full
application development functions targeted for NonStop servers. Development, editing,
and building functions are very similar on Visual Studio .NET and the ETK.
NonStop pTAL components are:
File
Component Name
TNS/R
TNS/E
Driver executable
ptal.exe
eptal.exe
Driver DLL
ptaldvr.dll
(No driver)
Front end
ptalc.dll
eptalcom.exe
External declaration file
extdec.tal
eextdec.tal
The directory structure of NonStop pTAL is:
Files
Directory
TNS/R
TNS/E
bin
ptal.exe
nld.exe
ld.exe
eptal.exe
eld.exe
cmplr
ptaldvr.dll
ptalc.dll
uopt.dll
ugen.dll
as1.dll
nld.dll
ld.dll
eptalcom.exe
include
extdec.tal
extdec.tal
For PC and NonStop server hardware and software requirements, see the ETK online
help. For instructions for accessing the online help, see Documentation on page 18-8.
HP pTAL Reference Manual—523746-006
18- 2
pTAL Cross Compiler
pTAL or EpTAL (PC Command Line)
pTAL or EpTAL (PC Command Line)
Beginning with RVU G06.14, you can call the pTAL cross compiler from the TNS/R
command line (DOS prompt) on your PC by using the command ptal.
Beginning with RVU H06.01, you can call the pTAL cross compiler from the TNS/E
command line (DOS prompt) on your PC by using the command eptal.
Note. Before you can use eptal, you must set the COMP_ROOT environment variable so
that it points to the root of the directory location of the cross compiler. For instructions, see
Using the Command-Line Cross Compilers on Windows.
ptal
eptal
-o
object-file
-i
directory
sourcefile.tal
flag
ptal-directive
VST033.vsd
ptal
calls the pTAL cross compiler from the command line. ptal is not case-sensitive.
eptal
calls the EpTAL cross compiler from the command line. eptal is not casesensitive.
object-file
is the name of the object file to be created. The default is sourcefile.o.
directory
is the name of a directory for the compiler to search. If no directory is specified, the
compiler searches only in the current working directory. If any directories are
specified, the compiler searches them in the order in which they are listed, but
does not search the current directory unless it is explicitly named.
HP pTAL Reference Manual—523746-006
18- 3
pTAL Cross Compiler
pTAL or EpTAL (PC Command Line)
flag
is one of the following:
flag
Directs the compiler to:
-Whelp
Display information about how to run the compiler. No compilation
system components are run.
-Wusage
Display information about how to run the compiler. No compilation
system components are run.
-Wverbose
Displays the command line used when the driver calls each
component of the compiler.
ptal-directive
is one of the following:
Directives
Sources (page 1 of 2)
-blockglobals
BLOCKGLOBALS on page 17-21
-[no]call_shared
CALL_SHARED on page 17-22
-[no]checkshiftcount
CHECKSHIFTCOUNT on page 17-23
-codecov (eptal only)
CODECOV on page 17-24
-columns=n
COLUMNS on page 17-24
-[no]defexpand
DEFEXPAND on page 17-26
-[no]do_tns_syntax
DO_TNS_SYNTAX on page 17-28
-errors=n
ERRORS on page 17-33
-export_globals
EXPORT_GLOBALS on page 17-33
-fieldalign(value)
FIELDALIGN on page 17-35
-[no]fmap
FMAP on page 17-36
-globalized (eptal only)
GLOBALIZED on page 17-36
-[no]gmap
GMAP on page 17-37
-[no]gp_ok
GP_OK on page 17-38
-[no]innerlist
INNERLIST on page 17-42
-invalid_for_ptal
INVALID_FOR_PTAL on page 17-43
-[no]list
LIST on page 17-44
-[no]map
MAP on page 17-45
-optimize=n
OPTIMIZE on page 17-47
-[no]overflow_traps
OVERFLOW_TRAPS on page 17-49
-[no]printsym
PRINTSYM on page 17-52
-refaligned(n)
REFALIGNED on page 17-53
-resettog(value)
RESETTOG on page 17-54
HP pTAL Reference Manual—523746-006
18- 4
pTAL Cross Compiler
Compilation and Linking
Directives
Sources (page 2 of 2)
-[no]round
ROUND on page 17-55
-settog(value)
SETTOG on page 17-58
-[no]symbols
SYMBOLS on page 17-66
-[no]syntax
SYNTAX on page 17-67
-warn=n
WARN on page 17-71
The command-line interface allows you to create batch scripts for use on multiple
platforms.
Compilation and Linking
The pTAL cross compiler can compile only one pTAL source file at a time.
Difference between platforms:
ETK Platform (NonStop pTAL)
Command-Line Platform (ptal or eptal)
Compilation and linking can be performed in
one step.
Linking must be performed as a separate
step after compilation.
Provides a GUI-based interface for you to
select linker options.
You must specify the run-time libraries to the
linker.
pTAL cross compiler linking is performed with one of the cross linkers:
Cross Linker
Cross Compilers
Directive
Object Code
nld
NonStop pTAL
ptal
-nocall_shared*
Non-PIC
ld
NonStop pTAL
ptal
-call_shared**
PIC
eld
NonStop pTAL
eptal
-call_shared
PIC
* Default for pTAL. EpTAL ignores it (and issues a warning).
** Default for EpTAL.
Note. You cannot link PIC and non-PIC object files into a single object file.
For more information:
Topic
Source
nld options
nld Manual
ld options
ld Manual
eld options
eld Manual
HP pTAL Reference Manual—523746-006
18- 5
pTAL Cross Compiler
Debugging
Debugging
On the ETK platform, debug pTAL source code using Visual Inspect. After Visual
Inspect is installed on your workstation, you can configure Visual Inspect as an
external tool.
On the command-line platform, debug loadfiles that were compiled through the pTAL
cross compiler either by using Visual Inspect on Windows or by running Native Inspect
on the NonStop RISC-based or Itanium-based server. To use Native Inspect, you must
copy the loadfiles and the source files to the host (see PC-to-NonStop-Host Transfer
Tools on page 18-7).
For more information:
Topic
Source
Visual Inspect
Visual Inspect online help
Native Inspect
Native Inspect Manual
Tools and Utilities
The following tools and utilities allow you to use the pTAL cross compiler more
efficiently:
•
•
•
NonStop ar Utility on page 18-6
TACL DEFINE Tool (ETK) on page 18-7
PC-to-NonStop-Host Transfer Tools on page 18-7
NonStop ar Utility
The NonStop ar utility creates and maintains archives composed of groups of object
files. After an archive has been created, new files can be added and existing files can
be extracted, deleted, or replaced.
The ar utility accepts all OSS files, Guardian TNS code files, Guardian C text files (file
code 180 files), TNS/R (PIC and non-PIC) native object files, and TNS/E native linkfiles
or loadfiles as archive members.
You can mix one or more object file formats in one archive file; however, such an
archive file will not contain the symbols table and cannot be used by the linker.
HP pTAL Reference Manual—523746-006
18- 6
pTAL Cross Compiler
TACL DEFINE Tool (ETK)
If an archive contains one or more native object files of the same format, the linker can
use the archive as an object file library, replacing most functions provided by the
Binder SELECT SEARCH command.
If an archive contains one
or more ...
This cross linker can
use the archive as an
object file library ...
For more information, see ...
TNS/R non-PIC object files
nld on a G-Series system
nld Manual
TNS/R PIC object files
ld
ld Manual
TNS/E PIC object files
eld
eld Manual
TACL DEFINE Tool (ETK)
On the ETK platform, this GUI-based tool allows you to add ADD, MODIFY, SET, and
DELETE statements to a DEFINE file. The TACL DEFINE tool automatically sets the
first entry in the DEFINE obey file to be SET DEFMODE ON. You can leave this default
or change it to SET DEFMODE OFF. Files created by the TACL DEFINE tool have the
extension .tdf.
PC-to-NonStop-Host Transfer Tools
ETK
The Deploy command builds and copies each project in the active solution to the
NonStop host.
The Transfer Tool moves any kind of files to the NonStop host for execution and
debugging.
The Transfer Tool is better for transferring very large, complex applications to the
NonStop host. For most applications, Deploy is more convenient.
PC Command Line
From the PC command line, you can use any FTP application to transfer executable
and source files to the NonStop host.
HP pTAL Reference Manual—523746-006
18- 7
pTAL Cross Compiler
Documentation
Documentation
The ETK has online help that provides conceptual, reference, task-oriented, and error
message information, as well as quick-start tutorials. To access the online help, do
either of the following:
•
•
From the Help menu, select Contents, Index, or Search.
Click the Help button in any ETK dialog box.
The command-line documentation, Using the Command-Line Cross Compilers on
Windows, is available:
•
•
•
On the pTAL cross compiler CD
On the EpTAL cross compiler CD
In the ETK online help in the References chapter
Syntax information for pTAL and EpTAL is also available from the command-line:
ptal -Whelp
eptal -Whelp
HP pTAL Reference Manual—523746-006
18- 8
A
•
•
•
•
•
•
•
•
Syntax Summary
Data Types on page A-1
Constants on page A-1
Expressions on page A-4
Declarations on page A-7
Statements on page A-39
Overflow Traps on page A-46
Built-in Routines on page A-46
Compiler Directives on page A-87
Data Types
STRING
INT
REAL
(
width
)
UNSIGNED
(
width
)
(
fpoint
)
FIXED
*
VST214.vsd
More information: Specifying Data Types on page 3-3
Constants
•
•
•
•
•
•
•
Character String on page A-2
STRING Numeric on page A-2
INT Numeric on page A-2
INT(32) Numeric on page A-2
FIXED Numeric on page A-3
REAL and REAL(64) Numeric on page A-3
Constant List on page A-3
HP pTAL Reference Manual—523746-006
A- 1
Syntax Summary
Character String
Character String
"
"
string
VST001.vsd
More information: Character String on page 3-12
STRING Numeric
integer
base
VST002.vsd
More information: STRING Numeric on page 3-14
INT Numeric
integer
+
base
VST027.vsd
More information: INT Numeric on page 3-15
INT(32) Numeric
ns
D
integer
+
base
ns
%D
VST028.vsd
More information: INT(32) Numeric on page 3-16
HP pTAL Reference Manual—523746-006
A- 2
Syntax Summary
FIXED Numeric
FIXED Numeric
integer
+
base
-
F
fraction
.
%F
VST005.vsd
More information: FIXED Numeric on page 3-17
REAL and REAL(64) Numeric
integer
.
fraction
+
-
exponent
E
L
+
VST006.vsd
More information: REAL and REAL(64) Numeric on page 3-19
Constant List
repetition-constant-list
FIELDALIGN
(
SHARED2
)
SHARED8
[
repetition-constant-list
]
constant-list-seq
VST621.vsd
HP pTAL Reference Manual—523746-006
A- 3
Syntax Summary
Expressions
repetition-constant-list
[
repetition-factor
constant-list-seq
]
*
VST008.vsd
constant-list-seq
constant
repetition-constant-list
,
VST029.vsd
More information: Constant Lists on page 3-21
Expressions
•
•
•
•
•
•
•
•
Arithmetic on page A-4
Conditional on page A-5
Assignment on page A-5
CASE on page A-5
IF on page A-5
Group Comparison on page A-6
Bit Extraction on page A-6
Bit Shift on page A-6
Arithmetic
+
-
operand
arithmetic-operand
operand
VST010.vsd
More information: Arithmetic Expressions on page 5-5
HP pTAL Reference Manual—523746-006
A- 4
Syntax Summary
Conditional
Conditional
condition
NOT
AND
OR
VST996.vsd
More information: Conditional Expressions on page 5-15
Assignment
variable
expression
:=
VST012.vsd
More information: Assignment on page 5-20
CASE
selector
CASE
OF
expression
BEGIN
;
END
expression
OTHERWISE
;
VST013.vsd
More information: CASE on page 5-21
IF
IF
condition
THEN
expression
ELSE
expression
VST014.vsd
More information: IF on page 5-23
HP pTAL Reference Manual—523746-006
A- 5
Syntax Summary
Group Comparison
Group Comparison
var-1
relational-operator
FOR
var-2
count
count-unit
constant
constant
[
]
constant-list
next-addr
->
VST015.vsd
More information: Group Comparison on page 5-24
Bit Extraction
int-expression
.
ns
<
ns
ns
>
left-bit
ns
ns
:
ns
right-bit
VST016.vsd
More information: Bit Extractions on page 5-31
Bit Shift
int-expression
shift-operator
positions
dbl-expression
VST017.vsd
More information: Bit Shifts on page 5-33
HP pTAL Reference Manual—523746-006
A- 6
Syntax Summary
Declarations
Declarations
•
•
•
•
•
•
•
•
•
•
LITERAL on page A-7
DEFINE on page A-7
Simple Variable on page A-8
Array on page A-8
Read-Only Array on page A-9
Structures on page A-9
Redefinition on page A-16
Pointer on page A-21
Equivalenced Variable on page A-22
Procedure and Subprocedure on page A-28
LITERAL
LITERAL
identifier
constant
=
,
VST018.vsd
More information: Declaring Literals on page 6-1
DEFINE
DEFINE
item-list
;
,
VST019.vsd
item-list
=
identifier
define-body
#
param-list
VST995.vsd
HP pTAL Reference Manual—523746-006
A- 7
Syntax Summary
Simple Variable
param-list
)
param-name
(
,
VST994.vsd
More information: Declaring DEFINEs on page 6-3
Simple Variable
type
VOLATILE
identifier
;
initialization
:=
,
VST622.vsd
More information: Declaring Simple Variables on page 7-1
Array
type
identifier
;
range
:=
.
initialization
.EXT
.SG
.SGX
,
VST021.vsd
HP pTAL Reference Manual—523746-006
A- 8
Syntax Summary
Read-Only Array
range
[
lower-bound
upper-bound
:
]
VST993.vsd
More information: Declaring Arrays on page 8-2
Read-Only Array
type
identifier
=
range
'p'
initialization
:=
;
,
VST022.vsd
range
[
lower-bound
:
upper-bound
]
VST993.vsd
More information: Declaring Read-Only Arrays on page 8-6
Structures
•
•
•
•
•
•
•
•
•
•
Definition Structure on page A-10
Template Structure on page A-11
Referral Structure on page A-12
Simple Variables Declared in Structure on page A-12
Arrays Declared in Structure on page A-13
Definition Substructure on page A-13
Referral Substructure on page A-14
Filler in Structure on page A-14
Simple Pointers Declared in Structure on page A-15
Structure Pointers Declared in Structure on page A-16
HP pTAL Reference Manual—523746-006
A- 9
Syntax Summary
Structures
Definition Structure
identifier
STRUCT
.
.EXT
.SG
.SGX
structure-layout
range
;
field-alignment
VST624.vsd
range
[
lower-bound
:
upper-bound
]
VST993.vsd
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
More information: Declaring Definition Structures on page 9-33
HP pTAL Reference Manual—523746-006
A -10
Syntax Summary
Structures
Template Structure
STRUCT
STRUCTALIGN
identifier
(
(
MAXALIGN
structure-layout
*
)
)
;
field-alignment
VST625.vsd
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
More information: Declaring Template Structures on page 9-35
HP pTAL Reference Manual—523746-006
A -11
Syntax Summary
Structures
Referral Structure
identifier
STRUCT
referral
(
)
.
.EXT
.SG
.SGX
;
range
VST025.vsd
range
[
lower-bound
:
upper-bound
]
VST993.vsd
More information: Declaring Referral Structures on page 9-38
Simple Variables Declared in Structure
type
VOLATILE
identifier
;
,
VST705.vsd
More information: Declaring Simple Variables in Structures on page 9-40
HP pTAL Reference Manual—523746-006
A -12
Syntax Summary
Structures
Arrays Declared in Structure
type
identifier
range
;
,
VST201.vsd
range
lower-bound
[
:
upper-bound
]
VST993.vsd
More information: Declaring Arrays in Structures on page 9-40
Definition Substructure
identifier
STRUCT
structure-layout
;
range
field-alignment
VST626.vsd
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
range
[
lower-bound
:
upper-bound
]
VST993.vsd
More information: Definition Substructures on page 9-42
HP pTAL Reference Manual—523746-006
A -13
Syntax Summary
Structures
Referral Substructure
identifier
STRUCT
(
referral
)
;
range
VST203.vsd
range
[
lower-bound
:
upper-bound
]
VST993.vsd
More information: Referral Substructures on page 9-45
Filler in Structure
FILLER
constant-expression
;
BIT_FILLER
VST026.vsd
More information: Declaring Filler on page 9-46
HP pTAL Reference Manual—523746-006
A -14
Syntax Summary
Structures
Simple Pointers Declared in Structure
type
VOLATILE
identifier
.
.EXT
.SG
.SGX
;
REFALIGNED
(
2
)
8
,
VST627.vsd
More information: Declaring Simple Pointers in Structures on page 9-48
HP pTAL Reference Manual—523746-006
A -15
Syntax Summary
Redefinition
Structure Pointers Declared in Structure
STRING
VOLATILE
INT
identifier
referral
(
)
.
.EXT
.SG
.SGX
;
REFALIGNED
(
2
)
8
,
VST628.vsd
More information: Declaring Structure Pointers in Structures on page 9-51
Redefinition
•
•
•
•
•
•
Simple Variable on page A-17
Array on page A-17
Definition Substructure on page A-18
Referral Substructure on page A-19
Simple Pointer on page A-19
Structure Pointer on page A-20
HP pTAL Reference Manual—523746-006
A -16
Syntax Summary
Redefinition
Simple Variable
type
identifier
previous-identifier
=
VOLATILE
;
VST706.vsd
More information: Simple Variable on page 9-54
Array
type
identifier
=
previous-identifier
;
range
VST030.vsd
range
[
lower-bound
:
upper-bound
]
VST993.vsd
More information: Array on page 9-55
HP pTAL Reference Manual—523746-006
A -17
Syntax Summary
Redefinition
Definition Substructure
identifier
STRUCT
range
=
previous-identifier
;
field-alignment
structure-layout
;
VST707.vsd
range
[
lower-bound
:
upper-bound
]
VST993.vsd
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
More information: Definition Substructure on page 9-56
HP pTAL Reference Manual—523746-006
A -18
Syntax Summary
Redefinition
Referral Substructure
identifier
STRUCT
=
referral
(
previous-identifier
)
;
range
VST208.vsd
range
lower-bound
[
upper-bound
:
]
VST993.vsd
More information: Referral Substructure on page 9-59
Simple Pointer
type
identifier
VOLATILE
.
.EXT
.SG
.SGX
REFALIGNED
(
2
)
8
=
previous-identifier
;
VST708.vsd
More information: Simple Pointer on page 9-61
HP pTAL Reference Manual—523746-006
A -19
Syntax Summary
Redefinition
Structure Pointer
STRING
VOLATILE
identifier
.
INT
.EXT
.SG
.SGX
(
referral
REFALIGNED
)
(
2
)
8
=
previous-identifier
;
VST709.vsd
More information: Structure Pointer on page 9-63
HP pTAL Reference Manual—523746-006
A -20
Syntax Summary
Pointer
Pointer
•
•
•
Simple on page A-21
Structure on page A-22
System Global on page A-22
Simple
type
VOLATILE
identifier
.
.EXT
.SG
.SGX
REFALIGNED
2
(
)
8
;
:=
initialization
,
VST676.vsd
More information: Declaring Simple Pointers on page 10-12
HP pTAL Reference Manual—523746-006
A -21
Syntax Summary
Equivalenced Variable
Structure
STRING
VOLATILE
INT
identifier
referral
(
)
.
.EXT
.SG
.SGX
;
:=
initialization
,
VST677.vsd
More information: Declaring Structure Pointers on page 10-16
System Global
type
.SG
;
identifier
preset-address
:=
,
VST020.vsd
More information: Declaring System Global Pointers on page 10-20
Equivalenced Variable
•
•
•
•
•
Nonstructure on page A-23
Simple Variable on page A-24
Simple Pointer on page A-24
Definition Structure on page A-25
'SG'-Equivalenced Simple Variable on page A-26
HP pTAL Reference Manual—523746-006
A -22
Syntax Summary
•
•
•
•
Equivalenced Variable
'SG'-Equivalenced Definition Structure on page A-26
'SG'-Equivalenced Referral Structure on page A-27
'SG'-Equivalenced Simple Pointer on page A-27
'SG'-Equivalenced Structure Pointer on page A-28
Nonstructure
VOLATILE
type
identifier
=
referral
(
)
previous-identifier
;
[
index
+
offset
]
,
VST629.vsd
More information: Declaring Nonstructure Equivalenced Variables on page 11-5
HP pTAL Reference Manual—523746-006
A -23
Syntax Summary
Equivalenced Variable
Simple Variable
type
VOLATILE
identifier
=
referral
(
)
previous-identifier
;
[
index
+
offset
]
,
VST004.vsd
More information: Equivalenced Simple Variables on page 11-8
Simple Pointer
type
VOLATILE
identifier
referral
(
)
.
.EXT
=
previous-identifier
.SG
.SGX
;
[
index
+
offset
]
,
VST630.vsd
More information: Equivalenced Simple Pointers on page 11-10
HP pTAL Reference Manual—523746-006
A -24
Syntax Summary
Equivalenced Variable
Definition Structure
identifier
STRUCT
referral
(
)
.
.EXT
.SG
.SGX
previous-identifier
=
field-alignment
;
[
index
+
offset
]
structure-layout
VST632.vsd
-
field-alignment
FIELDALIGN
(
SHARED2
)
SHARED8
AUTO
PLATFORM
VST992.vsd
More information: Declaring Equivalenced Definition Structures on page 11-16
HP pTAL Reference Manual—523746-006
A -25
Syntax Summary
Equivalenced Variable
'SG'-Equivalenced Simple Variable
type
identifier
=
'SG'
;
[
index
+
offset
]
,
VST068.vsd
More information: Equivalenced Simple Variable on page 11-23
'SG'-Equivalenced Definition Structure
identifier
STRUCT
=
'SG'
.EXT
.SG
.SGX
;
[
index
+
offset
structure-layout
;
]
VST710.vsd
More information: Equivalenced Definition Structure on page 11-24
HP pTAL Reference Manual—523746-006
A -26
Syntax Summary
Equivalenced Variable
'SG'-Equivalenced Referral Structure
identifier
STRUCT
referral
(
)
.SG
.SGX
.EXT
=
;
'SG'
[
index
+
offset
]
VST703.vsd
More information: Equivalenced Referral Structure on page 11-25
'SG'-Equivalenced Simple Pointer
type
identifier
=
'SG'
.SG
.SGX
.EXT
;
[
index
+
offset
]
,
VST704.vsd
More information: Equivalenced Simple Pointer on page 11-27
HP pTAL Reference Manual—523746-006
A -27
Syntax Summary
Procedure and Subprocedure
'SG'-Equivalenced Structure Pointer
STRING
identifier
.
.SG
INT
.SGX
.EXT
(
referral
)
=
'SG'
;
[
index
+
offset
]
,
VST711.vsd
More information: Equivalenced Structure Pointer on page 11-28
Procedure and Subprocedure
•
•
•
•
•
•
Procedure on page A-29
Subprocedure on page A-31
Formal Parameters on page A-33
Entry Point on page A-35
Label on page A-35
Procedure Pointer on page A-36
HP pTAL Reference Manual—523746-006
A -28
Syntax Summary
Procedure and Subprocedure
Procedure
identifier
PROC
type
public-name-spec
;
proc-attribute
parameter-list
,
proc-body
;
param-spec
;
EXTERNAL
FORWARD
VST058.vsd
type
See Data Types on page A-1.
public-name-spec
=
public-name
"
"
VST209.vsd
parameter-list
(
)
param-name
param-pair
,
VST210.vsd
param-pair
string
:
length
VST039.vsd
HP pTAL Reference Manual—523746-006
A -29
Syntax Summary
Procedure and Subprocedure
proc-attribute
MAIN
INTERRUPT
RESIDENT
CALLABLE
PRIV
VARIABLE
EXTENSIBLE
(
count
)
RETURNSCC
OVERFLOW_TRAPS
NOOVERFLOW_TRAPS
LANGUAGE
C
COBOL
FORTRAN
PASCAL
UNSPECIFIED
VST635.vsd
Note.
•
•
The EpTAL compiler ignores INTERRUPT.
Because no FORTRAN or Pascal compilers exist especially for TNS/R or TNS/E
architecture, LANGUAGE FORTRAN and LANGUAGE PASCAL have no meaning on
TNS/R or TNS/E architecture.
More information: Procedure Attributes on page 14-5
param-spec
See Formal Parameters on page A-33.
HP pTAL Reference Manual—523746-006
A -30
Syntax Summary
Procedure and Subprocedure
proc-body
BEGIN
local-decl
subproc-decl
;
;
END
statement
VST061.vsd
More information: Procedure Declarations on page 14-2
Subprocedure
identifier
SUBPROC
type
parameter-list
;
VARIABLE
RETURNSCC
OVERFLOW_TRAPS
NOOVERFLOW_TRAPS
subproc-body
parameter-spec
;
;
FORWARD
VST702.vsd
type
See Data Types on page A-1.
parameter-list
(
param-name
)
param-pair
,
VST210.vsd
HP pTAL Reference Manual—523746-006
A -31
Syntax Summary
Procedure and Subprocedure
param-pair
string
:
length
VST039.vsd
param-spec
See Formal Parameters on page A-33.
subproc-body
BEGIN
END
sublocal-decl
statement
;
;
;
VST062.vsd
More information: Subprocedure Body on page 14-21
More information: Subprocedure Declarations on page 14-19
HP pTAL Reference Manual—523746-006
A -32
Syntax Summary
Procedure and Subprocedure
Formal Parameters
param-type
param-name
.
.EXT
.SG
.SGX
(
referral
)
;
REFALIGNED
(
2
)
8
,
VST636.vsd
HP pTAL Reference Manual—523746-006
A -33
Syntax Summary
Procedure and Subprocedure
param-type
STRING
INT
REAL
UNSIGNED
(
width
)
(
width
)
FIXED
(
fpoint
)
*
STRUCT
BADDR
WADDR
EXTADDR
PROCADDR
CBADDR
CWADDR
SGBADDR
SGWADDR
SGXBADDR
SGXWADDR
PROC
type
VST637.vsd
Note. The EpTAL compiler does not allow you to assign label or subprocedure addresses
to CBADDR and CWADDR address types.
HP pTAL Reference Manual—523746-006
A -34
Syntax Summary
Procedure and Subprocedure
type
STRING
INT
REAL
(
width
)
UNSIGNED
(
width
)
(
fpoint
)
FIXED
*
VST214.vsd
More information: Formal Parameter Specification on page 14-10
Entry Point
ENTRY
identifier
;
,
VST195.vsd
More information: Entry-Point Declarations on page 14-22
Label
LABEL
identifier
;
,
VST196.vsd
More information: Labels in Procedures on page 14-37
HP pTAL Reference Manual—523746-006
A -35
Syntax Summary
Procedure and Subprocedure
Procedure Pointer
procptr-name
PROCPTR
return-type
attributes
formal-param-names
formal-param-spec
;
END
PROCPTR
VST600.vsd
formal-param-names
(
)
param-name
param-pair
,
VST210.vsd
param-pair
string
:
length
VST039.vsd
HP pTAL Reference Manual—523746-006
A -36
Syntax Summary
Procedure and Subprocedure
attributes
MAIN
INTERRUPT
RESIDENT
CALLABLE
PRIV
VARIABLE
EXTENSIBLE
(
count
)
RETURNSCC
OVERFLOW_TRAPS
NOOVERFLOW_TRAPS
LANGUAGE
C
COBOL
FORTRAN
PASCAL
UNSPECIFIED
VST635.vsd
Note.
•
•
The EpTAL compiler ignores INTERRUPT.
Because no FORTRAN or Pascal compilers exist especially for TNS/R or TNS/E
architecture, LANGUAGE FORTRAN and LANGUAGE PASCAL have no meaning on
TNS/R or TNS/E architecture.
HP pTAL Reference Manual—523746-006
A -37
Syntax Summary
Procedure and Subprocedure
formal-param-spec
procptr
param-type
identifier
.
.EXT
.SG
.SGX
(
referral
)
,
VST712.vsd
More information: Procedure Pointers on page 14-26
HP pTAL Reference Manual—523746-006
A -38
Syntax Summary
Statements
Statements
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Compound on page A-39
ASSERT on page A-40
Assignment on page A-40
Bit Deposit Assignment on page A-40
CALL on page A-41
Labeled CASE on page A-41
Unlabeled CASE on page A-42
DO-UNTIL on page A-42
DROP on page A-42
FOR on page A-43
GOTO on page A-43
IF on page A-43
Move on page A-44
RETURN on page A-44
SCAN and RSCAN on page A-45
USE on page A-45
WHILE on page A-45
Compound
BEGIN
END
statement
;
;
VST034.vsd
More information: Compound Statements on page 12-2
HP pTAL Reference Manual—523746-006
A -39
Syntax Summary
ASSERT
ASSERT
assert-level
ASSERT
condition
:
VST035.vsd
More information: ASSERT on page 12-3
Assignment
The assignment statement assigns a value to a previously declared variable.
variable
expression
:=
VST012.vsd
More information: Assignment on page 12-4
Bit Deposit Assignment
variable
ns
ns
.
<
ns
>
left-bit
ns
:
:=
ns
right-bit
ns
expression
VST037.vsd
More information: Bit-Deposit Assignment on page 12-9
HP pTAL Reference Manual—523746-006
A -40
Syntax Summary
CALL
CALL
identifier
(
CALL
)
param-name
param-pair
,
VST038.vsd
param-pair
string
length
:
VST039.vsd
More information: CALL on page 12-10
Labeled CASE
selector
CASE
OF
BEGIN
case-alternative
;
END
->
OTHERWISE
;
statement-2
VST041.vsd
case-alternative
case-label
lower-case-label
->
..
upper-case-label
,
statement-1
;
VST042.vsd
More information: Labeled CASE on page 12-13
HP pTAL Reference Manual—523746-006
A -41
Syntax Summary
Unlabeled CASE
Unlabeled CASE
CASE
selector
OF
BEGIN
;
statement
END
OTHERWISE
;
statement
VST040.vsd
More information: Unlabeled CASE on page 12-15
DO-UNTIL
DO
UNTIL
condition
statement
VST046.vsd
More information: DO-UNTIL on page 12-17
DROP
DROP
identifier
,
VST047.vsd
More information: DROP on page 12-19
HP pTAL Reference Manual—523746-006
A -42
Syntax Summary
FOR
FOR
FOR
index
TO
initial-value
:=
limit
DOWNTO
DO
BY
statement
step
VST048.vsd
More information: FOR on page 12-20
GOTO
GOTO
label-name
VST049.vsd
Note. Nonlocal GOTO statements are are inefficient and not recommended.
More information: GOTO on page 12-23
IF
IF
condition
THEN
statement
ELSE
statement
VST050.vsd
More information: IF on page 12-26
HP pTAL Reference Manual—523746-006
A -43
Syntax Summary
Move
Move
:=
destination
=:
&
source
count
FOR
count-unit
constant
[
constant
]
constant-list
->
next-addr
VST051.vsd
More information: Move on page 12-28
RETURN
Note. The EpTAL compiler issues a warning whenever a pTAL procedure returns both a
result-expression and a cc-expression and has the procedure attribute
RETURNSCC on page 14-8. The reason for this warning is in Appendix D, RETURN,
RETURNSCC, and C/C++ on TNS/E.
RETURN
cc-expression
result-expression
,
cc-expression
VST052.vsd
More information: RETURN on page 12-34
HP pTAL Reference Manual—523746-006
A -44
Syntax Summary
SCAN and RSCAN
SCAN and RSCAN
test-char
WHILE
variable
SCAN
UNTIL
RSCAN
next-addr
->
VST053.vsd
More information: SCAN and RSCAN on page 12-40
USE
USE
identifier
,
VST056.vsd
More information: USE on page 12-45
WHILE
WHILE
condition
DO
statement
VST057.vsd
More information: WHILE on page 12-45
HP pTAL Reference Manual—523746-006
A -45
Syntax Summary
Overflow Traps
Overflow Traps
OVERFLOW_TRAPS Directive
See OVERFLOW_TRAPS on page A-107.
[EN|DIS]ABLE_OVERFLOW_TRAPS Block Attribute
BEGIN
:
ENABLE_OVERFLOW_TRAPS
DISABLE_OVERFLOW_TRAPS
VST682.vsd
More information: [EN|DIS]ABLE_OVERFLOW_TRAPS Block Attribute on page 13-2
Built-in Routines
•
•
Atomic on page A-46
Nonatomic on page A-49
Atomic
•
•
•
•
•
•
$ATOMIC_ADD on page A-47
$ATOMIC_AND on page A-47
$ATOMIC_DEP on page A-47
$ATOMIC_GET on page A-48
$ATOMIC_OR on page A-48
$ATOMIC_PUT on page A-48
HP pTAL Reference Manual—523746-006
A -46
Syntax Summary
Atomic
$ATOMIC_ADD
$ATOMIC_ADD
(
var
value
,
)
;
VST607.vsd
Sets condition code
Yes (according the final value of var )
Sets $CARRY
Yes, if traps are disabled
Sets $OVERFLOW
Yes, if traps are disabled; otherwise, traps on overflow
More information: $ATOMIC_ADD on page 15-5
$ATOMIC_AND
$ATOMIC_AND
(
var
,
mask
)
;
VST608.vsd
Sets condition code
Yes (according the final value of var )
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $ATOMIC_AND on page 15-6
$ATOMIC_DEP
$ATOMIC_DEP
value
)
(
var
,
mask
,
;
VST609.vsd
Sets condition code
Yes (according the final value of var )
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $ATOMIC_DEP on page 15-7
HP pTAL Reference Manual—523746-006
A -47
Syntax Summary
Atomic
$ATOMIC_GET
$ATOMIC_GET
(
var
)
;
VST610.vsd
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $ATOMIC_GET on page 15-8
$ATOMIC_OR
$ATOMIC_OR
(
var
,
mask
)
;
VST611.vsd
Sets condition code
Yes (according the final value of var )
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $ATOMIC_OR on page 15-9
$ATOMIC_PUT
$ATOMIC_PUT
(
var
,
value
)
;
VST612.vsd
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $ATOMIC_PUT on page 15-10
HP pTAL Reference Manual—523746-006
A -48
Syntax Summary
Nonatomic
Nonatomic
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
$ABS on page A-52
$ALPHA on page A-52
$ASCIITOFIXED on page A-53
$AXADR on page A-53
$BADDR_TO_EXTADDR on page A-54
$BADDR_TO_WADDR on page A-54
$BITLENGTH on page A-54
$BITOFFSET on page A-55
$CARRY on page A-55
$CHECKSUM on page A-56
$COMP on page A-56
$COUNTDUPS on page A-57
$DBL on page A-57
$DBLL on page A-58
$DBLR on page A-58
$DFIX on page A-58
$EFLT on page A-59
$EFLTR on page A-59
$EXCHANGE on page A-59
$EXECUTEIO on page A-60
$EXTADDR_TO_BADDR on page A-60
$EXTADDR_TO_WADDR on page A-61
$FILL8, $FILL16, and $FILL32 on page A-61
$FIX on page A-62
$FIXD on page A-62
$FIXEDTOASCII on page A-63
$FIXEDTOASCIIRESIDUE on page A-63
$FIXI on page A-64
$FIXL on page A-64
HP pTAL Reference Manual—523746-006
A -49
Syntax Summary
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Nonatomic
$FIXR on page A-64
$FLT on page A-65
$FLTR on page A-65
$FREEZE on page A-66
$HALT on page A-66
$HIGH on page A-67
$IFIX on page A-67
$INT on page A-67
$INT_OV on page A-68
$INTERROGATEHIO on page A-68
$INTERROGATEIO on page A-69
$INTR on page A-69
$LEN on page A-70
$LFIX on page A-70
$LMAX on page A-70
$LMIN on page A-71
$LOCATESPTHDR on page A-71
$LOCKPAGE on page A-72
$MAX on page A-72
$MIN on page A-73
$MOVEANDCXSUMBYTES on page A-73
$MOVENONDUP on page A-74
$NUMERIC on page A-74
$OCCURS on page A-75
$OFFSET on page A-75
$OPTIONAL on page A-76
$OVERFLOW on page A-76
$PARAM on page A-77
$POINT on page A-77
$PROCADDR on page A-77
HP pTAL Reference Manual—523746-006
A -50
Syntax Summary
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Nonatomic
$READBASELIMIT on page A-78
$READCLOCK on page A-78
$READSPT on page A-79
$READTIME on page A-79
$SCALE on page A-80
$SGBADDR_TO_EXTADDR on page A-80
$SGBADDR_TO_SGWADDR on page A-80
$SGWADDR_TO_EXTADDR on page A-81
$SGWADDR_TO_SGBADDR on page A-81
$SPECIAL on page A-81
$STACK_ALLOCATE on page A-82
$TRIGGER on page A-82
$TYPE on page A-83
$UDBL on page A-83
$UDIVREM16 on page A-84
$UDIVREM32 on page A-84
$UNLOCKPAGE on page A-85
$WADDR_TO_BADDR on page A-85
$WADDR_TO_EXTADDR on page A-86
$WRITEPTE on page A-86
$XADR on page A-87
HP pTAL Reference Manual—523746-006
A -51
Syntax Summary
Nonatomic
$ABS
$ABS
expression
(
)
VST072.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $ABS on page 15-22
$ALPHA
$ALPHA
(
int-expression
)
VST073.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $ALPHA on page 15-23
HP pTAL Reference Manual—523746-006
A -52
Syntax Summary
Nonatomic
$ASCIITOFIXED
$ASCIITOFIXED
(
remainingdigits
,
bufferaddr
qvalueout
,
qvaluein
,
maxdigits
)
;
VST606.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
Yes
More information: $ASCIITOFIXED on page 15-24
$AXADR
Note. The EpTAL compiler does not support this routine. (The EpTAL compiler does allow
$AXADR as a DEFINE name.)
$AXADR
(
variable
)
VST116.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $AXADR on page 15-26
HP pTAL Reference Manual—523746-006
A -53
Syntax Summary
Nonatomic
$BADDR_TO_EXTADDR
$BADDR_TO_EXTADDR
(
expression
)
VST683.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $BADDR_TO_EXTADDR on page 15-26
$BADDR_TO_WADDR
$BADDR_TO_WADDR
(
expression
)
VST684.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $BADDR_TO_WADDR on page 15-27
$BITLENGTH
$BITLENGTH
(
variable
)
VST074.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $BITLENGTH on page 15-28
HP pTAL Reference Manual—523746-006
A -54
Syntax Summary
Nonatomic
$BITOFFSET
$BITOFFSET
(
variable
)
VST075.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $BITOFFSET on page 15-29
$CARRY
$CARRY
VST076.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $CARRY on page 15-30
HP pTAL Reference Manual—523746-006
A -55
Syntax Summary
Nonatomic
$CHECKSUM
$CHECKSUM
wordcount
checksum
(
)
,
bufferaddr
,
;
VST613.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $CHECKSUM on page 15-31
$COMP
$COMP
(
int-expression
)
VST077.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $COMP on page 15-32
HP pTAL Reference Manual—523746-006
A -56
Syntax Summary
Nonatomic
$COUNTDUPS
$COUNTDUPS
)
duplicationcount
,
scraddr
(
maxwords
,
;
VST614.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $COUNTDUPS on page 15-33
$DBL
$DBL
expression
(
)
VST078.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $DBL on page 15-34
HP pTAL Reference Manual—523746-006
A -57
Syntax Summary
Nonatomic
$DBLL
$DBLL
expression
(
)
VST079.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $DBLL on page 15-35
$DBLR
$DBLR
expression
(
)
VST080.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $DBLR on page 15-36
$DFIX
$DFIX
(
int-expression
fpoint
,
)
VST081.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $DFIX on page 15-36
HP pTAL Reference Manual—523746-006
A -58
Syntax Summary
Nonatomic
$EFLT
$EFLT
expression
(
)
VST082.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $EFLT on page 15-37
$EFLTR
$EFLTR
expression
(
)
VST083.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $EFLTR on page 15-38
$EXCHANGE
$EXCHANGE
(
var1
,
var2
)
;
VST615.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $EXCHANGE on page 15-39
HP pTAL Reference Manual—523746-006
A -59
Syntax Summary
Nonatomic
$EXECUTEIO
Note. The EpTAL compiler does not support this routine.
$EXECUTEIO
lacsubcommand
channel-status
channel
(
rdstdevstatus
,
)
lprmcommand
,
,
,
;
VST616.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $EXECUTEIO on page 15-40
$EXTADDR_TO_BADDR
$EXTADDR_TO_BADDR
(
expression
)
VST686.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $EXTADDR_TO_BADDR on page 15-41
HP pTAL Reference Manual—523746-006
A -60
Syntax Summary
Nonatomic
$EXTADDR_TO_WADDR
$EXTADDR_TO_WADDR
expression
(
)
VST687.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $EXTADDR_TO_WADDR on page 15-42
$FILL8, $FILL16, and $FILL32
$FILL8
CALL
$FILL16
$FILL32
(
area-to-fill
,
repetitions
,
value
)
VST688.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $FILL8, $FILL16, and $FILL32 on page 15-42
HP pTAL Reference Manual—523746-006
A -61
Syntax Summary
Nonatomic
$FIX
$FIX
expression
(
)
VST084.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $FIX on page 15-44
$FIXD
$FIXD
expression
(
)
VST085.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $FIXD on page 15-44
HP pTAL Reference Manual—523746-006
A -62
Syntax Summary
Nonatomic
$FIXEDTOASCII
$FIXEDTOASCII
maxdigits
(
)
,
qvalue
,
bufferaddr
;
VST617.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
More information: $FIXEDTOASCII on page 15-45
$FIXEDTOASCIIRESIDUE
$FIXEDTOASCIIRESIDUE
,
maxdigits
,
(
,
qvalue
qresidue
)
bufferaddr
;
VST618.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
More information: $FIXEDTOASCIIRESIDUE on page 15-46
HP pTAL Reference Manual—523746-006
A -63
Syntax Summary
Nonatomic
$FIXI
$FIXI
fixed-expression
(
)
VST086.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $FIXI on page 15-47
$FIXL
$FIXL
fixed-expression
(
)
VST087.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $FIXL on page 15-48
$FIXR
$FIXR
expression
(
)
VST088.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $FIXR on page 15-48
HP pTAL Reference Manual—523746-006
A -64
Syntax Summary
Nonatomic
$FLT
$FLT
expression
(
)
VST089.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $FLT on page 15-49
$FLTR
$FLTR
expression
(
)
VST090.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $FLTR on page 15-50
HP pTAL Reference Manual—523746-006
A -65
Syntax Summary
Nonatomic
$FREEZE
Note.
•
•
The EpTAL compiler does not support this procedure. Use $TRIGGER on page 15-88
instead. (The EpTAL compiler does allow $FREEZE as a DEFINE name.)
Execution does not return from this call.
$FREEZE
VST619.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $FREEZE on page 15-51
$HALT
Note.
•
•
The EpTAL compiler does not support this procedure. Use $TRIGGER on page 15-88
instead. (The EpTAL compiler does allow $HALT as a DEFINE name.)
Execution does not return from this call.
$HALT
VST620.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $HALT on page 15-51
HP pTAL Reference Manual—523746-006
A -66
Syntax Summary
Nonatomic
$HIGH
(
$HIGH
dbl-expression
)
VST091.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $HIGH on page 15-52
$IFIX
(
$IFIX
int-expression
fpoint
,
)
VST092.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $IFIX on page 15-52
$INT
$INT
expression
(
)
VST093.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $INT on page 15-53
HP pTAL Reference Manual—523746-006
A -67
Syntax Summary
Nonatomic
$INT_OV
Note. $INT_OV is supported in the D40 and later RVUs.
$INT_OV
expression
(
)
VST689.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes
More information: $INT_OV on page 15-54
$INTERROGATEHIO
Note. The EpTAL compiler does not support this routine.
$INTERROGATEHIO
,
)
ric-int-cause
(
,
select
rank-channel
,
ric-int-cause
,
channel-status
;
VST643.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $INTERROGATEHIO on page 15-55
HP pTAL Reference Manual—523746-006
A -68
Syntax Summary
Nonatomic
$INTERROGATEIO
Note. The EpTAL compiler does not support this routine.
$INTERROGATEIO
ric-int-cause
,
)
(
,
rank-channel
,
select
ric-int-cause
,
channel-status
;
VST644.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $INTERROGATEIO on page 15-57
$INTR
$INTR
expression
(
)
VST094.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $INTR on page 15-58
HP pTAL Reference Manual—523746-006
A -69
Syntax Summary
Nonatomic
$LEN
$LEN
variable
(
)
VST096.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $LEN on page 15-59
$LFIX
$LFIX
int-expression
(
fpoint
,
)
VST097.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $LFIX on page 15-60
$LMAX
$LMAX
(
int-expression
int-expression
,
)
VST098.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $LMAX on page 15-61
HP pTAL Reference Manual—523746-006
A -70
Syntax Summary
Nonatomic
$LMIN
int-expression
(
$LMIN
int-expression
,
)
VST099.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $LMIN on page 15-61
$LOCATESPTHDR
Note. The EpTAL compiler does not support this routine.
$LOCATESPTHDR
sptbase
)
(
headersize
,
virtaddr
,
;
VST645.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
Yes
Sets $OVERFLOW
No
More information: $LOCATESPTHDR on page 15-62
HP pTAL Reference Manual—523746-006
A -71
Syntax Summary
Nonatomic
$LOCKPAGE
Note. The EpTAL compiler does not support this routine.
(
$LOCKPAGE
virtaddr
)
only-if-locked
,
lock-count
,
;
VST646.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
Yes
Sets $OVERFLOW
No
More information: $LOCKPAGE on page 15-63
$MAX
$MAX
expression
(
,
expression
)
VST100.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $MAX on page 15-64
HP pTAL Reference Manual—523746-006
A -72
Syntax Summary
Nonatomic
$MIN
$MIN
expression
(
expression
,
)
VST101.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $MIN on page 15-64
$MOVEANDCXSUMBYTES
$MOVEANDCXSUMBYTES
destaddr
srcaddr
,
(
checksum
,
count
,
)
;
VST647.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $MOVEANDCXSUMBYTES on page 15-65
HP pTAL Reference Manual—523746-006
A -73
Syntax Summary
Nonatomic
$MOVENONDUP
$MOVENONDUP
maxwords
(
lastword
,
destaddr
,
)
;
srcaddr
,
VST648.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $MOVENONDUP on page 15-67
$NUMERIC
$NUMERIC
(
int-expression
)
;
VST102.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $NUMERIC on page 15-68
HP pTAL Reference Manual—523746-006
A -74
Syntax Summary
Nonatomic
$OCCURS
$OCCURS
(
variable
)
VST103.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $OCCURS on page 15-69
$OFFSET
$OFFSET
(
variable
)
VST104.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $OFFSET on page 15-71
HP pTAL Reference Manual—523746-006
A -75
Syntax Summary
Nonatomic
$OPTIONAL
$OPTIONAL
cond-expression
(
,
param
)
param-pair
VST213.vsd
param-pair
string
:
length
VST039.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $OPTIONAL on page 15-73
$OVERFLOW
$OVERFLOW
VST105.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $OVERFLOW on page 15-76
HP pTAL Reference Manual—523746-006
A -76
Syntax Summary
Nonatomic
$PARAM
$PARAM
formal-param
(
)
VST106.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $PARAM on page 15-77
$POINT
$POINT
fixed-expression
(
)
VST107.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $POINT on page 15-78
$PROCADDR
$PROCADDR
(
identifier
)
VST031.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $PROCADDR on page 15-78
HP pTAL Reference Manual—523746-006
A -77
Syntax Summary
Nonatomic
$READBASELIMIT
Note. The EpTAL compiler does not support this procedure.
$READBASELIMIT
(
xbase
,
xlimit
)
VST649.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $READBASELIMIT on page 15-79
$READCLOCK
$READCLOCK
VST108.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $READCLOCK on page 15-80
HP pTAL Reference Manual—523746-006
A -78
Syntax Summary
Nonatomic
$READSPT
Note. The EpTAL compiler does not support this routine.
$READSPT
(
virtaddr
sptentryaddr
,
)
VST650.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
Yes
Sets $OVERFLOW
No
More information: $READSPT on page 15-80
$READTIME
$READTIME
VST651.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $READTIME on page 15-81
HP pTAL Reference Manual—523746-006
A -79
Syntax Summary
Nonatomic
$SCALE
$SCALE
(
fixed-expression
,
scale
)
VST110.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $SCALE on page 15-82
$SGBADDR_TO_EXTADDR
$SGBADDR_TO_EXTADDR
(
expression
)
VST603.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $SGBADDR_TO_EXTADDR on page 15-83
$SGBADDR_TO_SGWADDR
$SGBADDR_TO_SGWADDR
(
expression
)
VST604.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $SGBADDR_TO_SGWADDR on page 15-83
HP pTAL Reference Manual—523746-006
A -80
Syntax Summary
Nonatomic
$SGWADDR_TO_EXTADDR
$SGWADDR_TO_EXTADDR
(
expression
)
VST605.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $SGWADDR_TO_EXTADDR on page 15-84
$SGWADDR_TO_SGBADDR
$SGWADDR_TO_SGBADDR
(
expression
)
VST690.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $SGWADDR_TO_SGBADDR on page 15-85
$SPECIAL
$SPECIAL
(
int-expression
)
VST111.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $SPECIAL on page 15-85
HP pTAL Reference Manual—523746-006
A -81
Syntax Summary
Nonatomic
$STACK_ALLOCATE
Note. The pTAL and EpTAL compilers behave differently.
$STACK_ALLOCATE
size
(
)
VST032.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $STACK_ALLOCATE on page 15-86
$TRIGGER
Note.
•
•
The pTAL compiler does not support this routine.
Execution does not return from this call.
$TRIGGER
(
op
)
VST060.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $TRIGGER on page 15-88
HP pTAL Reference Manual—523746-006
A -82
Syntax Summary
Nonatomic
$TYPE
(
$TYPE
variable
)
VST112.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $TYPE on page 15-88
$UDBL
$UDBL
int-expression
(
)
VST113.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $UDBL on page 15-89
HP pTAL Reference Manual—523746-006
A -83
Syntax Summary
Nonatomic
$UDIVREM16
$UDIVREM16
quotient
(
dividend
remainder
,
divisor
,
)
,
;
VST653.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes, if the divisor is 0 or the
quotient is too large
More information: $UDIVREM16 on page 15-90
$UDIVREM32
$UDIVREM32
quotient
(
dividend
remainder
,
,
)
divisor
,
;
VST654.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
Yes, if and only if the divisor is 0
More information: $UDIVREM32 on page 15-91
HP pTAL Reference Manual—523746-006
A -84
Syntax Summary
Nonatomic
$UNLOCKPAGE
Note. The EpTAL compiler does not support this routine.
unlockcount
(
$UNLOCKPAGE
virtaddr
,
)
;
VST655.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
Yes
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $UNLOCKPAGE on page 15-93
$WADDR_TO_BADDR
$WADDR_TO_BADDR
(
expression
)
VST691.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $WADDR_TO_BADDR on page 15-93
HP pTAL Reference Manual—523746-006
A -85
Syntax Summary
Nonatomic
$WADDR_TO_EXTADDR
$WADDR_TO_EXTADDR
(
expression
)
VST692.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $WADDR_TO_EXTADDR on page 15-94
$WRITEPTE
Note. The EpTAL compiler does not support this routine.
$WRITEPTE
abs
)
(
ptetag
pageframe
,
,
:
VST656.vsd
pTAL privileged procedure
Yes
Can be executed only by privileged procedures
Yes
Sets condition code
No
Sets $CARRY
Yes
Sets $OVERFLOW
No
More information: $WRITEPTE on page 15-95
HP pTAL Reference Manual—523746-006
A -86
Syntax Summary
Compiler Directives
$XADR
$XADR
(
variable
)
VST115.vsd
pTAL privileged procedure
No
Can be executed only by privileged procedures
No
Sets condition code
No
Sets $CARRY
No
Sets $OVERFLOW
No
More information: $XADR on page 15-96
Compiler Directives
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Directive Line on page A-89
ASSERTION on page A-89
BEGINCOMPILATION on page A-90
BLOCKGLOBALS on page A-90
CALL_SHARED on page A-91
CHECKSHIFTCOUNT on page A-92
CODECOV on page A-92
COLUMNS on page A-93
DEFEXPAND on page A-94
DEFINETOG on page A-95
DO_TNS_SYNTAX on page A-96
ENDIF on page A-96
ERRORFILE on page A-96
ERRORS on page A-97
EXPORT_GLOBALS on page A-97
FIELDALIGN on page A-98
FMAP on page A-98
GLOBALIZED on page A-99
GMAP on page A-99
HP pTAL Reference Manual—523746-006
A -87
Syntax Summary
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
Compiler Directives
GP_OK on page A-100
IF, IFNOT, and ENDIF on page A-100
INNERLIST on page A-103
INVALID_FOR_PTAL on page A-103
LINES on page A-104
LIST on page A-104
MAP on page A-105
OPTIMIZE on page A-105
OPTIMIZEFILE on page A-106
OVERFLOW_TRAPS on page A-107
PAGE on page A-108
PRINTSYM on page A-108
REFALIGNED on page A-109
RESETTOG on page A-110
ROUND on page A-111
SAVEGLOBALS on page A-111
SECTION on page A-112
SETTOG on page A-113
SOURCE on page A-114
SRL on page A-115
SUPPRESS on page A-115
SYMBOLS on page A-116
SYNTAX on page A-116
TARGET on page A-117
USEGLOBALS on page A-118
WARN on page A-119
HP pTAL Reference Manual—523746-006
A -88
Syntax Summary
Directive Line
Directive Line
?
directive
,
VST120.vsd
More information: Directive Line on page 17-2
ASSERTION
assertion-level
ASSERTION
,
=
procedure-name
VST123.vsd
Default:
None
Placement:
•
•
Scope:
Applies until another ASSERTION overrides it
Dependencies:
Has no effect without the ASSERT statement
References:
ASSERT on page A-40
Anywhere in the source file (not in the compilation command)
Must be the last directive on the directive line
More information: ASSERTION on page 17-19
HP pTAL Reference Manual—523746-006
A -89
Syntax Summary
BEGINCOMPILATION
BEGINCOMPILATION
Note.
This directive can appear only in the source file, not in the compilation command.
The EpTAL compiler ignores this directive.
•
•
BEGINCOMPILATION
VST991.vsd
Default:
None
Placement:
•
In the source file between the last global data declaration and the
first procedure declaration, including any EXTERNAL and
FORWARD declarations
•
Scope:
Can appear only once in a compilation unit
Applies to all source code that follows it in the compilation unit
Dependencies:
References:
•
•
Has no effect without the USEGLOBALS directive
If you specify either SAVEGLOBALS or USEGLOBALS, your
compilation unit must have exactly one BEGINCOMPILATION
directive
•
•
•
Interacts with SAVEGLOBALS and USEGLOBALS
SAVEGLOBALS on page A-111
USEGLOBALS on page A-118
More information: BEGINCOMPILATION on page 17-20
BLOCKGLOBALS
BLOCKGLOBALS
VST658.vsd
Default:
The compiler allocates data items in the _GLOBAL and $_GLOBAL data
blocks
Placement:
Before the first data declaration in a compilation
Scope:
Applies to the compilation unit
Dependencies:
None
More information: BLOCKGLOBALS on page 17-21
HP pTAL Reference Manual—523746-006
A -90
Syntax Summary
CALL_SHARED
CALL_SHARED
Note.
•
•
This directive is useful only for the pTAL compiler. The EpTAL compiler ignores it (and
issues a warning).
You cannot link PIC and non-PIC object files into a single object file.
CALL_SHARED
NOCALL_SHARED
VST036.vsd
Default:
pTAL compiler:
NOCALL_SHARED
EpTAL compiler:
CALL_SHARED
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
•
•
References:
If both CALL_SHARED and NOCALL_SHARED appear in the same
compilation unit, the compiler uses the one that appears last
Do not use CALL_SHARED with GP_OK
GP_OK on page A-100
More information: CALL_SHARED on page 17-22
HP pTAL Reference Manual—523746-006
A -91
Syntax Summary
CHECKSHIFTCOUNT
CHECKSHIFTCOUNT
CHECKSHIFTCOUNT
NOCHECKSHIFTCOUNT
PUSHCHECKSHIFTCOUNT
POPCHECKSHIFTCOUNT
VST659.vsd
Default:
NOCHECKSHIFTCOUNT
Placement:
Anywhere
•
Scope:
•
Dependencies:
CHECKSHIFTCOUNT applies to the shift operators that follow it
until it is overridden by NOCHECKSHIFTCOUNT
NOCHECKSHIFTCOUNT applies to the shift operators that follow it
until it is overridden by CHECKSHIFTCOUNT
None
Caution. If NOCHECKSHIFT is active and a bit-shift operation occurs in which the number of
positions in a bit-shift operation is too large, subsequent program behavior is undefined.
More information: CHECKSHIFTCOUNT on page 17-23
CODECOV
Note. This directive is valid only in the eptal command line.
CODECOV
VST834.vsd
Default:
No code coverage instrumentation in object code
Placement:
Anywhere [Reviewers: is this correct??]
Scope:
Applies to the compilation unit [Reviewers: is this correct??]
Dependencies:
None
More information:
•
•
Using the Code Coverage Tool on page 16-17
Code Coverage Tool Reference Manual
HP pTAL Reference Manual—523746-006
A -92
Syntax Summary
COLUMNS
COLUMNS
columns-value
COLUMNS
VST127.vsd
Default:
Placement:
COLUMNS 132
•
•
Scope:
Anywhere, but if COLUMNS appears in the source code,
COLUMNS must be the only directive on the directive line
Typically specified before any SECTION directive
Applies to all source code that follows it unless overridden by:
•
•
•
Another COLUMNS directive in the same source file (not
recommended)
A COLUMNS directive in a source file included by means of a
SOURCE directive
A COLUMNS directive in a section identified by a SECTION
directive
For details, see the explanation that follows this table.
Dependencies:
References:
None
•
•
SECTION on page A-112
SOURCE on page A-114
More information: COLUMNS on page 17-24
HP pTAL Reference Manual—523746-006
A -93
Syntax Summary
DEFEXPAND
DEFEXPAND
DEFEXPAND
NODEFEXPAND
PUSHDEFEXPAND
POPDEFEXPAND
VST023.vsd
Default:
NODEFEXPAND
Placement:
Anywhere
Scope:
•
•
Dependencies:
References:
DEFEXPAND applies to subsequent code it until it is overridden by
NODEFEXPAND
NODEFEXPAND applies to subsequent code until it is overridden by
DEFEXPAND
DEFEXPAND has no effect if NOLIST or SUPPRESS is active
•
•
LIST on page A-104
SUPPRESS on page A-115
More information: DEFEXPAND on page 17-26
HP pTAL Reference Manual—523746-006
A -94
Syntax Summary
DEFINETOG
DEFINETOG
DEFINETOG
toggle-name
toggle-number
,
(
toggle-name
)
toggle-number
,
VST212.vsd
Default:
Placement:
None
•
•
With a parenthesized list, it can appear anywhere
Without a parenthesized list, it must be the last directive on the
directive line or compilation command line
Scope:
Applies to the compilation unit
Dependencies:
Interacts with:
•
•
•
•
•
SETTOG
RESETTOG
IF
IFNOT
ENDIF
See Toggles on page 17-5.
References:
•
•
•
IF, IFNOT, and ENDIF on page A-100
RESETTOG on page A-110
SETTOG on page A-113
More information: DEFINETOG on page 17-27
HP pTAL Reference Manual—523746-006
A -95
Syntax Summary
DO_TNS_SYNTAX
DO_TNS_SYNTAX
DO_TNS_SYNTAX
NODO_TNS_SYNTAX
PUSHDO_TNS_SYNTAX
POPDO_TNS_SYNTAX
VST663.vsd
Default:
NODO_TNS_SYNTAX
Placement:
•
•
Scope:
Applies to the compilation unit
Dependencies:
None
References:
TARGET on page A-117
Can appear only once in a compilation
Must precede any TARGET directive and any nondirective lines
More information: DO_TNS_SYNTAX on page 17-28
ENDIF
See IF, IFNOT, and ENDIF on page A-100.
ERRORFILE
file-name
ERRORFILE
define-name
assign-name
VST137.vsd
Default:
Placement:
None
•
•
In the compilation command or in the source code before any
declarations
Can appear only once in a compilation unit
Scope:
Applies to the compilation unit
Dependencies:
None
More information: ERRORFILE on page 17-30
HP pTAL Reference Manual—523746-006
A -96
Syntax Summary
ERRORS
ERRORS
num-messages
ERRORS
=
VST138.vsd
Default:
Unlimited number of errors
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
None
More information: ERRORS on page 17-33
EXPORT_GLOBALS
EXPORT_GLOBALS
NOEXPORT_GLOBALS
PUSHEXPORT_GLOBALS
POPEXPORT_GLOBALS
VST662.vsd
Default:
Placement:
Scope:
Dependencies:
EXPORT_GLOBALS
•
•
•
Applies to the compilation unit, except that NOEXPORT_GLOBALS
does not affect a compilation’s private data block, which is always
exported
•
•
References:
Can appear any number of times in a compilation unit
Must appear before the first procedure is compiled
Cannot appear within BLOCK declarations
•
•
•
You must specify NOEXPORT_GLOBALS when declaring a data
block that belongs to an SRL
In a compilation that includes USEGLOBALS, the compiler exports
the data blocks declared in the USEGLOBALS declarations file only
if EXPORT_GLOBALS is active when the compiler encounters the
BEGINCOMPILATION directive.
BEGINCOMPILATION on page A-90
SRL on page A-115
USEGLOBALS on page A-118
More information: EXPORT_GLOBALS on page 17-33
HP pTAL Reference Manual—523746-006
A -97
Syntax Summary
FIELDALIGN
FIELDALIGN
(
FIELDALIGN
SHARED2
)
SHARED8
PLATFORM
AUTO
NODEFAULT
VST660.vsd
Default:
FIELDALIGN AUTO
Placement:
•
•
Scope:
Applies to the compilation unit
Dependencies:
None
Can appear only once in a compilation unit
Must precede all declarations of data, blocks, and procedures
More information: FIELDALIGN on page 17-35
FMAP
FMAP
NOFMAP
VST141.vsd
Default:
NOFMAP
Placement:
Anywhere, any number of times. The last FMAP or NOFMAP in the
compilation unit determines whether the compiler lists the file map.
Scope:
Applies to the compilation unit
Dependencies:
FMAP has no effect if either NOLIST or SUPPRESS is active
References:
•
•
LIST on page A-104
SUPPRESS on page A-115
More information: FMAP on page 17-36
HP pTAL Reference Manual—523746-006
A -98
Syntax Summary
GLOBALIZED
GLOBALIZED
Note. This directive is valid only in the eptal command line.
GLOBALIZED
VST835.vsd
Default:
Generate non-preemptable object code
Placement:
On the command line
Scope:
Applies to the compilation unit [reviewers: is this true??]
Dependencies:
None
GMAP
GMAP
NOGMAP
VST142.vsd
Default:
GMAP
Placement:
Anywhere, any number of times. The last GMAP or NOGMAP in the
compilation unit determines whether the compiler lists the global map.
Scope:
Applies to the compilation unit
Dependencies:
References:
•
•
•
•
•
GMAP has no effect if NOLIST, NOMAP, or SUPPRESS is active
NOGMAP suppresses the global map even if MAP is active
LIST on page A-104
MAP on page A-105
SUPPRESS on page A-115
More information: GMAP on page 17-37
HP pTAL Reference Manual—523746-006
A -99
Syntax Summary
GP_OK
GP_OK
Note. The EpTAL compiler ignores this directive.
GP_OK
NOGP_OK
PUSHGP_OK
POPGP_OK
VST661.vsd
Default:
Placement:
Scope:
pTAL compiler:
GP_OK
EpTAL compiler:
NOGP_OK
Anywhere except inside a data block or inside a procedure declaration
•
•
GP_OK applies to subsequent code it until it is overridden by
NOGP_OK
NOGP_OK applies to subsequent code until it is overridden by
GP_OK
Dependencies:
Do not use GP_OK with CALL_SHARED
References:
CALL_SHARED on page A-91
More information: GP_OK on page 17-38
IF, IFNOT, and ENDIF
IF
toggle-number
IFNOT
toggle-name
target
pTAL
VST694.vsd
ENDIF
toggle-name
toggle-number
target
pTAL
VST693.vsd
HP pTAL Reference Manual—523746-006
A-100
Syntax Summary
IF, IFNOT, and ENDIF
target
ANY
RISC1
TNS_ARCH
TNSR_ARCH
_TNS_E_TARGET
TARGETSPECIFIED
VST695.vsd
Compiler
pTAL
EpTAL
Implicitly Sets
•
•
•
•
Implicitly Resets
RISC1
TARGETSPECIFIED
_TNS_E_TARGET
_TNS_E_TARGET
TARGETSPECIFIED
RISC1
pTAL
Compiler
IF pTAL
IFNOT pTAL
pTAL or EpTAL
True
False
TAL
False
True
HP pTAL Reference Manual—523746-006
A-101
Syntax Summary
Default:
Placement:
IF, IFNOT, and ENDIF
None
•
•
•
Anywhere in the source file (not in the compilation command)
IF or IFNOT must be the last directive on its directive line
ENDIF must be the only directive on its directive line
Scope:
Everything between IF or IFNOT and the next ENDIF that specifies the
same toggle, target, or keyword
Dependencies:
Interact with:
•
•
•
•
DEFINETOG
SETTOG
RESETTOG
TARGET
See Toggles on page 17-5.
References:
•
•
•
•
DEFINETOG on page A-95
RESETTOG on page A-110
SETTOG on page A-113
TARGET on page A-117
More information:
•
•
IF and IFNOT on page 17-39
ENDIF on page 17-29
HP pTAL Reference Manual—523746-006
A-102
Syntax Summary
INNERLIST
INNERLIST
INNERLIST
NOINNERLIST
PUSHINNERLIST
POPINNERLIST
VST149.vsd
Default:
NOINNERLIST
Placement:
Anywhere
Scope:
•
•
Dependencies:
References:
INNERLIST applies to subsequent statements it until it is overridden
by NOINNERLIST
NOINNERLIST applies to subsequent statements until it is
overridden by INNERLIST
INNERLIST has no effect if NOLIST or SUPPRESS is active
•
•
LIST on page A-104
SUPPRESS on page A-115
More information: INNERLIST on page 17-42
INVALID_FOR_PTAL
INVALID_FOR_PTAL
VST701.vsd
Default:
None
Placement:
After IF or IFNOT and before ENDIF
Scope:
Applies to code between itself and ENDIF
Dependencies:
None
References:
IF, IFNOT, and ENDIF on page A-100
More information: INVALID_FOR_PTAL on page 17-43
HP pTAL Reference Manual—523746-006
A-103
Syntax Summary
LINES
LINES
num-lines
LINES
=
VST154.vsd
Default:
LINES 60
Placement:
Anywhere
Scope:
Applies until overridden by another LINES directive
Dependencies:
Has no effect if the list file is a terminal
More information: LINES on page 17-44
LIST
LIST
NOLIST
PUSHLIST
POPLIST
VST155.vsd
Default:
LIST
Placement:
Anywhere
Scope:
•
•
Dependencies:
LIST has no effect if SUPPRESS is active
References:
SUPPRESS on page A-115
LIST applies to subsequent code it until it is overridden by NOLIST
NOLIST applies to subsequent code until it is overridden by LIST
More information: LIST on page 17-44
HP pTAL Reference Manual—523746-006
A-104
Syntax Summary
MAP
MAP
MAP
NOMAP
PUSHMAP
POPMAP
VST157.vsd
Default:
MAP
Placement:
Anywhere
Scope:
•
•
Dependencies:
MAP has no effect if NOLIST or SUPPRESS is active
References:
•
•
MAP applies to subsequent code it until it is overridden by NOMAP
NOMAP applies to subsequent code until it is overridden by MAP
LIST on page A-104
SUPPRESS on page A-115
More information: MAP on page 17-45
OPTIMIZE
level
OPTIMIZE
=
VST665.vsd
Default:
OPTIMIZE 1
Placement:
Outside the boundary of a separately compiled program
Scope:
The optimization level active at the beginning of a separately compiled
program determines the level of optimization for that program and any
programs it contains
Dependencies:
None
More information: OPTIMIZE on page 17-47
HP pTAL Reference Manual—523746-006
A-105
Syntax Summary
OPTIMIZEFILE
OPTIMIZEFILE
filename
OPTIMIZEFILE
VST666.vsd
filename
routine-name
optimize-level
comment
#
blank line
VST064.vsd
Default:
The optimization level that OPTIMIZE specified
Placement:
Only in the compilation command (not in the source file)
Scope:
Applies to the compilation unit
Dependencies:
None
References:
OPTIMIZE on page A-105
Note. The pTAL and EpTAL compilers behave differently.
More information: OPTIMIZEFILE on page 17-47
HP pTAL Reference Manual—523746-006
A-106
Syntax Summary
OVERFLOW_TRAPS
OVERFLOW_TRAPS
OVERFLOW_TRAPS
NOOVERFLOW_TRAPS
PUSHOVERFLOW_TRAPS
POPOVERFLOW_TRAPS
VST697.vsd
Default:
pTAL compiler:
OVERFLOW_TRAPS
EpTAL compiler:
NOOVERFLOW_TRAPS
Placement:
Before or between procedure declarations
Scope:
From the point it occurs in the compilation until it is overridden or the
compilation ends, whichever occurs first
Dependencies:
OVERFLOW_TRAPS is overridden by:
•
•
NOOVERFLOW_TRAPS procedure attribute
DISABLE_OVERFLOW_TRAPS block attributes
NOOVERFLOW_TRAPS is overridden by:
•
•
References:
OVERFLOW_TRAPS procedure attribute
ENABLE_OVERFLOW_TRAPS block attributes
See Managing Overflow Traps on page 13-1
More information: OVERFLOW_TRAPS on page 17-49
HP pTAL Reference Manual—523746-006
A-107
Syntax Summary
PAGE
PAGE
PAGE
heading-string
"
"
VST160.vsd
Default:
LINES determines page ejects and no heading is printed
Placement:
Only in the source file (not in the compilation command)
Scope:
Applies until overridden by another PAGE directive
Dependencies:
Has no effect if either:
References:
•
•
•
•
•
NOLIST or SUPPRESS is active
The list file is a terminal
LINES on page A-104
LIST on page A-104
SUPPRESS on page A-115
More information: PAGE on page 17-51
PRINTSYM
PRINTSYM
NOPRINTSYM
VST162.vsd
Default:
PRINTSYM
Placement:
Anywhere
Scope:
•
•
Dependencies:
References:
•
•
•
•
•
•
PRINTSYM applies to subsequent declarations until overridden by
NOPRINTSYM
NOPRINTSYM applies to subsequent declarations until overridden
by PRINTSYM
PRINTSYM has no effect if NOLIST or SUPPRESS is active
PRINTSYM interacts with SAVEGLOBALS and USEGLOBALS
LIST on page A-104
SAVEGLOBALS on page A-111
SUPPRESS on page A-115
USEGLOBALS on page A-118
More information: PRINTSYM on page 17-52
HP pTAL Reference Manual—523746-006
A-108
Syntax Summary
REFALIGNED
REFALIGNED
REFALIGNED
(
2
)
8
PUSHREFALIGNED
POPREFALIGNED
VST669.vsd
Default:
REFALIGNED 8
Placement:
Anywhere
Scope:
Applies to subsequent pointers to nonstructure data items and
procedure reference parameters until overridden by another REFALIGN
directive
Dependencies:
None
More information: REFALIGNED on page 17-53
HP pTAL Reference Manual—523746-006
A-109
Syntax Summary
RESETTOG
RESETTOG
RESETTOG
toggle-name
toggle-number
,
(
toggle-name
)
toggle-number
,
VST164.vsd
Default:
Placement:
None
•
•
With a parenthesized list, it can appear anywhere
Without a parenthesized list, it must be the last directive on the
directive line or compilation command line
Scope:
Applies to the compilation unit
Dependencies:
Interacts with:
•
•
•
•
•
DEFINETOG
SETTOG
IF
IFNOT
ENDIF
See Toggles on page 17-5.
References:
•
•
•
DEFINETOG on page A-95
IF, IFNOT, and ENDIF on page A-100
SETTOG on page A-113
More information: RESETTOG on page 17-54
HP pTAL Reference Manual—523746-006
A-110
Syntax Summary
ROUND
ROUND
ROUND
NOROUND
VST165.vsd
Default:
NOROUND
Placement:
Anywhere
Scope:
•
•
Dependencies:
None
ROUND applies to subsequent code until overridden by NOROUND
NOROUND applies to subsequent code until overridden by ROUND
More information: ROUND on page 17-55
SAVEGLOBALS
Note. The EpTAL compiler does not accept this directive.
SAVEGLOBALS
file-name
define-name
VST670.vsd
Default:
None
Placement:
Either in the compilation command or in the source code before any
global data declarations
Scope:
Applies to the compilation unit
Dependencies:
•
•
References:
•
•
•
•
•
•
If SAVEGLOBALS and USEGLOBALS appear in the same
compilation unit, the compiler uses only the one that appears first
The compilation unit must have exactly one BEGINCOMPILATION
directive
Interacts with the directives referenced in the next row
BEGINCOMPILATION on page A-90
PRINTSYM on page A-108
SYMBOLS on page A-116
SYNTAX on page A-116
USEGLOBALS on page A-118
More information: SAVEGLOBALS on page 17-56
HP pTAL Reference Manual—523746-006
A-111
Syntax Summary
SECTION
SECTION
section-name
SECTION
VST171.vsd
Default:
Placement:
None
•
•
Only in the source file (not in the compilation command)
Must be the only directive on the directive line
Scope:
Applies to subsequent code until another SECTION directive or the end
of the file, whichever is first
Dependencies:
Interacts with SOURCE (see Section Names on page 17-61)
References:
SOURCE on page 17-60
More information: SECTION on page 17-57
HP pTAL Reference Manual—523746-006
A-112
Syntax Summary
SETTOG
SETTOG
SETTOG
toggle-name
toggle-number
,
(
toggle-name
)
toggle-number
,
VST172.vsd
Default:
Placement:
None
•
•
With a parenthesized list, it can appear anywhere
Without a parenthesized list, it must be the last directive on the
directive line or compilation command line
Scope:
Applies to the compilation unit
Dependencies:
Interacts with:
•
•
•
•
•
DEFINETOG
RESETTOG
IF
IFNOT
ENDIF
See Toggles on page 17-5.
References:
•
•
•
DEFINETOG on page A-95
IF, IFNOT, and ENDIF on page A-100
RESETTOG on page A-110
More information: SETTOG on page 17-58
HP pTAL Reference Manual—523746-006
A-113
Syntax Summary
SOURCE
SOURCE
SOURCE
file-name
(
define-name
section-name
)
,
assign-name
VST173.vsd
Default:
None
Placement:
•
•
Scope:
Applies to the source file
Dependencies:
References:
•
•
•
•
•
•
•
•
•
Only in the source file (not in the compilation command)
Must be the last directive on the directive line
Interacts with COLUMNS
Interacts with SECTION (see Section Names on page 17-61)
Interacts with the directives referenced in the next row
BEGINCOMPILATION on page A-90
COLUMNS on page A-93
LIST on page A-104
SECTION on page A-112
SUPPRESS on page A-115
USEGLOBALS on page A-118
More information: SOURCE on page 17-60
HP pTAL Reference Manual—523746-006
A-114
Syntax Summary
SRL
SRL
Note. The EpTAL compiler ignores this directive.
SRL
VST671.vsd
Default:
None
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
When declaring a data block that belongs to an SRL, you must specify
NOEXPORT_GLOBALS and NOGP_OK.
•
•
References:
EXPORT_GLOBALS on page A-97
GP_OK on page A-100
More information: SRL on page 17-65
SUPPRESS
SUPPRESS
NOSUPPRESS
VST176.vsd
Default:
NOSUPPRESS
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
Overrides all the listing directives (see the following row)
References:
•
•
•
•
•
•
•
•
DEFEXPAND on page A-94
FMAP on page A-98
GMAP on page A-99
INNERLIST on page A-103
LIST on page A-104
MAP on page A-105
PAGE on page A-108
PRINTSYM on page A-108
More information: SUPPRESS on page 17-65
HP pTAL Reference Manual—523746-006
A-115
Syntax Summary
SYMBOLS
SYMBOLS
SYMBOLS
NOSYMBOLS
VST672.vsd
Default:
NOSYMBOLS
Placement:
Before the first declaration in the compilation
Scope:
The last legally placed SYMBOLS or NOSYMBOLS applies to the
compilation unit
Dependencies:
Interacts with SAVEGLOBALS and USEGLOBALS
•
•
References:
SAVEGLOBALS on page A-111
USEGLOBALS on page A-118
Note. These linker options discard information that SYMBOLS saves:
•
•
-x discards line number information.
-s discards information needed for future linking (use it only in building an executable file).
More information: SYMBOLS on page 17-66
SYNTAX
SYNTAX
VST178.vsd
Default:
The compiler produces an object file
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
Interacts with SAVEGLOBALS and USEGLOBALS
References:
•
•
SAVEGLOBALS on page A-111
USEGLOBALS on page A-118
More information: SYNTAX on page 17-67
HP pTAL Reference Manual—523746-006
A-116
Syntax Summary
TARGET
TARGET
TARGET
T16
LIBERTY
RISC1
ANY
TNS_ARCH
TNS_R_ARCH
_TNS_E_TARGET
VST673.vsd
Default:
pTAL compiler:
TNS_R_ARCH
EpTAL compiler:
_TNS_E_TARGET
Placement:
Anywhere
Scope:
Applies to the compilation unit
Dependencies:
None
More information: TARGET on page 17-68
HP pTAL Reference Manual—523746-006
A-117
Syntax Summary
USEGLOBALS
USEGLOBALS
Note. The EpTAL compiler does not accept this directive.
USEGLOBALS
file-name
define-name
VST674.vsd
Default:
None
Placement:
Either in the compilation command or in the source code before any
global data declarations
Scope:
Applies to the compilation unit
Dependencies:
•
•
•
References:
•
•
•
•
•
•
•
The compilation unit must have exactly one BEGINCOMPILATION
directive.
The compiler exports the data blocks declared in the USEGLOBALS
declarations file only if EXPORT_GLOBALS is active when the
compiler encounters the BEGINCOMPILATION directive.
A module that specifies USEGLOBALS can export a global data
block that was declared in the compilation that specified
SAVEGLOBALS only if the SAVEGLOBALS compilation exported
the data block.
Typically, a project that uses SAVEGLOBALS explicitly links globals
into the object file and specifies NOEXPORT_GLOBALS (the
default) for all individual compilations.
Interacts with the directives referenced in the next row.
BEGINCOMPILATION on page A-90
EXPORT_GLOBALS on page A-97
PRINTSYM on page A-108
SAVEGLOBALS on page A-111
SYMBOLS on page A-116
SYNTAX on page A-116
More information: USEGLOBALS on page 17-69
HP pTAL Reference Manual—523746-006
A-118
Syntax Summary
WARN
WARN
WARN
warning-number
NOWARN
VST675.vsd
Default:
WARN
Placement:
Anywhere
Scope:
Dependencies:
•
•
WARN applies to subsequent code until overridden by NOWARN
NOWARN applies to subsequent code until overridden by WARN;
however: To print selected warnings, you must specify WARN before
any NOWARN directives. If you specify NOWARN first, subsequent
WARN warning-number directives have no effect.
None
More information: WARN on page 17-71
HP pTAL Reference Manual—523746-006
A-119
Syntax Summary
WARN
HP pTAL Reference Manual—523746-006
A-120
B
Disk File Names and HP TACL
Commands
Note. This appendix applies only to Guardian platforms, not Windows platforms.
•
•
Disk File Names on page B-1
HP TACL Commands on page B-4
For information about process or device file names, see the Guardian Programmer’s
Guide.
Disk File Names
A disk file name identifies a file that contains data or a program. A disk file name
reflects the specified file’s location on a NonStop system. The location of a disk file on
a NonStop system is analogous to the location of a form in a file cabinet. To find the
form, you must know:
•
•
•
•
Which file cabinet it is in
Which drawer it is in
Which folder it is in
Which form it is
Analogously, to find a disk file on a NonStop system, you must know:
•
•
•
•
Which node (system) it is on
Which volume it is on
Which subvolume it is on
Which disk file it is
In general, disk file names:
•
•
•
Cannot contain spaces
Can contain ASCII characters only
Are not case-sensitive; the following names are equivalent:
myfile
MyFile
MYFILE
•
Language functions and system procedures that return file names might return
them in uppercase letters (even if the file name was originally in lowercase letters).
Check the description of the routine that you are using.
HP pTAL Reference Manual—523746-006
B- 1
Disk File Names and HP TACL Commands
Parts of a Disk File Name
Topics:
•
•
•
•
Parts of a Disk File Name on page B-2
Partial File Names on page B-3
Logical File Names on page B-4
Internal File Names on page B-4
Parts of a Disk File Name
A disk file has a unique file name that consists of four parts, with each part separated
by a period:
•
•
•
•
A D-series node name or a C-series system name
A volume name
A subvolume name
A file ID
Example B-1. Disk File Name
\mynode.$myvol.mysubvol.myfileid
You can name your own subvolumes and file IDs, but nodes (systems) and volumes
are named by the system manager.
All parts of the file name except the file ID are optional except as noted in the following
discussion. If you omit any part of the file name, the system uses values as described
in Partial File Names on page B-3.
Topics:
•
•
•
•
Node or System Name on page B-2
Volume Name on page B-3
Subvolume Name on page B-3
File ID on page B-3
Node or System Name
The node or system name, such as \MYNODE, is the name of the node or system
where the file resides. If specified, the node or system name must begin with a
backslash (\) followed by one to seven alphanumeric characters. The character
following the backslash must be an alphabetic character.
HP pTAL Reference Manual—523746-006
B- 2
Disk File Names and HP TACL Commands
Partial File Names
Volume Name
The volume name, such as $MYVOL, is the name of the disk volume where the file
resides. If specified, the volume name must begin with a dollar sign ($), followed by
one to six or one to seven alphanumeric characters as follows. The character following
the dollar sign must be an alphabetic character.
On a D-series system, the volume name can contain one to seven alphanumeric
characters.
On a C-series system, the volume name can contain:
•
•
One to six alphanumeric characters if you include the system name
One to seven alphanumeric characters if you omit the system name
On a C-series system, if you specify the system name, you must also specify the
volume name. If you omit the system name, specifying the volume name is optional.
Subvolume Name
The subvolume name, such as MYSUBVOL, is the name of the set of files, on the disk
volume, within which the file resides. The subvolume name can contain from one to
eight alphanumeric characters, the first of which must be alphabetic.
On a D-series system, if you specify the volume name, you must also specify the
subvolume name. If you omit the volume name, specifying the subvolume name is
optional.
File ID
The file ID, such as MYFILE, is the identifier of the file in the subvolume. The file ID
can contain from one to eight alphanumeric characters, the first of which must be
alphabetic.
The file ID is required.
Partial File Names
A partial file name contains at least the file ID, but does not contain all the file-name
parts. When you specify a partial file name, the operating system or other process fills
in the missing file-name parts by using your current default values. Following are the
optional file-name parts and their default values:
File-Name Part
Default
node (system)
Node (system) on which your program is executing
volume
Current default volume
subvolume
Current default subvolume
HP pTAL Reference Manual—523746-006
B- 3
Disk File Names and HP TACL Commands
Logical File Names
Following are all the partial file names you can specify for a disk file named
\BRANCH.$DIV.DEPT.EMP:
Omitted File-Name Parts
Partial File Name
D-Series
System
C-Series
System
Node (system)
$div.dept.emp
Yes
Yes
Node (system), volume
dept.emp
Yes
Yes
Node (system), volume, subvolume
emp
Yes
Yes
Volume
\branch.dept.emp
Yes
No
Volume, subvolume
\branch.emp
Yes
No
Subvolume
\branch.$div.emp
No
Yes
Node (system), subvolume
$div.emp
No
Yes
You can change your current default values in various ways:
•
•
You can change the volume and subvolume with the VOLUME command of, for
example, the HP TACL products.
In some cases, you can specify node (system), volume, and subvolume names by
issuing HP TACL ASSIGN SSV commands.
Logical File Names
You can use a logical file name in place of the disk file name. A logical file name is an
alternate name you specify in an HP TACL DEFINE or ASSIGN command.
Internal File Names
The C-series operating system uses the internal form of a file name when passing it
between your program and the operating system. The D-series operating system uses
the internal form only if your program has not been converted to use D-series features.
For information about converting external file names to internal file names in a
program, see the Guardian Programmer’s Guide and the Guardian Procedure Calls
Reference Manual.
HP TACL Commands
Before starting the compiler, you can send information to it by using the following
HP TACL commands:
•
•
•
DEFINE on page B-5
PARAM SWAPVOL on page B-7
ASSIGN on page B-7
HP pTAL Reference Manual—523746-006
B- 4
Disk File Names and HP TACL Commands
DEFINE
For complete information about these commands, see the following manuals:
•
•
•
•
TACL Reference Manual (syntactic information)
TACL Programmer’s Guide (programmatic information)
Guardian User’s Guide (interactive information)
Guardian Programmer’s Guide (programmatic information)
DEFINE
•
•
Substituting File Names for DEFINE Macros on page B-5
DEFINE Names on page B-5
To create a DEFINE message or set its attributes, you must set a CLASS attribute for
the DEFINE. The CLASS attributes are:
•
•
•
•
MAP DEFINE (Guardian Platforms Only) on page B-6
TAPE DEFINE (D-Series Systems Only) on page B-6
SPOOL DEFINE on page B-6
DEFAULTS DEFINE on page B-7
Each attribute has an initial setting based on whether the attribute is required, optional,
or default.
Substituting File Names for DEFINE Macros
To substitute a file name for a DEFINE name that is being passed by a nonprivileged
program to a system procedure, use the following HP TACL commands:
HP TACL Command
Purpose
SET DEFMODE ON
Enable DEFINE processing
SET DEFINE CLASS
Set the initial attribute of a DEFINE command to CLASS MAP*
SET DEFINE
Set the working attributes
ADD DEFINE
Specify a file name to substitute for a DEFINE name
* MAP DEFINEs are available only on Guardian platforms.
DEFINE Names
HP TACL DEFINE names:
•
•
•
•
Are not case-sensitive
Have 2 to 24 characters
Begin with an equals sign (=) followed by an alphabetic character
Continue with any combination of letters, digits, hyphens (-), underscores (_), and
circumflexes (^)
HP pTAL Reference Manual—523746-006
B- 5
Disk File Names and HP TACL Commands
DEFINE
DEFINE names that begin with an equals sign followed by an underscore (=_) are
reserved by HP (for example, =_DEFAULTS).
Example B-2. DEFINE Names
=A
=The_chosen_file
=Long-but-not-too-long
=The-File-of-The-Week
MAP DEFINE (Guardian Platforms Only)
When you log on, the default CLASS attribute is MAP, which requires a file name. A
MAP DEFINE substitutes a file name for a DEFINE name used in the source file. For
example, suppose that your current CLASS attribute is MAP and your source file
includes the DEFINE name =MULTI in a SOURCE directive:
?SOURCE =multi
Before running the compiler, you can associate file name
\brig.$ullx.cable.port with =multi:
ADD DEFINE =multi, FILE \brig.$ullx.cable.port
During compilation, the compiler passes the DEFINE name to a system procedure,
which makes the file available to the compiler. If the system procedure cannot make
the file available, the open operation fails.
TAPE DEFINE (D-Series Systems Only)
The TAPE DEFINE lets you specify attributes for labeled magnetic tapes. For instance,
it lets you specify attributes such as block length, recording density, record format and
length, number of reels, and labeling.
SPOOL DEFINE
The SPOOL DEFINE lets you specify spooler settings or attributes, such as number of
copies, form name, location, owner, report name, and priority.
HP pTAL Reference Manual—523746-006
B- 6
Disk File Names and HP TACL Commands
PARAM SWAPVOL
DEFAULTS DEFINE
In the DEFAULTS class, a permanently built-in DEFINE named =_DEFAULTS has the
following attributes, which are active regardless of any DEFMODE setting:
Attribute
Required
Purpose
VOLUME
Yes
Contains the default node, volume, and subvolume names for
the current process as set by the HP TACL VOLUME,
SYSTEM, and LOGON commands
SWAP
No
Contains the node and volume name in which the operating
system is to store swap files
CATALOG
No
Contains a substitute name for a catalog as described in the
SQL/MP Reference Manual and the SQL/MX Reference
Manual.
PARAM SWAPVOL
The PARAM SWAPVOL command lets you specify the volume that the compiler and
SYMSERV use for temporary files. For example:
PARAM SWAPVOL $myvol
The compiler ignores any node specification and allocates temporary files on its own
node. If you omit the volume, the compiler uses the default volume for temporary files;
SYMSERV uses the volume that is to receive the object file.
Use this command when:
•
•
The volumes normally used for temporary files might not have sufficient space.
The default volume or the volume to receive the object file is on a different node
from the compiler.
ASSIGN
You can issue the HP TACL ASSIGN command before starting the compiler to
substitute actual file names for logical file names used in the source file. The HP TACL
product stores the file-name mapping until the compiler requests it.
ASSIGN commands fall into two categories:
•
•
Ordinary ASSIGN Command on page B-8
ASSIGN SSV on page B-9
HP pTAL Reference Manual—523746-006
B- 7
Disk File Names and HP TACL Commands
ASSIGN
Ordinary ASSIGN Command
The ordinary ASSIGN command equates a file name with a logical file name used in
ERRORFILE, SAVEGLOBALS, SEARCH, SOURCE, and USEGLOBALS directives.
The compiler accepts only the first 75 ordinary ASSIGN messages.
Note. The EpTAL compiler ignores the SAVEGLOBALS and USEGLOBALS directives.
In each ASSIGN command, specify a logical identifier followed by a comma and the file
name or an HP TACL DEFINE name:
ASSIGN dog, \a.$b.c.dog
ASSIGN cat, =mycat
If the file name is incomplete, the HP TACL product completes it from your current
default node, volume, and subvolume. For example, if your current defaults are
\X.$Y.Z, the HP TACL product completes the incomplete file names in ASSIGN
commands as follows:
Incomplete File Names
Complete File Names
ASSIGN qq, cat
ASSIGN qq, \x.$y.z.cat
ASSIGN ss, b.dog
ASSIGN ss, \x.$y.b.dog
ASSIGN tt, $a.b.rat
ASSIGN tt, \x.$a.b.rat.
If you use an HP TACL DEFINE name in place of a file name, the HP TACL product
qualifies the file name specified in the ADD DEFINE command when it processes the
ASSIGN command. Even if you specify new node, volume, and subvolume defaults
between the ADD DEFINE command and the ASSIGN command, the ASSIGN
mapping still reflects the ADD DEFINE settings.
If you issue the following commands:
ASSIGN aa, $a.b.cat
ASSIGN bb, $a.b.dog
ASSIGN cc, =my_zebra
ADD DEFINE =my_zebra, CLASS MAP, FILE $a.b.zebra
pTAL /IN mysource, OUT $s/ obj
the compiler equates SOURCE directives in MYSOURCE to files as follows:
?SOURCE aa
?SOURCE cc
?SOURCE bb
! Equivalent to ?SOURCE $a.b.cat
! Equivalent to ?SOURCE $a.b.zebra
! Equivalent to ?SOURCE $a.b.dog
You can name new source files at each compilation without changing the contents of
the source file.
HP pTAL Reference Manual—523746-006
B- 8
Disk File Names and HP TACL Commands
ASSIGN
ASSIGN SSV
The ASSIGN SSV (search subvolume) command lets you specify which node, volume,
and subvolume to take files from. The compiler uses ASSIGN SSV information to
resolve partial file names in the SEARCH, SOURCE, and USEGLOBALS directives.
Note. The EpTAL compiler ignores the USEGLOBALS directive.
For each ASSIGN SSV command, append to the SSV keyword a value in the range 0
through 49. Values in the range 0 through 9 can appear with or without a leading 0.
For example, if you specify:
ASSIGN SSV1, oldfiles
and the compiler encounters the directive:
?SOURCE myutil
the compiler looks for oldfiles.myutil.
If you then specify:
ASSIGN SSV1, newfiles
and run the compiler again, it looks for newfiles.myutil.
If you omit the node or volume, the HP TACL product uses the current default node or
volume. If you omit the subvolume, the compiler ignores the command. HP TACL
DEFINE names are not allowed.
The ASSIGN SSV command also lets you specify the order in which subvolumes are
searched. You can specify ASSIGN SSV commands in any order. If the same SSV
value appears more than once, the HP TACL product stores only the last command
having that value.
For example, if you issue the following commands, the HP TACL product stores only
two of the messages:
Assign SSV Command
Stored
ASSIGN SSV28, $a.b
Yes
ASSIGN SSV7, $c.d
No
ASSIGN SSV7, $e.f
No
ASSIGN SSV07, $g.h
Yes
The compiler stores ASSIGN SSV messages in its SSV table in ascending order.
For each file name the compiler processes, the compiler scans the SSVs in ascending
order from SSV0 until it finds a subvolume that holds the file.
HP pTAL Reference Manual—523746-006
B- 9
Disk File Names and HP TACL Commands
ASSIGN
For example, if you issue the following ASSIGN commands before running the
compiler:
ASSIGN
ASSIGN
ASSIGN
ASSIGN
ASSIGN
SSV7,
SSV10,
SSV8,
SSV20,
trig,
$aa.b3
$aa.grplip
mylib
$cc.divlib
$sp.math.xtrig
and the compiler encounters the following SOURCE directive:
?SOURCE unpack
the compiler first looks for an ASSIGN message having the logical name unpack. If
there is none, the compiler looks for the file in subvolumes in the following order:
$aa.b3.unpack
$default-volume.mylib.unpack
$aa.grplib.unpack
$cc.divlib.unpack
$default-volume.default-subvolume.unpack
(SSV7)
(SSV8)
(SSV10)
(SSV20)
The compiler uses the first file it finds. If it finds none named unpack, it issues an error
message.
When the compiler encounters this directive:
?SOURCE trig
it tries only $sp.math.xtrig; if it does not find that exact file, it issues an error
message.
HP pTAL Reference Manual—523746-006
B -10
C
Differences Between the pTAL and
EpTAL Compilers
•
•
•
•
General on page C-1
Data Types and Alignment on page C-1
Routines on page C-2
Compiler Directives on page C-3
General
Topic
pTAL Compiler
EpTAL Compiler
RVU
D40 and later
G06.20 and later
H06.01 and later
Compiler command
ptal
eptal
Cross compiler*
NonStop pTAL
NonStop EpTAL
•
•
•
Object code generated
•
TNS/R object code
Non-PIC (default) or PIC
Object files have file code
700 on Guardian platform
Preemptable
•
•
•
•
TNS/E object code
PIC
Object files have file code
800 on Guardian platform
Non-preemptable (default)
or preemptable
* For differences between cross compilers, see NonStop pTAL (ETK) on page 18-2
Data Types and Alignment
Topic
pTAL Compiler
EpTAL Compiler
STRUCTALIGN clause
with MAXALIGN attribute
Syntax error
Accepted in template structure declarations
(see Declaring Template Structures on
page 9-35)
HP pTAL Reference Manual—523746-006
C- 1
Differences Between the pTAL and EpTAL Compilers
Routines
Routines
Routine or Attribute
pTAL Compiler
EpTAL Compiler
INTERRUPT attribute
Not recognized
RETURN statement
Issues a warning if a
RETURN statement
includes both a
result-expression
and a cc-expression
(see Appendix D,
RETURN, RETURNSCC,
and C/C++ on TNS/E)
$AXADR routine
Not supported except as a
DEFINE name
$EXECUTEIO routine
Not supported
$FREEZE routine
Not supported except as a
DEFINE name. Use
$TRIGGER instead.
$HALT routine
Not supported except as a
DEFINE name. Use
$TRIGGER instead.
$INTERROGATEHIO routine
Not supported
$INTERROGATEIO routine
Not supported
$LOCATESPTHDR routine
Not supported
$LOCKPAGE routine
Not supported
$READBASELIMIT routine
Not supported
$READSPT routine
Not supported
$STACKALLOCATE routine
•
•
If size is not an
integral multiple of 8,
$STACK_ALLOCATE
rounds size up to the
next integral multiple of
8.
The returned value is
aligned to an 8-byte
boundary.
$UNLOCKPAGE routine
$TRIGGER routine
•
•
If size is not an
integral multiple of 16,
$STACK_ALLOCATE
rounds size up to the
next integral multiple of
16.
The returned value is
aligned to a 16-byte
boundary.
Not supported
Not supported
$UNLOCKPAGE routine
Not supported
$WRITEPTE routine
Not supported
HP pTAL Reference Manual—523746-006
C- 2
Differences Between the pTAL and EpTAL Compilers
Compiler Directives
Compiler Directives
Directive
pTAL Compiler
EpTAL Compiler
BEGINCOMPILATION
Ignored
SAVEGLOBALS
Not accepted
USEGLOBALS
Not accepted
CALL_SHARED
Default
NOCALL_SHARED
Default
Not accepted
GP_OK
Not accepted
NOGP_OK
Ignored
PUSHGP_OK
Ignored
POPGP_OK
Ignored
OPTIMIZEFILE
Does not issue warnings
for errors in filename
OVERFLOW_TRAPS
Default
Issues a warning when filename
meets one of the Conditions: on
page C-3
NOOVERFLOW_TRAPS
Default
SRL
Not accepted
TARGET
Default and only
accepted option is
TNS_R_ARCH
Default and only accepted option
is _TNS_E_TARGET
Conditions:
The EpTAL compiler issues a warning when the filename in OPTIMIZEFILE:
•
•
•
•
•
Does not exist
Cannot be opened
Is not an EDIT file (Guardian operating systems only)
Has the same routine-name on more than one line
Has a line that:
°
°
Exceeds 511 characters (Windows operating systems only)
°
°
Has an optimize-level other than 0, 1, or 2
Has a routine-name that does not match any routine declaration in the
source file
Has one or more characters other than spaces or tabs:
°
°
°
Before routine-name
After optimize-level
Between routine-name and optimize-level
HP pTAL Reference Manual—523746-006
C- 3
Differences Between the pTAL and EpTAL Compilers
HP pTAL Reference Manual—523746-006
C- 4
Compiler Directives
D
RETURN, RETURNSCC, and C/C++
on TNS/E
Read this appendix if you write or call pTAL procedures that:
•
•
Return both:
°
°
A traditional function value by means of the RETURN statement
An unrelated condition code value by means of the RETURNSCC attribute
And are called by C or C++ procedures
On the TNS architecture, a TAL procedure can return both a traditional function value
and an unrelated condition code value. Both return values are accessible after the
procedure call. pTAL procedures emulate this behavior on both the TNS/R and TNS/E
architectures, but C/C++ procedures do not.
On the TNS/R architecture, if a C/C++ procedure calls a pTAL procedure that returns
both a traditional function value and a condition code value, the C/C++ compiler issues
an error message.
Some programmers work around this C/C++ compile-time error by writing C/C++
prototypes that rely on the knowledge that on the TNS/R architecture, pTAL object
code stores the two return values in a single 64-bit value. After the C/C++ procedure
calls the pTAL procedure, it extracts from the 64-bit value either both return values
(see Example D-1 on page D-2) or only the traditional function value (see Example D-2
on page D-3).
Caution. C/C++ prototypes such as these are not guaranteed to work on the TNS/R
architecture, and extracting only the traditional function value (as in Example D-2 on page D-3)
does not work on the TNS/E architecture.
The EpTAL compiler issues a warning whenever a pTAL procedure returns both a
traditional function value and a condition code value. To migrate such a procedure to
TNS/E, HP recommends that you:
1. Write a pTAL shell procedure that returns the two values in the way that C/C++
returns them (in Example D-3 on page D-3, this procedure is P_SHELL).
2. Change the alias of the C/C++ prototype to the name of the pTAL shell procedure
in Step 1. (This change eliminates the need to change the calls to this prototype.)
3. Retire the original pTAL procedure linkage name. This allows the eld utility to
identify any uses of unchanged C/C++ prototypes, instead of producing an
executable program that uses the old prototypes (because the eld utility does not
produce an executable program if there are unresolved procedure references).
HP pTAL Reference Manual—523746-006
D- 1
RETURN, RETURNSCC, and C/C++ on TNS/E
Example D-1. C Procedure Extracting Two pTAL Return Values from a 64-Bit
Value (Works Only on TNS/R Systems—Not Recommended)
pTAL procedure with two return values:
int proc p (i, j, k) returnscc;
int(16)
i;
int(32) .ext j;
int(64)
k;
begin
...
return i, j < k; ! Traditional function value is the value of i.
! Expression j < k sets condition code.
end;
C/C++ prototype for accessing pTAL procedure:
_tal _alias ("P") long long some_name (short i, int* j, long long k);
C/C++ code that captures the 64-bit value:
typedef union val_cc_combo
{
long long combo;
struct
{
long value;
long condition_code;
} parts
} val_cc_combo
...
val_cc_combo.combo = some_name ();
C/C++ code that extracts the condition code from the 64-bit value:
(short)val_cc_combo.parts.value
val_cc_combo.parts.value
/* For 16-bit return value */
/* For 32-bit return value */
C/C++ code that extracts the two return values from the 64-bit value:
(short)val_cc_combo.parts.condition_code
/* Always 16-bits */
HP pTAL Reference Manual—523746-006
D- 2
RETURN, RETURNSCC, and C/C++ on TNS/E
Example D-2. C Procedure Extracting Only the Traditional Function Value from a
64-Bit Value (Works Only on TNS/R Systems)
pTAL procedure with two return values:
int proc p (i, j, k) returnscc;
int(16)
i;
int(32) .ext j;
int(64)
k;
begin
...
return i, j < k; ! Traditional function value is the value of i.
! Expression j < k sets condition code.
end;
C/C++ prototype for accessing pTAL procedure:
_tal _alias ("P") long some_name1 (short i, int* j, long long k);
Example D-3. Migrating a pTAL Procedure With Two Return Values to TNS/E
(Works on TNS/R and TNS/E Systems)
pTAL shell procedure that returns values in the way that C/C++ does:
int proc p_shell (result, i, j, k);
int(32) .
result;
int(16)
i;
int(32) .ext j;
int(64)
k;
begin
int cc;
result := p (i, j, k);
if < then
cc := -1D
else
if > then
cc := 1D
else
cc := 0D;
return cc;
end;
Declaration of pTAL procedure P in Example D-1 on page D-2 :
int proc p (i, j, k) returnscc;
int(16)
i;
int(32) .ext j;
int(64)
k;
begin
...
return i, j < k; ! Traditional function value is the value of i.
! Expression j < k sets condition code.
end;
C/C++ prototype for accessing pTAL shell procedure:
_tal _alias ("P_SHELL") short xyz
(int* result, short i, int* j, long long k);
HP pTAL Reference Manual—523746-006
D- 3
RETURN, RETURNSCC, and C/C++ on TNS/E
HP pTAL Reference Manual—523746-006
D- 4
Glossary
accelerate. To speed up emulated execution of a TNS object file by applying the
Accelerator for TNS/R system execution or the TNS Object Code Accelerator (OCA)
for TNS/E system execution before running the object file.
accelerated mode. See TNS accelerated mode.
accelerated object code. The MIPS RISC instructions (in the MIPS region) that result from
processing a TNS object file with the Accelerator or the Intel® Itanium® instructions (in
the Itanium instruction region) that result from processing a TNS object file with the
Object Code Accelerator (OCA).
accelerated object file. A TNS object file that, in addition to its TNS instructions (in the
TNS region) and symbol information (in the symbol region), has been augmented by
the Accelerator with equivalent but faster MIPS RISC instructions (in the MIPS region),
the Object Code Accelerator (OCA) with equivalent but faster Intel® Itanium®
instructions (in the Itanium instruction region), or both.
Accelerator. A program optimization tool that processes a TNS object file and produces an
accelerated object file that also contains equivalent MIPS RISC instructions (called the
MIPS region). TNS object code that is accelerated runs faster on TNS/R processors
than TNS object code that is not accelerated. See also TNS Object Code Accelerator
(OCA).
actual parameter. An argument that a calling procedure or subprocedure passes to a called
procedure or subprocedure. Compare to formal parameter.
addressing mode. The mode in which a variable is to be accessed—direct addressing or
extended addressing—as specified in the data declaration.
aligned. In native mode, a data item is aligned if its address is a multiple of its size; for
example, a 4-byte data item is aligned if its byte address is a multiple of four.
arithmetic expression. An expression that computes a single numeric value.
array. A variable that represents a collectively stored set of elements of the same data type
that are uniquely identified by a monotonically increasing integer with a user-specified
base integer.
assignment expression. An expression that stores a value in a variable.
assignment statement. A statement that stores a value in a variable.
ASSIGN command. An HP TACL command (available only on Guardian platforms) that lets
you associate a logical file name with an HP file name.
HP pTAL Reference Manual—523746-006
Glossary -1
Glossary
ASSIGN SSV command
ASSIGN SSV command. An HP TACL command (available only on Guardian platforms)
that lets you specify the node, system, volume, and subvolume from which the
compiler is to resolve incomplete file names specified in SEARCH, SOURCE, and
USEGLOBALS directives.
Binder. A programming utility that combines one or more compilation units’ TNS object
code files to create an executable TNS object code file for a TNS program or library.
Used only with TNS object files.
bit deposit. The assignment of a value to a bit field in a previously allocated STRING, INT,
INT(32), or UNSIGNED(1-31) variable, but not in an UNSIGNED(1-16) variable. A bitdeposit field has the form <n > or <n :n >. Deposits of 16 or fewer bits require an INT
value to be deposited. Deposits of more than 16 bits require an INT(32) value.
bit extraction. The access of a bit field in an INT expression [which can include STRING,
INT, INT(32), UNSIGNED(1-16), or UNSIGNED(1-31) variables]. A bit-extraction field
has the form <n > or <n :n >. Extractions of 16 or fewer bits yield an INT-typed value.
Extractions of 17 or more bits yield an INT(32)-typed value.
bit field. One of the following units:
•
•
An n-bit storage unit that is allocated for a variable of the UNSIGNED data type.
For an UNSIGNED simple variable, the bit field can be 1 to 31 bits. For an
UNSIGNED array element, the bit field can be 1, 2, 4, or 8 bits.
A bit field in the form <n > or <n :n >, used in bit deposit and bit extraction
operations.
bit shift. The shifting of bits within an INT or INT(32) expression a specified number of
positions to the left or right. An INT expression can consist of STRING, INT, or
UNSIGNED(1-16) values. An INT(32) expression can consist of INT(32) or
UNSIGNED(17-31) values.
bit-shift operators. Unsigned ('<<', '>>') or signed (<<, >>) operators that left shift or right
shift a bit field within an INT or INT(32) expression.
pTAL and epTAL implement arithmetic left shift (<<) as logical left shift ('<<'). The
arithmetic left shift operator (<<) causes a warning.
bitwise logical operator. The LOR, LAND, or XOR operator, which performs a bit-by-bit
operation on INT expressions.
blocked global data. Data you declare within BLOCK declarations. See BLOCK
declaration.
BLOCK declaration. A means by which you can group global data declarations into a
relocatable data block that is either shareable with all compilation units in a program or
private to the current compilation unit.
HP pTAL Reference Manual—523746-006
Glossary -2
Glossary
breakpoint
breakpoint. A location in a program at which execution is suspended so that you can
examine and modify the program state. Breakpoints are set by debugger commands.
byte. An 8-bit storage unit; the smallest addressable unit of memory.
central processing unit (CPU). Historically, the main data processing unit of a computer.
HP NonStop™ servers have multiple cooperating processors rather than a single CPU.
See also processor.
character string constant. A string of one or more ASCII characters that you enclose
within quotation mark delimiters. Also referred to as a character string.
CISC. See complex instruction set computing (CISC).
code segment. A segment that contains program instructions to be executed, plus related
information. Applications can read code segments but cannot write to them.
code space. A part of virtual memory that is reserved for user code, user library code,
system code, and system library code. The current code space of your process
consists of an optional library code space and a user code space.
Common Run-Time Environment. See CRE.
compilation unit. A source file plus source code that is read in from other source files by
SOURCE directives, which together compose a single input to the compiler.
complex instruction set computing (CISC). A processor architecture based on a large
instruction set, characterized by numerous addressing modes, multicycle machine
instructions, and many special-purpose instructions. Compare to reduced instruction
set computing (RISC) and explicitly parallel instruction set computing (EPIC).
condition code. A status returned by expressions and by some file system procedure calls
as follows:
Condition
Code
Meaning
Expression Status
CCG
Condition-code-greater-than
Positive
CCL
Condition-code-less-than
0
CCE
Condition-code-equal-to
Negative
conditional expression. An expression that establishes the relationship between values
and results in a true or false value; an expression that consists of relational conditions
and conditional operators.
constant. A number or a character string.
constant expression. An arithmetic expression that contains only constants, LITERALs,
and DEFINEs as operands. Constant expressions can be evaluated at compilation
time.
HP pTAL Reference Manual—523746-006
Glossary -3
Glossary
CPU
CPU. See central processing unit (CPU).
CRE. Common Run-Time Environment. Services that facilitate mixed-language programs.
data segment. A virtual memory segment holding data. Every process begins with its own
data segments for program global variables and runtime stacks (and for some libraries,
instance data). Additional data segments can be dynamically created.
DEFINE. An HP Tandem Advanced Command Language (TACL) command you can use to
specify a named set of attributes and values to pass to a process.
definition structure. A declaration that describes a structure layout and allocates storage
for the structure layout. Compare to referral structure and template structure.
direct addressing. Data access that requires only one memory reference and that is
relative to the base of the global, local, or sublocal area of the data space. Compare to
extended addressing.
DLL. See dynamic-link library (DLL).
doubleword. A 32-bit storage unit for the INT(32) or REAL data type.
dynamic-link library (DLL). A collection of procedures whose code and data can be loaded
and executed at any virtual memory address, with run-time resolution of links to and
from the main program and other independent libraries. The same DLL can be used by
more than one process. Each process gets its own copy of DLL static data.
entry point. An identifier by which a procedure can be called. The primary entry point is the
procedure identifier specified in the procedure declaration. Secondary entry points are
identifiers specified in entry-point declarations.
EPIC. See explicitly parallel instruction set computing (EPIC).
EpTAL compiler. The compiler that takes pTAL source code as input and generates either
TNS/R native object code or TNS/E native object code. Compare to pTAL compiler and
TAL compiler.
equivalenced variable. A declaration that associates an alternate identifier and description
with a location in a primary storage area.
executable object file. See loadfile.
explicitly parallel instruction set computing (EPIC). A processor architecture in which
the instruction stream encodes what can be done in parallel (so that the hardware
need not do this). Compare to complex instruction set computing (CISC) and reduced
instruction set computing (RISC).
expression. A sequence of operands and operators that, when evaluated, produces a
single value.
HP pTAL Reference Manual—523746-006
Glossary -4
Glossary
EXTDECS
EXTDECS. A file, provided by the operating system, that contains external declarations for
system procedures. System procedures, for example, manage files, activate and
terminate programs, and monitor the operations of processes.
extended addressing. Data access through an extended (32-bit) pointer. Compare to direct
addressing.
extended data segment. See selectable segment.
extended pointer. A 32-bit simple pointer or structure pointer. An extended pointer can
contain a 32-bit byte address of any location in virtual memory.
EXTENSIBLE procedure. A procedure that you declare using the EXTENSIBLE keyword; a
procedure to which you can add formal parameters without recompiling its callers; a
procedure for which the compiler considers all parameters to be optional, even if some
are required by your program. Compare to VARIABLE procedure.
EXTERNAL procedure declaration. A procedure declaration that includes the EXTERNAL
keyword and no procedure body; a declaration that enables you to call a procedure
that is declared in another source file.
file identifier. In the Guardian environment, the portion of a filename following the
subvolume name. In the Open System Services (OSS) environment, a file identifier is a
portion of the internal information used to identify a file in the OSS file system (an node
number). The two identifiers are not comparable.
filename. In the Open System Services (OSS) environment, a component of a pathname
containing any valid characters other than slash (/) or null. See also file name.
file name. A string of characters that uniquely identifies a file.
In the PC environment, file names for disk files normally have at least two parts (the
disk name and the file name); for example, B:MYFILE.
In the Guardian environment, disk file names include an Expand node name, volume
name, subvolume name, and file identifier; for example,
\NODE.$DISK.SUBVOL.MYFILE.
In the Open System Services (OSS) environment, a file is identified by a pathname; for
example, /usr/john/workfile. See also filename.
fileset. In the Open System Services (OSS) environment, a set of files with a common
mount point within the file hierarchy. A fileset can be part or all of a single virtual file
system.
On an HP NonStop™ system, the Guardian file system for an Expand node has a
mount point and is a subset of the OSS virtual file system. The entire Guardian file
system therefore could be viewed as a single fileset. However, each volume and each
process of subtype 30 within the Guardian file system is actually a separate fileset.
The term file system is often used interchangeably with fileset in UNIX publications.
HP pTAL Reference Manual—523746-006
Glossary -5
Glossary
file system
file system. In the Open System Services (OSS) environment, a collection of files and file
attributes. A file system provides the namespace for the file serial numbers that
uniquely identify its files. Open System Services provides a file system (see also
ISO/IEC IS 9945-1:1990 [ANSI/IEEE Std. 1003.1-1990], Clause 2.2.2.38); the
Guardian application program interface (API) provides a file system; and OSS Network
File System (NFS) provides a file system. (OSS NFS filenames and pathnames are
governed by slightly different rules than OSS filenames and pathnames.) Within the
OSS and OSS NFS file systems, filesets exist as manageable objects.
On an HP NonStop™ system, the Guardian file system for an Expand node is a subset
of the OSS virtual file system. Traditionally, the API for file access in the Guardian
environment is referred to as the Guardian file system.
In some UNIX and NFS implementations, the term file system means the same thing
as fileset. That is, a file system is a logical grouping of files that, except for the root of
the file system, can be contained only by directories within the file system. See also
fileset.
filler bit. A declaration that allocates a bit place holder for data or unused space in a
structure.
filler byte. A declaration that allocates a byte place holder for data or unused space in a
structure.
flat segment. A type of logical segment. Each flat segment has its own distinct address
range within the process address space that never overlaps the range of any other
allocated segments. Thus all allocated flat segments for a process are always available
for use concurrently. Compare to selectable segment.
formal parameter. A specification, within a procedure or subprocedure, of an argument that
is provided by the calling procedure or subprocedure. Compare to actual parameter.
FORWARD procedure declaration. A procedure declaration that includes the FORWARD
keyword but no procedure body; a declaration that allows you to call a procedure
before you declare the procedure body.
global variable. A variable that has global scope; that is, a variable that is declared at the
program level (not in a procedure or subprocedure). A global variable is visible
everywhere in the program after the point where it is declared. Compare to local
variable and sublocal variable.
group comparison expression. An expression that compares a variable with another
variable or with a constant.
high PIN. A process identification number (PIN) that is greater than 255. Compare to low
PIN.
home terminal. Usually the terminal from which a process was started.
HP pTAL Reference Manual—523746-006
Glossary -6
Glossary
HP Transaction Application Language (TAL)
HP Transaction Application Language (TAL). A systems programming language with
many features specific to stack-oriented TNS systems.
identifier. A name you declare for an object such as a variable, LITERAL, or procedure.
IF expression. An expression that selects the THEN expression for a true state or the
ELSE expression for a false state.
index. An element (byte, word, doubleword, or quadrupleword) offset or an occurrence
offset as follows:
•
•
•
Array index—an element offset from the zeroth element
Simple pointer index —an element offset from the address stored in the pointer
Structure or substructure index—an occurrence offset from the zeroth occurrence
indexing. Data access through an index appended to a variable name.
keyword. A term that has a predefined meaning to the compiler. A program cannot use a
keyword as an identifier.
label. An identifier you place before a statement for access by other statements within the
encompassing procedure, usually a GOTO statement.
LAND. A bitwise logical operator that performs a bitwise logical AND operation.
linkfile. An object file that requires linking with other object files before execution (also
called a nonexecutable object file). Compare to loadfile.
LITERAL. A declaration that associates an identifier with a constant.
loadfile. An object file that is ready for immediate execution. Compare to linkfile.
local variable. A variable that has local scope; that is, a variable that is declared in a
procedure (including its formal parameters). A local variable is visible everywhere in
the procedure that declares it (including within subprocedures of that procedure) after
the point where it is declared. Compare to global variable and sublocal variable.
logical operator. See bitwise logical operator.
logical segment. A single data area consisting of one or more consecutive 128-kilobyte
unitary segments that is dynamically allocated by a process. The two types of logical
segments are selectable segments and flat segments. See also selectable segment
and flat segment.
LOR. A bitwise logical operator that performs a bitwise logical OR operation.
low PIN. A process identification number (PIN) in the range 0 through 254. Compare to high
PIN.
HP pTAL Reference Manual—523746-006
Glossary -7
Glossary
misaligned
misaligned. In TNS mode and TNS accelerated mode, an erroneous address that is oddbyte aligned. In native mode, an inefficient address that is not aligned.
mixed-language program. A program that contains source files written in different HP
programming languages.
move statement. A statement that copies a group of elements from one location to another.
multidimensional array. A structure that contains nested substructures.
NAME declaration. A declaration that associates an identifier with a compilation unit (and
with its private global data block if any).
named data block. A BLOCK declaration that specifies a data-block identifier. The global
data declared within the BLOCK declaration is accessible to all compilation units in the
program. Compare to private data block.
Native Inspect. The HP interactive symbolic debugging tool for TNS/E programs. Compare
to Visual Inspect.
native mode. The operational environment in which Itanium and native-compiled RISC
instructions execute. Compare to TNS accelerated mode and TNS mode.
native object file. TNS/R or TNS/E object file.
nonexecutable object file. See linkfile.
NonStop Series architecture. See TNS architecture.
NonStop Series/Itanium architecture. See TNS/E architecture.
NonStop Series/RISC architecture. See TNS/R architecture.
object file. A file, generated by a compiler or binder, that contains machine instructions and
other information needed to construct the executable code spaces and initial data for a
process. The file can be a complete program ready for execution, or it can be
incomplete and require binding with other object files before execution. Compare to
source file.
offset. Represents, when used in place of an index, the distance in bytes of an item from
either the location of a direct variable or the location of the pointer of an indirect
variable, not from the location of the data to which the pointer points.
operand. A value that appears in an expression. An operand can be a constant, a variable
identifier, a LITERAL identifier, or a routine call.
operator. A symbol—such as an arithmetic or conditional operator—that performs a specific
operation on operands.
parameter. An argument that can be passed between procedures or subprocedures.
HP pTAL Reference Manual—523746-006
Glossary -8
Glossary
parameter mask
parameter mask. A means by which the compiler keeps track of which actual parameters
are passed by a procedure to an EXTENSIBLE procedure or VARIABLE procedure.
parameter pair. Two parameters connected by a colon that together describe a single data
type to some languages.
pathname. In the Open System Services (OSS) file system and Network File System
(NFS), the string of characters that uniquely identifies a file within its file system. A
pathname can be either relative or absolute. See also ISO/IEC IS 9945-1:1990
(ANSI/IEEE Std. 1003.1-1990 or POSIX.1), Clause 2.2.2.57.
PIC (position-independent code). Executable code that need not be modified to run at
different virtual addresses. External reference addresses appear only in a data area
that can be modified by the loader; they do not appear in PIC code. PIC is also called
shared code.
PIN. See process identification number (PIN).
pointer. A variable that contains the address of another variable. Pointers include simple
pointer and structure pointers that you declare and manage. See also extended pointer
and standard pointer.
position-independent code. See PIC (position-independent code).
private data block. A BLOCK declaration that specifies the PRIVATE keyword. Global data
declared within such a BLOCK declaration is accessible only to procedures within the
current compilation unit. Compare to named data block.
procedure. A program unit that can contain the executable parts of a program and that is
callable from anywhere in a program; a named sequence of machine instructions.
procedure declaration. Declaration of a program unit that can contain the executable parts
of a program and that is callable from anywhere in a program. Consists of a procedure
heading and either a procedure body or the keyword FORWARD or EXTERNAL.
process.
1. A program that has been submitted to the operating system for execution, or a
program that is currently running in the computer.
2. An address space, a single thread of control that executes within that address
space, and the system resources required by that thread of control.
process environment. The software environment that exists when the processor module is
executing instructions that are part of a user process or a system process.
process identification number (PIN). A number that uniquely identifies a process running
in a processor. The same number can exist in other processors in the same system.
HP pTAL Reference Manual—523746-006
Glossary -9
Glossary
processor
processor.
1. A functional unit of a computer that reads program instructions, moves data
between processor memory and the input/output controllers, and performs
arithmetic operations. Because a processor is composed of several hardware
components that reside in different enclosures, it is sometimes called a logical
processor. A processor is sometimes called a central processing unit (CPU), but
HP NonStop™ servers have multiple cooperating processors rather than a single
CPU.
2. One or more computer chips, typically mounted on a logic board, that are designed
to perform data processing or to manage a particular aspect of computer
operations.
program. See program file.
program file. An executable object code file containing a program’s main routine plus
related routines statically linked together and combined into the same object file. Other
routines shared with other programs might be located in separately loaded libraries. A
program file can be named on a RUN command; other code files cannot.
pTAL compiler. The compiler that takes pTAL source code as input and generates TNS/R
native object code. Compare to EpTAL compiler and TAL compiler.
public name. A specification within a procedure declaration of a procedure name to use in
Binder or the linker, not within the compiler. Only a D-series EXTERNAL procedure
declaration can include a public name. If you do not specify a public name, the
procedure identifier becomes the public name.
quadrupleword. A 64-bit storage unit for the REAL(64) or FIXED data type.
read-only array. An array that you can read but cannot modify.
redefinition. A declaration, within a structure, that associates a new identifier and
sometimes a new description with a previously declared item in the same structure.
reduced instruction set computing (RISC). A processor architecture based on a relatively
small and simple instruction set, a large number of general-purpose registers, and an
optimized instruction pipeline that supports high-performance instruction execution.
Compare to complex instruction set computing (CISC) and explicitly parallel instruction
set computing (EPIC).
reference parameter. An argument for which a calling procedure or subprocedure passes
an address to a called procedure or subprocedure. The called procedure or
subprocedure can modify the original argument in the caller’s scope. Compare to value
parameter.
referral structure. A declaration that allocates storage for a structure whose layout is the
same as the layout of a specified structure or structure pointer. Compare to definition
structure and template structure.
HP pTAL Reference Manual—523746-006
Glossary -10
Glossary
register
register. A facility that stores information about a running process. Registers include the
program register, the instruction register, the local register, the stack register, the
register stack, and the environment register.
relational operator. A signed (<, =, >, <=, >= <>) or unsigned ('<', '=', '>', '<=', '>=', '<>')
operator that performs signed or unsigned comparison, respectively, of two operands
and then returns a true or false state.
release version update (RVU). A collection of compatible revisions of NonStop OS
software products, identified by an RVU ID, and shipped and supported as a unit. An
RVU consists of the object modules, supporting files, and documentation for the
product revisions. An RVU also includes a set of documentation for the overall RVU.
RESIDENT procedure. A procedure you declare using the RESIDENT keyword; a
procedure that remains in main memory for the duration of program execution. The
operating system does not swap pages of RESIDENT code.
RISC. See reduced instruction set computing (RISC).
root operator. The last operator executed on the right side of an assignment statement.
RVU. See release version update (RVU).
scope. The set of levels—global, local, or sublocal—at which you can access each
identifier.
selectable segment. A type of logical segment formerly known as an extended data
segment. The data area for a selectable segment always begins with relative segment
4, and this area can be dynamically switched among several selectable segments by
calls to the Guardian SEGMENT_USE_ procedure. The effect is similar to a rapid
overlaying of one large data area. Compare to flat segment.
shared code. See PIC (position-independent code).
signal. The method by which an environment notifies a process of an event. Signals are
used to notify a process when an error that is not related to input or output has
occurred. A signal is often an indication of a run-time event that requires immediate
attention. Many such events preclude continuing the interrupted instruction stream.
Signals are generated for TNS/R native Guardian processes. (TNS Guardian
processes receive traps instead.) A SIGILL signal indicates that an instruction cannot
be executed because the instruction or its data are invalid. Compare to trap.
simple pointer. A variable that contains the address of a memory location, usually of a
simple variable or an array element, that you can access with this simple pointer.
simple variable. A variable that contains one item of a specified data type.
HP pTAL Reference Manual—523746-006
Glossary -11
Glossary
source file
source file. A file that contains source text such as data declarations, statements, compiler
directives, and comments. The source file, together with any source code read in from
other source files by SOURCE directives, compose a compilation unit that you can
compile into an object file.
SSV. See ASSIGN SSV command.
standard pointer. A 16-bit simple pointer or structure pointer. A standard pointer can
contain a 16-bit address.
structure. A variable that can contain different kinds of variables of different data types. A
definition structure, a template structure, or a referral structure.
structure data item. An accessible structure field declared within a structure, including a
simple variable, array, substructure, simple pointer, structure pointer, or redefinition.
Compare to structure item.
structure item. Any structure field, including a structure data item, a bit filler, or a byte filler.
structure pointer. A variable that contains the address of a structure that you can access
with this structure pointer.
sublocal variable. A variable that has sublocal scope; that is, a variable that is declared in
a subprocedure (including its formal parameters). A sublocal variable is visible only in
the subprocedure that declares it, after the point where it is declared. Compare to local
variable and global variable.
subprocedure. A named sequence of machine instructions that is nested (declared) within
a procedure and that is callable only from within that procedure.
substructure. A structure that is nested (declared) within a structure or substructure.
system. All the processors, controllers, firmware, peripheral devices, software, and related
components that are directly connected together to form an entity that is managed by
one HP NonStop™ operating system image and operated as one computer.
system procedure. A procedure provided by the operating system for your use. System
procedures, for example, manage files, activate and terminate programs, and monitor
the operations of processes.
TAL. See HP Transaction Application Language (TAL).
TAL compiler. The compiler that takes TAL or pTAL source code as input and generates
TNS object code. Compare to pTAL compiler and EpTAL compiler.
template structure. A declaration that describes a structure layout but allocates no storage
for the structure. Compare to definition structure and referral structure.
HP pTAL Reference Manual—523746-006
Glossary -12
Glossary
TNS accelerated mode
TNS accelerated mode. A TNS emulation environment on a TNS/R or TNS/E system in
which accelerated TNS object files are run. TNS instructions have been previously
translated into optimized sequences of MIPS or Intel® Itanium® instructions. TNS
accelerated mode runs much faster than TNS interpreted mode. Accelerated or
interpreted TNS object code cannot be mixed with or called by native mode object
code. See also TNS Object Code Accelerator (OCA). Compare to native mode.
TNS architecture. NonStop Series architecture. HP computers that are based on CISC
technology. TNS architecture implements the TNS instruction set.
TNS mode. The operational environment in which unaccelerated TNS instructions execute.
Compare to TNS accelerated mode and native mode.
TNS object code. The TNS instructions that result from processing program source code
with a TNS compiler. TNS object code executes on TNS, TNS/R, and TNS/E systems.
TNS Object Code Accelerator (OCA). A program optimization tool that processes a TNS
object file and produces an accelerated file for the TNS/E architecture. OCA augments
a TNS object file with equivalent Intel® Itanium® instructions. TNS object code that is
accelerated runs faster on TNS/E systems than TNS object code that is not
accelerated.
TNS/E architecture. NonStop Series/Itanium architecture. HP computers that are based on
Itanium technology. TNS/E architecture implements the Itanium instruction set
[explicitly parallel instruction set computing (EPIC)] and are upwardly compatible with
the TNS and TNS/R system-level architectures.
TNS/E native object code. The Intel®® Itanium® instructions that result from processing
program source code with a TNS/E native compiler. TNS/E native object code
executes only on TNS/E systems, not on TNS systems or TNS/R systems.
TNS/R architecture. NonStop Series/RISC architecture. HP computers that are based on
RISC technology. TNS/R architecture implements the RISC instruction set and are
upwardly compatible with the TNS system-level architecture.
TNS/R native object code. The MIPS RISC instructions that result from processing
program source code with a TNS/R native compiler. TNS/R native object code
executes only on TNS/R systems, not on TNS systems or TNS/E systems.
trap. A software interrupt that provides a way of handling certain events, such as detection
of a hardware (or software) fault, a timer expiration, or a lack of system resources. A
trap is often an indication of a run-time event that requires immediate attention. Most
such events preclude continuing the interrupted instruction stream. Traps are
generated for TNS Guardian processes. (TNS/R native Guardian processes receive
signals instead.) An Instruction Failure trap indicates that an instruction cannot execute
because the instruction or its data are invalid. Compare to signal.
HP pTAL Reference Manual—523746-006
Glossary -13
Glossary
value parameter
value parameter. An argument for which a procedure or subprocedure passes a value,
rather than the address of the argument, to a called procedure or subprocedure. The
called procedure or subprocedure can modify the passed value but not the original
argument in the caller’s scope. Compare to reference parameter.
variable. A symbolic representation of an item or a group of items or elements. A simple
variable, array, structure, simple pointer, structure pointer, or equivalenced variable. A
variable can store data that can change during program execution.
VARIABLE procedure. A procedure that you declare using the VARIABLE keyword; a
procedure to which you can add formal parameters but then you must recompile all its
callers; a procedure for which the compiler considers all parameters to be optional,
even if some are required by your code. Compare to EXTENSIBLE procedure.
virtual memory. A range of addresses that processes use to reference physical memory
and disk storage.
Visual Inspect. The HP interactive symbolic debugging tool for TNS/R programs. Compare
to Native Inspect.
white space. One or more space or tab characters.
word. An instruction-set-defined unit of memory that corresponds to the width of registers
and to the most common and efficient size of memory operations. A TNS word is
2 bytes (16 bits) wide, beginning on any 2-byte boundary in memory. A MIPS RISC
word is 4 bytes (32 bits) wide, beginning on any 4-byte boundary in memory. An Intel®
Itanium® word is also 4 bytes (32 bits) wide, beginning on any 4-byte boundary in
memory.
XOR. A bitwise logical operator that performs a bitwise exclusive OR operation.
HP pTAL Reference Manual—523746-006
Glossary -14
Index
A
ABS routine 15-22/15-23
Absolute value 15-22
Actual parameters
description of 12-11
checking for presence of 15-77
in CALL statement 12-10
of DEFINEs 6-7/6-9
Addition operator
signed (+)
in arithmetic expression 5-5
operand types for 5-6
precedence of 5-3
unsigned (’+’)
in arithmetic expression 5-5
operand types for 5-8
precedence of 5-3
result types for 5-9
with INT(32) operands 5-11
Address misalignment
causes of 4-1
handling 4-3
tracing facility for 4-1/4-2
Address symbols, base 2-7
Address types
description of 3-5/3-6
converting 3-7/3-9
stored in pointers 10-5/10-11
Addresses
See also Data addresses
arrays of 8-2
as parameters to built-in
routines 15-2/15-3
assignment of 16-15
extended 5-12
in simple pointers 10-14, 10-17
Addresses (continued)
in structure pointers
description of 10-17
within structures 9-52
nonextended 5-12
of structures declared in
subprocedures 9-39
types of
See Address types
Address-conversion routines 15-14
Aliases for data types 3-4
Alignment
base 9-9
of constant lists 3-22/3-23
of data 4-1/4-3
of structure fields 9-5/9-13
of structures
in depth 9-15
overview 9-4/9-5
of substructures 9-16/9-19
ALPHA routine 15-23/15-24
AND operator
description of 5-17
condition codes and 5-18
in conditional expression 5-15
operand types for 5-17
precedence of 5-4
truth table for 5-15
Angle brackets (< >) 2-4
ar utility 18-6
Architecture and RVUs 1-2
Arguments 17-3
See also Parameters
Arithmetic expressions 5-5/5-6
Arithmetic operators
signed
description of 5-6/5-7
in arithmetic expressions 5-5
HP pTAL Reference Manual—523746-006
Index -1
Index
A
Arithmetic operators (continued)
unsigned
description of 5-8/5-11
in arithmetic expressions 5-5
Arithmetic overflow testing 15-76
Arrays
description of 8-1
alignment of, in structures 9-13/9-15
as parameters 14-13, 14-14
data type of 15-88
declaring
in structures 9-40/9-41
read-only 8-6/8-7
read-write 8-2/8-5
elements of
accessing 3-9
number of 15-69
length of
in bits 15-28
in bytes 15-59
nonstring 8-9
number of elements of 15-69
of addresses 8-2
redefining 9-55/9-56
ASCII characters
set of 2-2
testing for
alphabetic 15-23
numeric 15-68
special (nonalphanumeric) 15-85
ASCIITOFIXED routine 15-24/15-25
ASSERT statement 12-3/12-4
ASSERTION directive 17-19/17-20
ASSIGN command
description of B-7
ordinary B-8
search subvolume (SSV) B-9/B-10
Assignment operator (:=) 5-4
See also Assignments
Assignments
description of 12-4/12-6
bit-deposit 12-9/12-10
character string 12-7
expressions in 5-20/5-21
FIXED variable 12-7
hardware indicators after 13-3/13-8
initial 7-1
move statement 12-28/12-33
number 12-7
of addresses 16-15
pointer 12-6
procedure pointer 14-33/14-34
Asterisk (*)
as multiplication operator
See Multiplication operator
in compiler listing 17-42
in constant lists 2-5
in template structures 9-36
in value parameter 2-6
in $ASCIITOFIXED routine 15-25
in $FIXEDTOASCII routine 15-45
in $FIXEDTOASCIIRESIDUE
routine 15-46, 15-47
to prevent scaling
of FIXED initialization value 3-4
of FIXED parameter 14-11/14-12
Atomic operations
description of 15-4
data misalignment and 4-1, 4-3
ATOMIC_ADD routine 15-5
ATOMIC_AND routine 15-6
ATOMIC_DEP routine 15-7/15-8
ATOMIC_GET routine 15-8
ATOMIC_OR routine 15-9
ATOMIC_PUT routine 15-10
Attributes
block 13-2/13-3
procedure 14-5/14-9
SCF user interface 4-3
HP pTAL Reference Manual—523746-006
Index -2
Index
B
AUTO parameter
description of 9-7
compared to PLATFORM
parameter 9-8
FIELDALIGN clause and 9-5/9-6
AXADR routine 15-26
B
Backslash (\)
See Remainder operator (’\’)
BADDR address type
description of 10-6
converting 3-9
parameters of 14-11
STRING pointers of 10-9
BADDR_TO_EXTADDR
routine 15-26/15-27
BADDR_TO_WADDR routine 15-27
Base address symbols 2-7
Bases of constants 2-12
BEGIN keyword
in compound statement 12-2
in procedure 14-17
in structure 9-3
in subprocedure 14-21
BEGINCOMPILATION directive
description of 17-20
and global data
declarations 17-8/17-13
SOURCE directive and 17-63
BEGIN-END construct
See Compound statements
Bit fields
description of 3-1
delimiting 2-4
Bit operations
description of 1-6, 5-31
bit-deposit assignment
statement 12-9/12-10
extraction 5-31/5-32
Bit operations (continued)
logical 5-10
precedence of 5-3
shift 5-33/5-35
BITLENGTH routine 15-28
BITOFFSET routine 15-29
Bitwise logical operators 5-10
Bit-deposit assignment
statement 12-9/12-10
BIT_FILLER declaration 9-46/9-47
Block attributes 13-2/13-3
BLOCKGLOBALS directive 17-21/17-22
Blocks, data
See Global data, blocked
Boolean expressions
See Conditional expressions
Brackets
angle (< >) 2-4
square ([ ]) 2-4
Built-in routines 15-1
See also Atomic operations
See also Nonatomic operations
BY keyword in FOR statement 12-20
Bytes 3-1
C
C procedure attribute 14-5
CALL statement 12-10/12-12
CALLABLE procedure attribute 14-5, 14-6
CALL_SHARED directive 17-22
CARRY routine
description of 15-30
after assignments 13-4
atomic operation that can set 15-4
in nested IF statements 13-12/13-13
nonatomic operations that can
set 15-20/15-22
returning its value to calling
procedure 13-16
CASE expressions 5-21/5-22
HP pTAL Reference Manual—523746-006
Index -3
Index
C
CASE statement
description of 12-12
empty 12-12
labeled 12-13/12-15
unlabeled 12-15/12-17
CBADDR address type
description of 10-6
converting 3-9
parameters of 14-11
pointers of 10-10
Character set for pTAL 2-2
Character string constants 3-12/3-13
Character-test routines 15-14
CHECKSHIFTCOUNT directive 17-23
CHECKSUM routine 15-31/15-32
COBOL procedure attribute 14-5
Code Coverage Tool 16-17
CODECOV directive 17-24
Codes
completion 16-6
condition
See Condition codes
Colon (:) 2-4
COLUMNS directive
description of 17-24/17-25
SOURCE directive and 17-62
Comma (,) 2-4
Commands
ASSIGN
See ASSIGN command
compilation
See Compilation command
DEFINE
See DEFINEs
Deploy 18-7
Comments, delimiters for 2-4
Common run-time environment (CRE)
services 1-7
COMP routine 15-32
Compatibility of pTAL and TAL 1-1
Compilation command
description of 16-4/16-6
with compiler directives 17-1
Compilation units, naming 16-13
Compiler directives
interpretation and processing of 17-1
specifying
in compilation command line 17-1
in source code 17-2/17-3
summary of 17-13/17-19
Compiler input directives 17-14
Compiler listing
asterisk (*) in 17-42
conditionally compiled lines and 17-42
directives that affect 17-14
Compiler listing directives 17-14
Compilers
comparison of EpTAL, pTAL, and
TAL 1-2
differences between pTAL and
EpTAL C-1/C-3
Completion codes 16-6
Compound statements
syntax of 12-2/12-3
within DEFINE bodies 6-4
Concatenation operator (&) 12-30
Condition codes
See also Hardware indicators
after assignments 13-4/13-8
AND operator and 5-18
atomic operations that can set 15-4
C/C++ procedures on TNS/E and D-1
group comparisons and 5-29/5-30
nesting 13-12/13-14
nonatomic operations that
alter 15-17/15-22
NOT operator and 5-18
OR operator and 5-18
HP pTAL Reference Manual—523746-006
Index -4
Index
D
Condition codes (continued)
returning
with RETURN statement 12-35
with RETURNSCC attribute
in procedure 14-5/14-8
in subprocedure 14-19/14-20
testing after function calls 12-35/12-36
Conditional compilation directives 17-17
Conditional expressions
description of 5-15/5-17
hardware indicators in 13-8/13-12
Constant expressions
description of 5-14
as parameters 14-14
in data type specifications 3-3
Constant lists
description of 3-21/3-22
aligning 3-22/3-23
in array declarations 8-8/8-9
in move statement 12-28
Constants
See also LITERALs
comparing to data addresses 3-11
description of 2-12
in expressions
See Constant expressions
lists of
See Constant lists
numeric bases of 2-12
Continuation lines 17-3
Conventions for syntax diagrams -xxxvii/-xl
Conversion
between address types 3-7/3-9
between addresses and numbers 3-7
implicit 3-8
Copy operation (move
statement) 12-28/12-33
COUNTDUPS routine 15-33/15-34
CRE services 1-7
Cross compilers
ar utility and 18-6
compiling with 18-5
debugging and 18-6, 18-7
documentation for 18-8
features of 18-1
file extension for 18-1
from PC command line 18-3
in ETK 18-2
linking and 18-5
PC-to-NonStop host transfer tools
for 18-7
platforms for 18-1
CWADDR address type
description of 10-6
converting 3-9
parameters of 14-11
pointers of 10-10
C-series RVU 1-2
C/C++ procedures D-1
D
Data
alignment of 4-1/4-3
blocks of
See Global data, blocked
global
See System global data
misaligned
See Address misalignment
operations on 1-6
representation of 3-1
scanning 12-1
sets of 1-5
system global
See System global data
transferring
statements for 12-1
HP pTAL Reference Manual—523746-006
Index -5
Index
D
Data (continued)
types of
See Data types
Data addresses
arithmetic operations on 3-10/3-11
comparing
description of 5-11
extended addresses 5-12
nonextended addresses 5-12/5-14
to constants 3-11
to procedure pointers 3-11
computing distance between 3-11
converting to numbers 3-7
decrementing 3-10
incrementing 3-10
storing in variables 3-7
Data allocation statements 12-1
Data types
See also Address types
aliases for 3-4
changing, with group
comparisons 5-27/5-28
obtaining 15-88
of expressions 5-2
pTAL
description of 3-1/3-2
compared to TAL 1-5
specifying 3-3/3-4
DBL routine 15-34/15-35
DBLL routine 15-35
DBLR routine 15-36
Debugging
cross compilers and 18-6, 18-7
Enterprise Toolkit (ETK) and 18-6
OPTIMIZE directive and 17-47
with ASSERTION directive and
ASSERT statement 12-3/12-4
Decimal point, implied
See Implied decimal point
Declarations
description of 2-8
array
See Arrays, declaring
BIT_FILLER 9-46/9-47
DEFINE 6-3/6-5
entry point 14-22/14-25
equivalenced
See Equivalenced variables,
declaring
external 17-63
FILLER 9-46/9-47
function
See Procedures, declaring
global
See Global data
LITERAL 6-1/6-3
NAME 16-13
pointer
See Pointers, declaring
procedure
See Procedures, declaring
simple variable
See Simple variables, declaring
structure
See Structures, declaring
sublocal 14-21
subprocedure
See Subprocedures, declaring
substructure
See Substructures, declaring
Default misalignment handling method 4-3
Default target file 16-6
DEFAULTS DEFINE B-7
DEFEXPAND directive
description of 17-26/17-27
output of 6-6
position of 6-4
DEFINE files 18-1
DEFINE tool 18-7
HP pTAL Reference Manual—523746-006
Index -6
Index
E
DEFINEs
calling 6-5/6-6
CLASS attributes of B-5
declaring 6-3/6-5
expansion of 6-6
how compiler processes 6-6
LITERAL declarations and 6-1
names of B-5
parameters of
actual 6-7/6-9
formal 6-3
substituting file names for B-5
DEFINETOG directive 17-27/17-28
Definition structures, declaring
equivalenced 11-24/11-25
not equivalenced 9-33/9-35
Definition substructures
declaring 9-42/9-44
redefining 9-56/9-59
Delimiters 2-4/2-5
Deploy command 18-7
DFIX routine 15-36/15-37
Diagnostics directives 17-15
Directive stacks 17-4/17-5
DISABLE_OVERFLOW_TRAPS block
attribute 13-2/13-3
Disk file names
description of B-1/B-2
as compiler directive arguments 17-3
ASSIGN command and B-7
internal B-4
logical B-4
partial B-3/B-4
parts of B-2/B-3
substituting for DEFINE commands B-5
Division operator
signed (⁄
)
in arithmetic expression 5-5
operand types for 5-6
precedence of 5-3
Division operator (continued)
unsigned (’⁄
’)
in arithmetic expression 5-5
operand types for 5-9
precedence of 5-3
result types for 5-9
with INT(32) and FIXED
operands 5-11
DLLs (dynamic-link libraries) 16-12
DO keyword
in DO-UNTIL statement 12-17
in FOR statement 12-20
in WHILE statement 12-45
Dollar sign ($) 2-5
Doublewords 3-1
DOWNTO keyword 12-20
DO-UNTIL statement
description of 12-17/12-19
hardware indicators in 13-8
DO_TNS_SYNTAX directive 17-28/17-29
DROP statement 12-19/12-20
Dynamically selected procedure
calls 14-35/14-36
Dynamic-link libraries (DLLs) 16-12
D-series RVU 1-2
E
EFLT routine 15-37
EFLTR routine 15-38, 15-38/15-39
eld utility
ar utility and 18-7
migrating to TNS/E and D-1
Ellipsis (...) 12-13
ELSE keyword 12-26
Embedded SQL/MP or SQL/MX 1-3
Empty CASE statement 12-12
EMS (Event Management Service) 4-2
ENABLE_OVERFLOW_TRAPS block
attribute 13-2/13-3
HP pTAL Reference Manual—523746-006
Index -7
Index
E
END keyword
in compound statement 12-2
in procedure 14-17
in structure 9-3
in subprocedure 14-21
ENDIF directive 17-29/17-30
Enterprise Toolkit (ETK)
cross compilers and 18-2
debugging and 18-6
DEFINE files and 18-1
online help for 18-8
Entry points
declaring 14-22/14-25
procedure 10-10
subprocedure 10-10
Equal sign
as delimiter 2-5
as equal operator
signed (=)
in conditional expression 5-18
operand types for 5-18
precedence of 5-4
without operands 5-19
unsigned (’=’)
in conditional expression 5-18
operand types for 5-19
precedence of 5-4
with INT(32) operands 5-10
without operands 5-19
Equivalenced variables
description of 11-1/11-2
declaring
description of 11-2/11-3
nonstructure 11-5/11-15
system global 11-22/11-29
memory allocation for 11-4
Error messages
logging to a file 17-30
maximum allowed 17-33
ERRORFILE directive 17-30/17-32
ERRORS directive 17-33
ETK
See Enterprise Toolkit (ETK)
Event Management Service (EMS) 4-2
EXCHANGE routine 15-39
Exclamation mark (!) 2-4
Executable statements
See Statements
EXECUTEIO routine 15-40/15-41
Exporting program names 16-12
EXPORT_GLOBALS directive 17-34
Expressions
description of 5-1
arithmetic 5-5/5-6
as parameters to built-in routines 15-3
assignment 5-20/5-21
Boolean (conditional) 5-15/5-17
CASE 5-21/5-22
conditional 5-15/5-17
constant
description of 5-14
as parameters 14-14
in data type specifications 3-3
data types of 5-2
group comparison
See Group comparison expressions
IF 5-23/5-24
special 5-20
EXTADDR address type
description of 10-6
comparing 5-12
converting 3-9
parameters of 14-11
pointers of 10-11
EXTADDR_TO_BADDR routine 15-41
EXTADDR_TO_WADDR routine 15-42
EXTDECS file 17-63
Extended addresses 5-12
Extended parameters 14-16
HP pTAL Reference Manual—523746-006
Index -8
Index
F
EXTENSIBLE procedure attribute 14-5,
14-7
External declarations 17-63
EXTERNAL keyword
in procedure declaration 14-2, 14-4
in procedure entry-point
declaration 14-23
Extracting bits 5-31/5-32
F
FAIL misalignment handling method 4-3
FIELDALIGN clause
description of 9-20
role in field alignment 9-5/9-6
FIELDALIGN directive
description of 9-20, 17-35
role in field alignment 9-5/9-6
File IDs B-3
File names
See Disk file names
Files
DEFINE 18-1
EXTDECS 17-63
input 16-3
map of 17-36
OBJECT 16-6
object
See Object files
output 16-3
source
See Source files
target 16-6
temporary B-7
FILL16 procedure 15-42/15-43
FILL32 procedure 15-42/15-43
FILL8 procedure 15-42/15-43
FILLER declaration 9-46/9-47
FIX routine 15-44
FIXD routine 15-44/15-45
FIXED data type
See also FIXED variables
built-in routines for 15-15
constants of 3-17/3-18
functions that return values of 14-12
obtaining
with $DFIX routine 15-36
with $FIX routine 15-44
with $FIXD routine 15-44
with $FIXR routine 15-48
with $IFIX routine 15-52
with $LFIX routine 15-60
parameters of 14-11, 14-12
rounding and 15-13
FIXED variables
See also FIXED data type
assigning numbers to 12-7
rounding 17-55
scaling
description of 5-7
when assigning numbers to 12-7
using 5-8
FIXEDTOASCII routine 15-45/15-46
FIXEDTOASCIIRESIDUE
routine 15-46/15-47
FIXED(0) data type
See FIXED data type
Fixed-point scaling 12-7
FIXERRS macro 17-30/17-32
FIXI routine 15-47/15-48
FIXL routine 15-48
FIXR routine 15-48/15-49
FLT routine 15-49/15-50
FLTR routine 15-50
FMAP directive 17-36
FOR keyword
in FOR statement 12-20
in move statement 12-28
HP pTAL Reference Manual—523746-006
Index -9
Index
G
FOR statement
description of 12-20/12-21
nested 12-21
optimized 12-22
standard 12-21
Formal parameters
indirection symbols and 2-7
of DEFINEs 6-3
of procedures 14-3, 14-10
of subprocedures 14-10, 14-19
passing by reference 2-7
procedure pointers as 14-26, 14-32
specifying 14-10/14-15
FORTRAN procedure attribute 14-5
FORWARD keyword
in procedure declaration 14-2, 14-4
in procedure entry-point
declaration 14-23
in subprocedure declaration 14-19,
14-21
in subprocedure entry-point
declaration 14-24
fpoint
changing 15-82
obtaining 15-78
rounding 17-55
scaling 12-7
specifying 15-60
FREEZE routine 15-51
Functions
See also Procedures
See also Routines
atomic
See Atomic operations
definition of 14-1
RETURN statement and 12-34
with two return values D-1/D-3
G
Global data
See also System global data
blocked
allocating 16-15
declaring 16-12/16-15
SECTION directive and 16-16
sharing 16-16
SOURCE directive and 16-16
map of 17-37
saving and using 17-8/17-13
unblocked 16-14
Global scope 2-10
GLOBALIZED directive 17-36
GMAP directive 17-37
GOTO statement 12-23/12-25
GP_OK directive 17-38/17-39
Greater than operator
signed (>)
in conditional expression 5-18
operand types for 5-18
precedence of 5-4
without operands 5-19
unsigned (’>’)
in conditional expression 5-18
operand types for 5-19
precedence of 5-4
with INT(32) operands 5-10
without operands 5-19
Greater than or equal operator
signed (>=)
in conditional expression 5-18
operand types for 5-18
precedence of 5-4
without operands 5-19
unsigned (’>=’)
in conditional expression 5-18
operand types for 5-19
precedence of 5-4
HP pTAL Reference Manual—523746-006
Index -10
Index
H
Greater than or equal operator
unsigned (’>=’) (continued)
with INT(32) operands 5-10
without operands 5-19
Group comparison expressions
description of 5-24/5-27
for changing data types 5-27/5-28
testing 5-29/5-30
H
HALT routine 15-51
Hardware indicators
See also Condition codes
across procedures 13-14/13-16
after assignments 13-3/13-8
built-in routines and 15-4
in conditional expressions 13-8/13-12
list of 13-1
Hash mark (#) 2-5
HIGH routine 15-52
HP TACL commands
description of B-4
ASSIGN
See ASSIGN command
DEFINE
See DEFINEs
RUN 16-4
Hybrid executable object files 16-11
Hyphen (-)
followed by hyphen (-) 2-4
followed by right angle bracket (>) 2-5
I
Identifiers
description of 2-8/2-9
classes of 2-9
listing
with GMAP directive 17-37
with MAP directive 17-45
Identifiers
listing (continued)
with PRINTSYM directive 17-52
saving 17-66
IF and IFNOT directives 17-39/17-42
IF expressions 5-23/5-24
IF statement
See also Conditional expressions
description of 12-26/12-27
hardware indicators in 13-8
IFIX routine 15-52/15-53
Implicit address conversion 3-8
Implied decimal point
ignoring
with $FIXD routine 15-45
with $FIXI routine 15-47
with $FIXL routine 15-48
in data type declarations 3-3
in formal parameters 14-12
in simple variable declarations 7-2
moving 15-82
obtaining
with $DFIX routine 15-37
with $IFIX routine 15-53
with $LFIX routine 15-60
parentheses and 2-4
IN file option 16-4
Indexes, accessing array elements with 3-9
Indirection symbols 2-7
Initialization
of exported data 17-34
of read-only arrays 8-7
of simple pointers 10-14/10-16
of structure pointers 10-17/10-19
scope and 2-11
INNERLIST directive 17-42/17-43
Input files 16-3
Instruction codes, listing 17-42
HP pTAL Reference Manual—523746-006
Index- 11
Index
K
INT data type
constants of 3-15
converting 3-9
functions that return values of 14-12
high-order word of 15-52
parameters of 14-11, 14-12
rounding and 15-13
signed value of 15-47
unsigned value of 15-48
$INTR routine and 15-58
INT routine 15-53/15-54
Internal file names B-4
INTERROGATEHIO routine 15-55/15-56
INTERROGATEIO routine 15-57/15-58
INTERRUPT procedure attribute 14-5, 14-6
INTR routine 15-58/15-59
INT(16) data type
See INT data type
INT(32) address type
bitwise logical operators and 5-10/5-11
converting 3-9
obtaining
with $DBLL routine 15-35
with $DBLR routine 15-36
with $UDBL routine 15-89
unsigned operators and 5-10/5-11
INT(32) data type
constants of 3-16/3-17
rounding and 15-13
INT(64) data type
See INT data type
INT_OV routine 15-54/15-55
INVALID_FOR_PTAL directive 17-43
Itanium architecture
See TNS/E architecture
K
Keywords
description of 2-2
in syntax diagrams -xxxviii
Keywords (continued)
nonreserved 2-3/2-4
reserved 2-3
L
Labeled CASE statement 12-13/12-15
Labels
address types of 10-10
dropping 12-19
in procedures 14-37
LAND operator
in arithmetic expression 5-5
operand types for 5-10
precedence of 5-3
with INT(32) operands 5-10
$ATOMIC_AND routine and 15-6
$ATOMIC_DEP routine and 15-7
LANGUAGE procedure attribute 14-5/14-8
ld utility 18-7
Least significant byte 3-1
Left-to-right move (:=) 12-28
LEN routine 15-59/15-60
Length parameters
in CALL statements 12-11
in declarations
procedure 14-3
procedure pointer 14-28
subprocedure 14-20
passing conditionally 15-74
Less than operator
signed (<)
in conditional expression 5-18
operand types for 5-18
precedence of 5-4
without operands 5-19
unsigned (’<’)
in conditional expression 5-18
operand types for 5-19
precedence of 5-4
HP pTAL Reference Manual—523746-006
Index -12
Index
M
Less than operator
unsigned (’<’) (continued)
with INT(32) operands 5-10
without operands 5-19
Less than or equal operator
signed (<=)
in conditional expression 5-18
operand types for 5-18
precedence of 5-4
without operands 5-19
unsigned (’<=’)
in conditional expression 5-18
operand types for 5-19
precedence of 5-4
with INT(32) operands 5-10
without operands 5-19
LFIX routine 15-60/15-61
Libraries
dynamic-link (DLLs) 16-12
user 17-65
LINES directive 17-44
Linking
description of 16-7/16-11
cross compilers and 18-5
LIST directive
description of 17-44/17-45
SOURCE directive and 17-62
LITERAL declarations 6-1/6-3
LMAX routine 15-61
LMIN routine 15-61/15-62
Local GOTO statement 12-23
Local scope 2-10
LOCATESPTHDR routine 15-62/15-63
LOCKPAGE routine 15-63/15-64
Logical file names
ASSIGN command and B-7
compiler directives that accept 17-3
in place of disk file names B-4
Logical operators
bitwise 5-10
in arithmetic expressions 5-5
with INT(32) operands 5-10
longjmp() instruction 9-1
Loops
FOR
See FOR statement
WHILE
See WHILE statement
LOR operator
in arithmetic expression 5-5
operand types for 5-10
precedence of 5-3
with INT(32) operands 5-10
$ATOMIC_DEP routine and 15-7
$ATOMIC_OR routine and 15-9
M
MAIN procedure attribute 14-5
MAP DEFINE B-6
MAP directive 17-45/17-46
MAX routine 15-64
MAXALIGN attribute 9-37
Maximum routines 15-15
Messages, error
See Error messages
MIN routine 15-64/15-65
Minimum routines 15-15
Minus sign (-)
as subtraction operator
See Subtraction operator
as unary operator
operand types for 5-6
precedence of 5-3
syntax of 5-5
MISALIGNLOG attribute (SCF)
misalignment handling and 4-3
misalignment tracing facility and 4-1
HP pTAL Reference Manual—523746-006
Index -13
Index
N
Misalignment
See Address misalignment
Mnemonics, listing 17-42
Modular programming 1-6
Most significant byte 3-1
Move statement 12-28/12-33
MOVEANDCXSUMBYTES
routine 15-65/15-66
MOVENONDUP routine 15-67/15-68
Multiplication operator
signed (*)
description of 2-6
in arithmetic expression 5-5
operand types for 5-6
precedence of 5-3
unsigned (’*’)
description of 2-6
operand types for 5-8
precedence of 5-3
result types for 5-9
with INT(32) operands 5-11
N
NAME declarations 16-13
Named toggles 17-6
Naming compilation units 16-13
NATIVEATOMICMISALIGN attribute
(SCF) 4-3
Nesting condition codes 13-12/13-14
Next address
in move statement 12-28
in RSCAN statement 12-40
in SCAN statement 12-40
nld utility 18-7
Node names B-2
NOname directive
See name directive
Nonatomic access 4-3
Nonatomic operations 15-11, 15-17/15-22
Nonextended addresses 5-12
Nonlocal GOTO statement 12-24
Nonreserved keywords 2-3/2-4
NonStop EpTAL 18-2
NonStop operating systems 1-2
NonStop pTAL 18-2
NonStop Series
See TNS architecture
NonStop Series/Itanium
See TNS/E architecture
NonStop Series/RISC
See TNS/R architecture
Nonstring arrays 8-9
NOOVERFLOW_TRAPS procedure
attribute
description of 13-2
in procedure 14-5, 14-8
in subprocedure 14-19, 14-20
Not equal operator
signed (<>)
in conditional expression 5-18
operand types for 5-18
precedence of 5-4
without operands 5-19
unsigned (’<>’)
in conditional expression 5-18
operand types for 5-19
precedence of 5-4
with INT(32) operands 5-10
without operands 5-19
NOT operator
description of 5-17
condition codes and 5-18
in conditional expression 5-15
operand types for 5-17
precedence of 5-4
truth table for 5-15
Null statement 12-2
Numbers, converting to data addresses 3-7
NUMERIC routine 15-68
Numeric toggles 17-6
HP pTAL Reference Manual—523746-006
Index -14
Index
O
O
OBJECT file 16-6
Object files
content directives for 17-16
creating 16-7/16-11
generating 16-4
hybrid 16-11
linking 16-7/16-11
OCCURS routine 15-69/15-71
Odd-byte references 10-14, 10-17
OF keyword
in labeled CASE statement 12-13
in unlabeled CASE statement 12-15
OFFSET routine
description of 15-71/15-73
structure pointers and 10-18
Online help for cross compilers 18-8
Operands
in arithmetic expressions 5-5
scaling FIXED 5-7
Operating systems 1-2
Operations
See also Operators
atomic
See Atomic operations
bit
See Bit operations
data 1-6
listed by data type 3-4
nonatomic
See Nonatomic operations
Operators
description of 2-5/2-6
AND
description of 5-17
condition codes and 5-18
arithmetic
See Arithmetic operators
concatenation (&) 12-30
Operators (continued)
logical
description of 5-10
in arithmetic expressions 5-5
NOT
description of 5-17
condition codes and 5-18
OR
description of 5-17
condition codes and 5-18
precedence of 5-3/5-4
relational
See Relational operators
signed
See Signed operators
unsigned
See Unsigned operators
OPTIMIZE directive 17-47
OPTIMIZEFILE directive 17-47/17-49
Optional parameters 15-73/15-76
OPTIONAL routine 15-73/15-76
OR operator
description of 5-17
condition codes and 5-18
in conditional expression 5-15
operand types for 5-17
precedence of 5-4
truth table for 5-15
OTHERWISE keyword
in labeled CASE statement 12-13
in unlabeled CASE statement 12-15
OUT file option 16-4
Output files 16-3
Overflow
managing
generally 13-1/13-3
GOTO statement and 12-24/12-25
testing 15-76
HP pTAL Reference Manual—523746-006
Index -15
Index
P
OVERFLOW routine
description of 15-76/15-77
after assignments 13-3/13-4
atomic operation that can set 15-4
in nested IF statements 13-12/13-13
nonatomic operations that can
set 15-17/15-22
returning its value to calling
procedure 13-16
OVERFLOW_TRAPS
directive 17-49/17-50
OVERFLOW_TRAPS procedure attribute
description of 13-2
in procedure 14-5, 14-8
in subprocedure 14-19, 14-20
P
PAGE directive 17-51
Page heading 17-51
PARAM routine 15-77
PARAM SWAPVOL command B-7
Parameters
See also Arguments
actual
See Actual parameters
extended 14-16
formal
See Formal parameters
of built-in routines 15-2/15-3
optional 15-73/15-76
referencing 14-16
Parentheses
as delimiters 2-4
implied decimal point and 2-4
operator precedence and 5-4
Partial file names
description of B-3/B-4
ASSIGN SSV command and B-9
PASCAL procedure attribute 14-5
PC-to-NonStop host transfer tools 18-7
Period (.)
in bit-deposit assignment
statement 12-9
in formal parameters 14-10, 14-13
in pointers
procedure 14-28
simple 10-12
structure 10-16
in structure item identifiers 2-4
in structures
equivalenced definition 11-24
referral 9-38
PIC
See Position-independent code (PIC)
PLATFORM parameter
description of 9-7
compared to AUTO parameter 9-8
FIELDALIGN clause and 9-5/9-6
Plus sign (+)
as addition operator
See Addition operator
as unary operator
in arithmetic expression 5-5
operand types for 5-6
precedence of 5-3
POINT routine 15-78
Pointers
description of 1-6
address types stored in 10-5/10-11
allocation of 10-1
assignment statements with 12-6
declaring
overview 10-2/10-4
procedure
See Procedure pointers,
declaring
simple
See Simple pointers, declaring
HP pTAL Reference Manual—523746-006
Index -16
Index
P
Pointers
declaring (continued)
structure
See Structure pointers,
declaring
system global
See System global data,
declaring, pointers
VOLATILE 10-4
procedure
See Procedure pointers
simple
See Simple pointers
stepping 3-10
structure
See Structure pointers
testing for nonzero values 3-12
POPname directive
See name directive
Position-independent code (PIC) 17-22
Pound sign (#) 2-5
Precedence of operators 5-3/5-4
PRINTSYM directive 17-52
PRIV procedure attribute 14-5/14-6
Private data area 1-4
PRIVATE keyword 16-14
Privileged mode 15-1/15-2
Privileged routines 15-11/15-12
PROC address type 14-11/14-12
PROC keyword 14-2
PROCADDR address type
description of 10-6
comparing to PROCPTR 3-11
converting 3-9
parameters of 14-11
pointers of 10-10
PROCADDR routine 15-78/15-79
Procedure calls (CALL
statement) 12-10/12-12
Procedure entry points 10-10
Procedure pointers
description of 14-26/14-29
address types of 10-10
assignments to 14-33/14-34
comparing to data addresses 3-11
declaring
as formal parameters 14-32
as variables 14-29/14-30
in structures 14-30/14-31
for dynamically selected procedure
calls 14-35/14-36
Procedures
description of 1-4, 14-1
See also Functions
See also Routines
address types of 10-10
as parameters 14-14
attributes of 14-5/14-9
bodies of 14-17/14-18
callable 14-6
converting from variable to
extensible 14-7
C/C++ D-1
declaring 14-2/14-4
dynamically selected calls
to 14-35/14-36
extensible 14-7
EXTERNAL declaration of 14-2, 14-4
formal parameter specification
in 14-10/14-15
FORWARD declaration of 14-2, 14-4
labels in 14-37
languages of 14-8
main 14-5
resident 14-6
scope of 2-10/2-11
system 1-7
that return condition codes 12-37, 14-8
typed
See Functions
HP pTAL Reference Manual—523746-006
Index -17
Index
Q
Procedures (continued)
using hardware indicators
across 13-14/13-16
variable 14-7
with RETURN statements 12-34
with two return values D-1/D-3
Procedure-parameter routines 15-16
PROCPTRs
See Procedure pointers
PROC(32) address type 14-11
Program control statements 12-1
pTAL language
applications 1-3
character set for 2-2
compatibility with TAL 1-1
elements of 2-1
features of 1-4/1-6
services for 1-7
syntax of
See Syntax
Punctuation characters in syntax
diagrams -xxxviii
PUSHname directive
See name directive
P-relative arrays
See Read-only arrays
Q
Quadruplewords 3-1
Question mark (?) 2-5
Quotation mark (") 2-5
See also Single quotation mark (’)
R
READBASELIMIT routine 15-79
READCLOCK routine 15-80
READSPT routine 15-80/15-81
READTIME routine 15-81
Read-only arrays
address types of 10-10
constant lists in 8-8
declaring 8-6/8-7
REAL data type
functions that return values of 14-12
numeric constants of 3-19/3-20
obtaining
with $FLT routine 15-49
with $FLTR routine 15-50
parameters of 14-11
REAL(32) data type
See REAL data type
REAL(64) data type
numeric constants of 3-19/3-20
obtaining
with $EFLT routine 15-37
with $EFLTR routine 15-38
Records
See Structures
Recursion 1-5
Redefinitions
array 9-55/9-56
pointer
simple 9-61/9-62
structure 9-63/9-64
rules for 9-53
simple variable 9-54/9-55
substructure
definition 9-56/9-59
referral 9-59/9-60
REFALIGNED clause
with simple equivalenced
pointers 11-15
with structure pointers 9-27/9-32
REFALIGNED directive 17-53
Referral structures, declaring
equivalenced 11-25/11-26
not equivalenced 9-38/9-39
HP pTAL Reference Manual—523746-006
Index -18
Index
S
Referral substructures
declaring 9-45
redefining 9-59/9-60
Relational operators
in conditional expressions 5-18
signed
in address comparisons 5-11
operand types for 5-18
precedence of 5-4
unsigned
in address comparisons 5-11
operand types for 5-19
precedence of 5-4
with INT(32) operands 5-10
with extended addresses 5-12
with nonextended addresses 5-12
Relocatable data blocks
See Global data, blocked
Remainder operator (’\’)
in arithmetic expression 5-5
operand types for 5-9
precedence of 5-3
result types for 5-9
with INT(32) and FIXED operands 5-11
Reserved keywords 2-3
RESETTOG directive 17-54/17-55
RESIDENT procedure attribute 14-5, 14-6
RETURN statement 12-34/12-40
RETURNSCC procedure attribute
for procedures 14-5, 14-8
for subprocedures 14-19, 14-20
Right-to-left move (=:) 12-28
RISC
See TNS/R architecture
ROUND directive 17-55/17-56
ROUND (default) misalignment handling
method 4-3
Rounding
expressions unaffected by 15-13
ROUND directive and 17-55/17-56
Rounding (continued)
type-conversion routines and 15-13
Routines
See also Functions
See also Procedures
address-conversion 15-14
arithmetic 15-15
built-in 15-1
character-test 15-14
maximum 15-15
minimum 15-15
miscellaneous built-in 15-16/15-17
procedure-parameter 15-16
pTAL privileged 15-11/15-12
type-conversion 15-12/15-13
variable-characteristic 15-16
RSCAN statement 12-40/12-42
Run-time environment directives 17-17
S
SAVEGLOBALS directive 17-8/17-13,
17-56/17-57
SCALE routine 15-82/15-83
Scaling FIXED values
by specifying fpoint 5-7
in assignment statements 12-7
with $SCALE routine 15-82
SCAN statement 12-40/12-42
SCF user interface
attributes of 4-3
misalignment handling and 4-3
misalignment tracing facility and 4-1
Scope of declared items 2-10/2-11
Search subvolume (SSV)
command B-9/B-10
SECTION directive
description of 17-57/17-58
global data blocks and 16-16
SOURCE directive and 17-61
Section names 17-57
HP pTAL Reference Manual—523746-006
Index -19
Index
S
Segment Page Table (SPT)
address of 15-62
copying an entry from 15-80
Selector
in labeled CASE statement 12-13
in unlabeled CASE statement 12-15
Semicolon (;)
as delimiter 2-4
in statements 12-2
Services
CRE 1-7
pTAL 1-7
system 1-6
setjmp() instruction 9-1
SETTOG directive 17-58/17-59
SGBADDR address type
description of 10-6
converting 3-9
parameters of 14-11
pointers of 10-9
SGBADDR_TO_EXTADDR routine 15-83
SGBADDR_TO_SGWADDR
routine 15-83/15-84
SGWADDR address type
description of 10-6
converting 3-9
parameters of 14-11
pointers of 10-9
SGWADDR_TO_EXTADDR
routine 15-84/15-85
SGWADDR_TO_SGBADDR routine 15-85
SGXBADDR address type
description of 10-6
converting 3-9
parameters of 14-11
pointers of 10-9
SGXWADDR address type
description of 10-6
converting 3-9
parameters of 14-11
SGXWADDR address type (continued)
pointers of 10-9
Shared code
See Position-independent code (PIC)
SHARED2 parameter
description of 9-6, 9-20/9-22
FIELDALIGN clause and 9-5/9-6
SHARED8 parameter
description of 9-6, 9-22/9-27
FIELDALIGN clause and 9-5/9-6
Shifting bits
description of 5-33/5-35
precedence of operators for 5-3
Short-circuit expression evaluation 5-17
SIGILL signal (signal #4) 4-3
Signed operators
arithmetic 5-6/5-7
bit shift 5-3
relational 5-18
Simple pointers
description of 10-1
addresses in 10-17
as parameters 14-14
declaring
equivalenced 11-10/11-15
not equivalenced 10-12/10-14
equivalenced 11-10/11-15
initializing 10-14/10-16
redefining 9-61/9-62
using 9-49/9-50
VOLATILE 10-4
within structures 9-48/9-49
Simple variables
as parameters 14-13, 14-14
data type of 15-88
declaring
equivalenced 11-8/11-10
not equivalenced 7-1/7-3
equivalenced 11-23/11-24
HP pTAL Reference Manual—523746-006
Index -20
Index
S
Simple variables (continued)
length of
in bits 15-28
in bytes 15-59
redefining 9-54/9-55
within structures 9-40
Single quotation mark (’) 2-5
sINT 15-1
Slash (⁄
)
See Division operator
Smear operation 12-33, 15-42
Source code listing 17-44
SOURCE directive
description of 17-60/17-64
global data blocks and 16-16
NOLIST directive and 17-63
system procedure declarations
and 17-63
Source files
checking syntax of 17-67
compiling 16-2/16-3
listing 17-44
Spacing rules in syntax diagrams -xxxix
Special expressions 5-20
SPECIAL routine 15-85/15-86
SPT 15-62
SPT (Segment Page Table)
address of 15-62
copying an entry from 15-80
SQL/MP or SQL/MX in pTAL 1-3
Square brackets ([ ]) 2-4
SRL directive 17-65
Stacks, directive
See Directive stacks
STACK_ALLOCATE routine 15-86/15-87
Standard functions
See Built-in routines
Statements
categories of 12-1
Statements (continued)
compound
See Compound statements
null 12-2
role in program 2-12
Static T flag 13-1
Stepping pointers 3-10
Storage units 3-1
STRING data type
functions that return values of 14-12
numeric constants of 3-14
parameters of
actual
passed conditionally 15-74
passed unconditionally 12-11
formal
for procedure pointers 14-27
for procedures 14-3, 14-11,
14-12
for subprocedures 14-11,
14-12, 14-20
STRUCT data type 14-11, 14-16
STRUCT keyword
in structures
definition 9-33
referral 9-38
template 9-35
in substructures
definition
not redefined 9-42
redefined 9-56
referral
not redefined 9-45
redefined 9-59
STRUCTALIGN clause 9-37
STRUCTALIGN (MAXALIGN)
attribute 9-32, 9-36
Structure items
arrays 9-40
filler bits or bytes 9-46/9-47
HP pTAL Reference Manual—523746-006
Index -21
Index
S
Structure items (continued)
offsets of
in bits 15-29
in bytes 15-71
pointers
simple 9-48/9-49
structure 9-51/9-53
procedure pointers as 14-26
simple variables 9-40
substructures
definition 9-42/9-44
referral 9-45/9-46
Structure pointers
description of 10-1
addresses in 10-17
as parameters 14-14
declaring 10-16/10-17
initializing 10-17/10-19
redefining 9-63/9-64
reference alignment with 9-27/9-32
VOLATILE 10-5
within structures 9-51/9-53
Structures
description of 9-1
alignment of
description of 9-4/9-5
arrays in 9-13/9-15
base 9-9
fields of 9-5/9-13
in depth 9-15
as parameters 14-13, 14-14, 14-16
data type of 15-88
declaring
definition
equivalenced 11-24/11-25
not equivalenced 9-33/9-35
referral
equivalenced 11-25/11-26
not equivalenced 9-38/9-39
Structures
declaring (continued)
template 9-35/9-38
items within
See Structure items
layout of 9-3/9-5
length of
in bits 15-28
in bytes 15-59
maximum nesting levels in 9-3
number of occurrences of 15-69
redefining 9-53
Sublocal declarations 14-21
Sublocal scope 2-10
SUBPROC keyword 14-19
Subprocedure entry points 10-10
Subprocedures
See also Functions
address types of 10-10
bodies of 14-21/14-22
declaring 14-19/14-21
description of 14-1
formal parameter specification
in 14-10/14-15
FORWARD declaration of 14-21
description of 1-4
sublocal declarations in 14-21
that return condition codes 14-20
variable 14-20
with RETURN statements 12-34
Substructures
alignment of 9-16/9-19
data type of 15-88
declaring
definition 9-42/9-44
referral 9-45/9-46
length of
in bits 15-28
in bytes 15-59
number of elements of 15-69
HP pTAL Reference Manual—523746-006
Index -22
Index
T
Substructures (continued)
redefining
definition 9-56/9-59
referral 9-59/9-60
Subsystem Control Facility
See SCF user interface
Subtraction operator
signed (-)
in arithmetic expression 5-5
operand types for 5-6
precedence of 5-3
unsigned (’-’)
in arithmetic expression 5-5
operand types for 5-8
precedence of 5-3
result types for 5-9
with INT(32) operands 5-11
Subvolume names B-3
SUPPRESS directive 17-65/17-66
Swap volume B-7
SWAPVOL command B-7
SYMBOLS directive 17-66/17-67
Symbols, base address 2-7
Syntax
checking 17-67/17-68
conventions for -xxxvii/-xl
summary of A-1/A-119
SYNTAX directive 17-67/17-68
System clock setting 15-80
System global data
See also Global data
declaring
equivalenced 11-22/11-29
pointers 10-20
pointers to 10-9
System names B-2
System procedures
description of 1-7
SOURCE directive and 17-63
System services 1-6
T
TACL commands
See HP TACL commands
TACL DEFINE tool 18-7
TAL
compatibility with pTAL 1-1
procedures that return two values D-1
TARGET directive 17-68/17-69
Target file option 16-6
Template structures, declaring 9-35/9-38
Temporary files B-7
Temporary variables
creating 12-45
dropping 12-20
THEN keyword 12-26
TNS architecture RVUs 1-2
TNSMISALIGN attribute (SCF) 4-3
TNS/E architecture RVUs 1-2
TNS/R architecture RVUs 1-2
TNS/R native mode 4-3
TO keyword 12-20
Toggles
description of 17-5
turning off 17-54
turning on 17-58
Tracing facility 4-1/4-2
Transfer Tool 18-7
Traps, managing
generally 13-1/13-3
GOTO statement and 12-24/12-25
TRIGGER routine 15-88
TYPE routine 15-88/15-89
Typed procedures
See Functions
Type-conversion routines 15-12/15-13
U
UDBL routine 15-89/15-90
UDIVREM16 routine 15-90/15-91
UDIVREM32 routine 15-91/15-92
HP pTAL Reference Manual—523746-006
Index -23
Index
V
uINT 15-1
Unlabeled CASE statement 12-15/12-17
UNLOCKPAGE routine 15-93
UNSIGNED data type
functions that return values of 14-12
parameters of 14-11
Unsigned operators
arithmetic 5-8/5-11
bit shift 5-3
relational 5-19
UNSPECIFIED procedure attribute 14-5
UNTIL keyword
in DO statement 12-17
in RSCAN statement 12-40
in SCAN statement 12-40
USE statement 12-45
USEGLOBALS directive
description of 17-69/17-70
SAVEGLOBALS and
BEGINCOMPILATION and 17-8/17-13
SOURCE directive and 17-63
User library 17-65
V
VARIABLE procedure attribute
for procedures 14-5, 14-7
for subprocedures 14-19, 14-20
Variables
description of 2-10
equivalenced
See Equivalenced variables
FIXED 5-8
procedure pointers as 14-26
scope of 2-10/2-11
simple
See Simple variables
storing data addresses in 3-7
temporary
creating 12-45
dropping 12-20
Variables (continued)
types of 2-10
Variable-characteristic routines 15-16
VARIABLE-to-EXTENSIBLE procedure
conversions 14-7
Visual Studio .NET 18-2
VOLATILE pointers
simple 10-4
structure 10-5
VOLATILE procedure attribute 9-33
Volume names B-3
W
WADDR address type
description of 10-6
converting 3-9
parameters of 14-11
pointers of 10-9
WADDR_TO_BADDR routine 15-93/15-94
WADDR_TO_EXTADDR routine 15-94
WARN directive 17-71/17-72
Warning messages 17-71/17-72
WHILE keyword
in RSCAN statement 12-40
in SCAN statement 12-40
in WHILE statement 12-45
WHILE statement
description of 12-45/12-46
hardware indicators in 13-8
Words 3-1
WRITEPTE routine 15-95
X
XADR routine 15-96
XOR operator
in arithmetic expression 5-5
operand types for 5-10
precedence of 5-3
with INT(32) operands 5-10
HP pTAL Reference Manual—523746-006
Index -24
Index
Z
Z
ZZBInnnn target file 16-6
Special Characters
! (exclamation mark) 2-4
" (quotation mark) 2-5
# (hash mark or pound sign) 2-5
$ (dollar sign) 2-5
$ABS routine 15-22/15-23
$ALPHA routine 15-23/15-24
$ASCIITOFIXED routine 15-24/15-25
$ATOMIC_ routines 4-1, 4-3
$ATOMIC_ADD routine 15-5
$ATOMIC_AND routine 15-6
$ATOMIC_DEP routine 15-7/15-8
$ATOMIC_GET routine 15-8
$ATOMIC_OR routine 15-9
$ATOMIC_PUT routine 15-10
$AXADR routine 15-26
$BADDR_TO_EXTADDR
routine 15-26/15-27
$BADDR_TO_WADDR routine 15-27
$BITLENGTH routine 15-28
$BITOFFSET routine 15-29
$CARRY routine
description of 15-30
after assignments 13-4
atomic operation that can set 15-4
in nested IF statements 13-12/13-13
nonatomic operations that can
set 15-20/15-22
returning its value to calling
procedure 13-16
$CHECKSUM routine 15-31/15-32
$COMP routine 15-32
$COUNTDUPS routine 15-33/15-34
$DBL routine 15-34/15-35
$DBLL routine 15-35
$DBLR routine 15-36
$DFIX routine 15-36/15-37
$EFLT routine 15-37
$EFLTR routine 15-38, 15-38/15-39
$EXCHANGE routine 15-39
$EXECUTEIO routine 15-40/15-41
$EXTADDR_TO_BADDR routine 15-41
$EXTADDR_TO_WADDR routine 15-42
$FILL16 procedure 15-42/15-43
$FILL32 procedure 15-42/15-43
$FILL8 procedure 15-42/15-43
$FIX routine 15-44
$FIXD routine 15-44/15-45
$FIXEDTOASCII routine 15-45/15-46
$FIXEDTOASCIIRESIDUE
routine 15-46/15-47
$FIXI routine 15-47/15-48
$FIXL routine 15-48
$FIXR routine 15-48/15-49
$FLT routine 15-49/15-50
$FLTR routine 15-50
$FREEZE routine 15-51
$HALT routine 15-51
$HIGH routine 15-52
$IFIX routine 15-52/15-53
$INT routine 15-53/15-54
$INTERROGATEHIO routine 15-55/15-56
$INTERROGATEIO routine 15-57/15-58
$INTR routine 15-58/15-59
$INT_OV routine 15-54/15-55
$LEN routine 15-59/15-60
$LFIX routine 15-60/15-61
$LMAX routine 15-61
$LMIN routine 15-61/15-62
$LOCATESPTHDR routine 15-62/15-63
$LOCKPAGE routine 15-63/15-64
$MAX routine 15-64
$MIN routine 15-64/15-65
$MOVEANDCXSUMBYTES
routine 15-65/15-66
$MOVENONDUP routine 15-67/15-68
$NUMERIC routine 15-68
$OCCURS routine 15-69/15-71
HP pTAL Reference Manual—523746-006
Index -25
Index
Special Characters
$OFFSET routine
description of 15-71/15-73
structure pointers and 10-18
$OPTIONAL routine 15-73/15-76
$OVERFLOW routine
description of 15-76/15-77
after assignments 13-3/13-4
atomic operation that can set 15-4
built-in routines and 15-4
in nested IF statements 13-12/13-13
nonatomic operations that can
set 15-17/15-22
returning its value to calling
procedure 13-16
$PARAM routine 15-77
$POINT routine 15-78
$PROCADDR routine 15-78/15-79
$READBASELIMIT routine 15-79
$READCLOCK routine 15-80
$READSPT routine 15-80/15-81
$READTIME routine 15-81
$SCALE routine 15-82/15-83
$SGBADDR_TO_EXTADDR routine 15-83
$SGBADDR_TO_SGWADDR
routine 15-83/15-84
$SGWADDR_TO_EXTADDR
routine 15-84/15-85
$SGWADDR_TO_SGBADDR
routine 15-85
$SPECIAL routine 15-85/15-86
$STACK_ALLOCATE routine 15-86/15-87
$TRIGGER routine 15-88
$TYPE routine 15-88/15-89
$UDBL routine 15-89/15-90
$UDIVREM16 routine 15-90/15-91
$UDIVREM32 routine 15-91/15-92
$UNLOCKPAGE routine 15-93
$WADDR_TO_BADDR
routine 15-93/15-94
$WADDR_TO_EXTADDR routine 15-94
$WRITEPTE routine 15-95
$XADR routine 15-96
& (concatenation operator) 12-30
*
See Asterisk (*)
+
See Plus sign (+)
See Hyphen (-)
See Minus sign (-)
->
in labeled CASE statement 12-13
in move statement 12-28
in RSCAN statement 12-40
in SCAN statement 12-40
.
See Period (.)
.EXT
in equivalenced variables 11-24
in formal parameters 14-10, 14-13
in pointers
procedure 14-28
simple 10-12
structure 10-16
in referral structures 9-38
.SG
in formal parameters 14-13
in procedure pointers 14-28
in system global pointers 10-20
.SGX
in formal parameters 14-13
in procedure pointers 14-28
.tal file extension 18-1
... (ellipsis) 12-13
: (colon) 14-23
:=
assignment operator 5-4
See also Assignments
left-to-right move 12-28
; (semicolon)
as delimiter 2-4
in statements 12-2
HP pTAL Reference Manual—523746-006
Index -26
Index
Special Characters
<
’-’
See Less than operator, signed (<)
< > (angle brackets) 2-4
<...> (bit extraction) 5-3
<...> := (bit deposit operator) 5-4
<< (signed left bit shift) 5-3
<=
See Less than or equal operator, signed
(<=)
<>
See Not equal operator, signed (<>)
=
See Equal sign
=: (right-to-left move) 12-28
>
See Greater than operator, signed (>)
>=
See Greater than or equal operator,
signed (>=)
>> (signed right bit shift) 5-3
? (question mark) 2-5
@ operator
in entry-point identifiers
for procedures 14-23
for subprocedures 14-24
in pointers 10-14
in PROC parameters 14-16
in reference parameters 14-14
precedence of 5-3
[ ] (square brackets) 2-4
’ (single quotation mark) 2-5
’P’ (read-only array symbol)
See Read-only arrays
’SG’-equivalenced variables
See Equivalenced variables
’*’
See Multiplication operator, unsigned
(’*’)
’+’
See Addition operator, unsigned (’+’)
See Subtraction operator, unsigned (’-’)
’<<’ (unsigned left bit shift) 5-3
’<=’
See Less than or equal operator,
unsigned (’<=’)
’<>’
See Not equal operator, unsigned (’<>’)
’<’
See Less than operator, unsigned (’<’)
’=’
See Equal sign, as equal operator,
unsigned
’>=’
See Greater than or equal operator,
unsigned (’>=’)
’>>’ (unsigned right bit shift) 5-3
’>’
See Greater than operator, unsigned
(’>’)
’\’
See Remainder operator (’\’)
’⁄
’
See Division operator, unsigned (’⁄ ’)
⁄
See Division operator, signed (⁄
)
HP pTAL Reference Manual—523746-006
Index -27
Index
Special Characters
HP pTAL Reference Manual—523746-006
Index -28
">
/
دانلود
فقط یک یادآوری دوستانه. می توانید سند را درست در اینجا مشاهده کنید. اما مهمتر از همه، هوش مصنوعی ما قبلاً آن را خوانده است. این می تواند موارد پیچیده را به زبان ساده توضیح دهد، به سوالات شما به هر زبانی پاسخ دهد و به شما کمک کند به سرعت حتی طولانی ترین یا پیچیده ترین اسناد را پیمایش کنید.
تبلیغات