HP pTAL

Download as pdf or txt
Download as pdf or txt
You are on page 1of 742

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 Examples Figures Tables

What’s New in This Manual xxxi


Manual Information xxxi
New and Changed Information 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 1-2
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

Hewlett-Packard Company—523746-006
i
Contents 2. Language Elements

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 4-1
Misalignment Handling 4-3

HP pTAL Reference Manual—523746-006


ii
Contents 5. Expressions

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 5-10
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 7-4
Examples 7-4

HP pTAL Reference Manual—523746-006


iii
Contents 8. Arrays

8. Arrays
Declaring Arrays 8-2
Declaring Read-Only Arrays 8-6
Using Constant Lists in Array Declarations 8-8
Read-Only Arrays 8-8
Nonstring Arrays 8-9

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
Contents 9. Structures (continued)

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 9-50
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

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
Contents 10. Pointers (continued)

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 12-7
Assigning Character Strings 12-7
Examples 12-8
Bit-Deposit Assignment 12-9
CALL 12-10
CASE 12-12
Empty CASE 12-12

HP pTAL Reference Manual—523746-006


vi
Contents 13. Hardware Indicators

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 12-24
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
Contents 14. Procedures, Subprocedures, and Procedure
Pointers

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 14-16
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
Contents 15. Built-In Routines (continued)

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
Contents 15. Built-In Routines (continued)

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
Contents 15. Built-In Routines (continued)

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
Contents 17. Compiler Directives

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
Contents 17. Compiler Directives (continued)

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 17-63
Examples 17-64
SRL 17-65
SUPPRESS 17-65
SYMBOLS 17-66
SYNTAX 17-67
TARGET 17-68
USEGLOBALS 17-69
WARN 17-71

18. pTAL Cross Compiler


NonStop pTAL (ETK) 18-2
pTAL or EpTAL (PC Command Line) 18-3

HP pTAL Reference Manual—523746-006


xiii
Contents 18. pTAL Cross Compiler (continued)

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 18-7
Documentation 18-8

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 A-3
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-28

HP pTAL Reference Manual—523746-006


xiv
Contents A. Syntax Summary (continued)

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 A-46
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
Contents B. Disk File Names and HP TACL Commands

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 B-2
Partial File Names B-3
Logical File Names B-4

HP pTAL Reference Manual—523746-006


xvi
Contents C. Differences Between the pTAL and EpTAL
Compilers

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 C-1
Routines C-2
Compiler Directives C-3

D. RETURN, RETURNSCC, and C/C++ on TNS/E


Glossary
Index
Examples
Example 2-1. Correct Identifiers 2-9
Example 2-2. Incorrect Identifiers 2-9
Example 2-3. Scope of Declared Items 2-11
Example 2-4. Global and Local Variable With the Same Name 2-11
Example 3-1. Constant Expressions in Data Type Specifications 3-4
Example 3-2. Using Indexing to Access an Array Element 3-9
Example 3-3. Adding Integer Values to Addresses 3-10
Example 3-4. Subtracting Integer Values From Addresses 3-10
Example 3-5. Signed and Unsigned Operators in Address Arithmetic 3-10
Example 3-6. Assigning Character Strings to Variables 3-13
Example 5-1. Extended Addresses 5-12
Example 5-2. Constant Expressions 5-14
Example 5-3. Short-Circuit Expression Evaluation 5-17
Example 5-4. CASE Expression 5-22
Example 5-5. Array Comparison 5-30
Example 5-6. Structure Comparison 5-30
Example 5-7. Constant Comparison 5-30
Example 5-8. Bit Extraction 5-32
Example 5-9. Bit Extraction From an Array 5-32
Example 5-10. Modifying Bits Before Extracting Them 5-32

HP pTAL Reference Manual—523746-006


xvii
Contents Examples (continued)

Examples (continued)
Example 5-11. Checking a Bit for a Nonzero Value 5-32
Example 5-12. Arithmetic Left Shift 5-34
Example 6-1. Literal Declarations 6-2
Example 6-2. DEFINE Declarations 6-5
Example 6-3. STRUCT and DEFINE Macro Items With the Same Name 6-5
Example 6-4. Parenthesized and Nonparenthesized DEFINE Bodies 6-6
Example 6-5. Fewer Actual Parameters Than Formal Parameters 6-7
Example 6-6. No Actual Parameters 6-7
Example 6-7. More Actual Parameters Than Formal Parameters 6-7
Example 6-8. Commas in an Actual Parameter 6-7
Example 6-9. Parentheses in an Actual Parameter 6-8
Example 6-10. Assignment Statement Using DEFINE Macro Identifier 6-8
Example 6-11. Incrementing and Decrementing Utilities 6-8
Example 6-12. Filling an Array With Zeros 6-8
Example 6-13. Checking a Condition Code 6-9
Example 7-1. Declaring Simple Variables Without Initializing Them 7-5
Example 7-2. Declaring and Initializing Simple Variables 7-5
Example 7-3. Effect of fpoint on FIXED Simple Variables 7-5
Example 7-4. Initializing Simple Variables With Constants and Variables* 7-6
Example 7-5. Declaring Simple VOLATILE Variables 7-6
Example 7-6. PROCADDR and PROCPTR 7-6
Example 8-1. Declaring Arrays With Various Bounds 8-4
Example 8-2. Declaring Arrays and Initializing Them With Constants 8-4
Example 8-3. Declaring Arrays and Initializing Them With Constant Lists 8-5
Example 8-4. Initializing Arrays 8-5
Example 8-5. Array With Positive fpoint 8-5
Example 8-6. Array With Negative fpoint 8-5
Example 8-7. Read-Only Array Declaration With Indirection Symbol 8-7
Example 8-8. Declaring and Initializing a Read-Only Array 8-7
Example 8-9. Declaring Read-Only Arrays With Constant Lists 8-8
Example 8-10. Declaring Nonstring Arrays With Constant Lists 8-9
Example 9-1. Arrays Within Structures 9-13
Example 9-2. SHARED2: 2-Byte Alignment 9-14
Example 9-3. SHARED8: 4-Byte Alignment 9-14
Example 9-4. 8-Byte Alignment and 4-Byte Alignment 9-15
Example 9-5. SHARED8 Structures With Different Base Alignments 9-15
Example 9-6. Well-Aligned Structure With Well-Aligned Substructure 9-16
Example 9-7. SHARED8 Structures With SHARED2 Substructures 9-17

HP pTAL Reference Manual—523746-006


xviii
Contents Examples (continued)

Examples (continued)
Example 9-8. SHARED2 Structures With SHARED8 Substructure 9-17
Example 9-9. SHARED8 Structure With SHARED2 Substructure 9-18
Example 9-10. Combining SHARED2 and SHARED8 Structures 9-18
Example 9-11. AUTO Field Alignment in Structure (Error) 9-19
Example 9-12. FIELDALIGN(SHARED2) and REFALIGNED(2) Directives 9-21
Example 9-13. Byte Offsets (Decimal) of Fields of a SHARED2 Structure 9-22
Example 9-14. Filler Forcing Alignment in a SHARED8 Structure 9-24
Example 9-15. Structure With SHARED2 Field Alignment 9-25
Example 9-16. Structure With SHARED8 Field Alignment 9-25
Example 9-17. Optimized Structure With SHARED8 Field Alignment 9-25
Example 9-18. Structures That Need Filler 9-26
Example 9-19. Structure Field Crossing an Even-Byte Address (Error) 9-26
Example 9-20. Structure That Needs Filler 9-26
Example 9-21. SHARED8 Structure With Misaligned UNSIGNED Fields 9-27
Example 9-22. SHARED8 Structure With Correctly Aligned UNSIGNED Fields 9-27
Example 9-23. REFALIGNED Clause With Structure Pointers 9-28
Example 9-24. REFALIGNED Clause 9-28
Example 9-25. Default Reference Alignment 9-29
Example 9-26. REFALIGNED(2) 9-30
Example 9-27. REFALIGNED(8) 9-31
Example 9-28. VOLATILE Attribute 9-33
Example 9-29. Template Structure Declaration 9-37
Example 9-30. Template Structure With STRUCTALIGN(MAXALIGN) 9-37
Example 9-31. Referral Structure That References a Template Structure 9-39
Example 9-32. Simple Variables Within a Structure 9-40
Example 9-33. Arrays Within a Structure 9-41
Example 9-34. Using a Zero-Length Array to Initialize a Structure 9-42
Example 9-35. Declaring Definition Substructures 9-44
Example 9-36. Declaring a Referral Substructure 9-46
Example 9-37. Filler Byte Declarations 9-47
Example 9-38. Filler Bit Declaration 9-47
Example 9-39. Simple Pointers Within a Structure 9-49
Example 9-40. Assigning Addresses to Pointers in Structures 9-50
Example 9-41. Assigning Addresses to Pointers in Structures 9-51
Example 9-42. Declaring a Structure Pointer Within a Structure 9-53
Example 9-43. Simple Variable Redefinition 9-55
Example 9-44. Array Redefinition 9-56
Example 9-45. Definition Substructure Redefinition 9-58

HP pTAL Reference Manual—523746-006


xix
Contents Examples (continued)

Examples (continued)
Example 9-46. Definition Substructure Redefinition 9-59
Example 9-47. Referral Substructure Redefinition 9-60
Example 9-48. Simple Pointer Redefinition 9-62
Example 9-49. Structure Pointer Redefinition 9-64
Example 10-1. Declaring VOLATILE Simple Pointers 10-4
Example 10-2. Declaring VOLATILE Structure Pointers 10-5
Example 10-3. Determining Address Types 10-7
Example 10-4. BADDR and WADDR 10-9
Example 10-5. SGBADDR, SGWADDR, SGXBADDR, and SGXWADDR 10-9
Example 10-6. PROCADDR 10-10
Example 10-7. CBADDR and CWADDR 10-11
Example 10-8. EXTADDR Declarations 10-11
Example 10-9. Declaring But Not Initializing a Simple Pointer 10-15
Example 10-10. Declaring and Initializing a Simple Pointer 10-15
Example 10-11. Declaring and Initializing a STRING Simple Pointer 10-15
Example 10-12. Declaring and Initializing Simple Pointers 10-15
Example 10-13. Declaring and Initializing a Simple Pointer, Using $XADR 10-16
Example 10-14. Declaring and Initializing an Extended Simple Pointer 10-16
Example 10-15. Declaring and Initializing a Structure Pointer, Using $OFFSET 10-18
Example 10-16. Declaring and Initializing a STRING Structure Pointer 10-18
Example 10-17. Declaring and Initializing a Local Structure Pointer 10-19
Example 10-18. Declaring and Initializing a Local STRING Structure Pointer 10-19
Example 10-19. Declaring and Initializing a Local STRING Structure Pointer 10-19
Example 10-20. System Global Pointer Declaration 10-20
Example 11-1. Declaring Equivalenced Variables 11-3
Example 11-2. Equivalenced Pointers 11-4
Example 11-3. Memory Usage for Nonstructured Equivalenced Variables 11-7
Example 11-4. Read-Only Pointer 11-12
Example 11-5. Equivalenced Objects of Unequal Length 11-14
Example 11-6. REFALIGNED Clause for Equivalenced Simple Pointers 11-15
Example 11-7. Equivalencing PROCADDR and PROCPTR Variables 11-15
Example 11-8. Declaring Equivalenced Structures 11-18
Example 11-9. Structure Variants 11-20
Example 11-10. Structure Variants 11-20
Example 11-11. 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
Contents Examples (continued)

Examples (continued)
Example 11-13. FIELDALIGN Clause in Structured Equivalenced Variables 11-22
Example 11-14. Equivalenced Simple Variable Declaration 11-24
Example 11-15. Equivalenced Definition Structure Declaration 11-25
Example 11-16. Equivalenced Referral Structure Declaration 11-26
Example 11-17. Equivalenced Simple Pointer Declaration 11-28
Example 11-18. Equivalenced Structure Pointer Declaration 11-29
Example 12-1. Null Compound Statement 12-3
Example 12-2. Compound Statement 12-3
Example 12-3. ASSERTION Directive and ASSERT Statement 12-4
Example 12-4. Assignment Statements 12-8
Example 12-5. Assignment Statements Equivalent to a Constant List 12-8
Example 12-6. Assignment Statement With Assignment Expressions 12-8
Example 12-7. CALL Statement 12-12
Example 12-8. Empty CASE Statement 12-12
Example 12-9. Labeled CASE Statement 12-14
Example 12-10. Labeled CASE Statement 12-15
Example 12-11. Unlabeled CASE Statement 12-16
Example 12-12. Unlabeled CASE Statement 12-17
Example 12-13. Unlabeled CASE Statement Assigning Text to Array 12-17
Example 12-14. DO-UNTIL Statement 12-18
Example 12-15. DO-UNTIL Statement 12-18
Example 12-16. DO-UNTIL Statement With Hardware Indicator 12-19
Example 12-17. DO-UNTIL Statement With GOTO Statement 12-19
Example 12-18. Nested FOR Statement 12-21
Example 12-19. Standard FOR Statement 12-22
Example 12-20. Standard and Optimized FOR Statements 12-22
Example 12-21. Local GOTO Statement 12-23
Example 12-22. Nonlocal GOTO Statement 12-24
Example 12-23. Local GOTO and Target Statements That Have Different Trapping
States 12-24
Example 12-24. Nonlocal GOTO and Target Statements That Have Different Trapping
States 12-25
Example 12-25. IF Statement 12-26
Example 12-26. MOVE Statement Copying to an Array 12-31
Example 12-27. MOVE Statement Copying Bracketed and Unbracketed
Constants 12-31
Example 12-28. MOVE Statement Copying From One Structure to Another 12-31
Example 12-29. MOVE Statement Copying a Substructure 12-32

HP pTAL Reference Manual—523746-006


xxi
Contents Examples (continued)

Examples (continued)
Example 12-30. MOVE Statement With Destination Shorter Than Source 12-32
Example 12-31. FILL16 Statement 12-33
Example 12-32. RETURN Statements Nested in an IF Statement 12-35
Example 12-33. RETURN Statement That Returns a Value and a Condition
Code 12-35
Example 12-34. Testing a Condition Code 12-35
Example 12-35. RETURN Statement in a Procedure 12-36
Example 12-36. RETURN Statement in a Procedure That Returns a Condition
Code 12-37
Example 12-37. Procedure Without RETURNSCC 12-37
Example 12-38. Procedure With RETURNSCC 12-37
Example 12-39. Function Without RETURNSCC 12-38
Example 12-40. Function With RETURNSCC 12-38
Example 12-41. Condition Code Returned by Function Called by CALL
Statement 12-39
Example 12-42. Condition Code Based on Numeric Value 12-39
Example 12-43. Condition Code That Is Independent of the Function’s Value 12-40
Example 12-44. Invalid Function That Attempts to Return an Explicit Condition
Code 12-40
Example 12-45. SCAN UNTIL Statement 12-42
Example 12-46. Determining What Stopped a Scan 12-42
Example 12-47. Extended Pointers in SCAN and RSCAN Statements 12-42
Example 12-48. Scanning Adjacent Fields Within a Structure 12-43
Example 12-49. Scanning Data in a P-Relative Array 12-44
Example 12-50. Scanning Data in a P-Relative Array 12-44
Example 12-51. WHILE Statement 12-46
Example 12-52. WHILE Statement 12-46
Example 13-1. OVERFLOW_TRAPS Compiler Directive and Procedure
Attribute 13-2
Example 13-2. ENABLE_OVERFLOW_TRAPS and DISABLE_OVERFLOW_TRAPS
Block Attributes 13-3
Example 13-3. Assignments After Which You Can Test Condition Codes 13-7
Example 13-4. Hardware Indicators in DO-UNTIL Statements 13-9
Example 13-5. Hardware Indicators in WHILE Statements 13-9
Example 13-6. Testing a Hardware Indicator Set in a Calling Procedure 13-15
Example 13-7. Returning the Value of $OVERFLOW in a Reference
Parameter 13-16
Example 14-1. Procedure Declaration 14-4
Example 14-2. EXTENSIBLE Procedures as Actual Parameters 14-9

HP pTAL Reference Manual—523746-006


xxii
Contents Examples (continued)

Examples (continued)
Example 14-3. Function With Value and Reference Formal Parameters 14-15
Example 14-4. Reference Structure as a Formal Reference Parameter 14-15
Example 14-5. Using a Referral STRUCT as a Formal Parameter 14-16
Example 14-6. Procedures 14-18
Example 14-7. FORWARD Declaration for a Procedure 14-18
Example 14-8. Function Subprocedure 14-22
Example 14-9. Procedure Entry-Point Identifiers 14-23
Example 14-10. FORWARD Declarations for Entry Points 14-24
Example 14-11. Subprocedure Entry-Point Identifiers 14-25
Example 14-12. PROCPTRs as Variables and Formal Parameters 14-30
Example 14-13. PROCPTR in a Structure 14-31
Example 14-14. PROCPTRs in Structure 14-31
Example 14-15. Code That Uses the Structure in Example 14-14 on
page 14-31 14-31
Example 14-16. PROCPTRs as Formal Parameters 14-32
Example 14-17. Assignments to PROCPTRs 14-33
Example 14-18. Assignments to PROCPTRs 14-34
Example 14-19. Dynamically Selected Procedure Call 14-35
Example 14-20. Dynamically Selected Procedure Call 14-36
Example 14-21. IF Statements Identified by Labels 14-37
Example 15-1. Built-In Routine With Address Parameter 15-2
Example 15-2. Built-In Routine With Address Output Parameter 15-3
Example 15-3. $ATOMIC_ADD Routine 15-5
Example 15-4. $ATOMIC_AND Routine 15-6
Example 15-5. $ATOMIC_DEP Routine 15-7
Example 15-6. $ATOMIC_GET Routine 15-8
Example 15-7. $ATOMIC_OR Routine 15-9
Example 15-8. $ATOMIC_PUT Routine 15-10
Example 15-9. $ABS Routine 15-23
Example 15-10. $ALPHA Routine 15-24
Example 15-11. $ASCIITOFIXED Routine 15-25
Example 15-12. $AXADR Routine 15-26
Example 15-13. $BADDR_TO_EXTADDR Routine 15-27
Example 15-14. $BADDR_TO_WADDR Routine 15-27
Example 15-15. $BITLENGTH Routine 15-28
Example 15-16. $BITOFFSET Routine 15-29
Example 15-17. $CARRY Routine 15-30
Example 15-18. $CHECKSUM Routine 15-32

HP pTAL Reference Manual—523746-006


xxiii
Contents Examples (continued)

Examples (continued)
Example 15-19. $COMP Routine 15-32
Example 15-20. $COUNTDUPS Routine 15-34
Example 15-21. $DBL Routine 15-35
Example 15-22. $DBLL Routine 15-35
Example 15-23. $DBLR Routine 15-36
Example 15-24. $DFIX Routine 15-37
Example 15-25. $EFLT Routine 15-37
Example 15-26. $EFLTR Routine 15-38
Example 15-27. $EFLTR Routine 15-39
Example 15-28. $EXECUTEIO Routine 15-41
Example 15-29. $EXTADDR_TO_BADDR Routine 15-41
Example 15-30. $EXTADDR_TO_WADDR Routine 15-42
Example 15-31. $FILL8 Procedure 15-43
Example 15-32. $FIX Routine 15-44
Example 15-33. $FIXD Routine 15-45
Example 15-34. $FIXEDTOASCII Routine 15-46
Example 15-35. $FIXEDTOASCIIRESIDUE Routine 15-47
Example 15-36. $FIXI Routine 15-48
Example 15-37. $FIXL Routine 15-48
Example 15-38. $FIXR Routine 15-49
Example 15-39. $FLT Routine 15-50
Example 15-40. $FLTR Routine 15-50
Example 15-41. $HIGH Routine 15-52
Example 15-42. $IFIX Routine 15-53
Example 15-43. $INT Routine 15-54
Example 15-44. $INT Routine 15-54
Example 15-45. Difference Between $INT and $INT_OV 15-55
Example 15-46. $INTERROGATEHIO Routine 15-56
Example 15-47. $INTERROGATEIO Routine 15-58
Example 15-48. $INTR Routine 15-59
Example 15-49. $LEN Routine 15-59
Example 15-50. $LEN Routine 15-60
Example 15-51. $LEN Routine 15-60
Example 15-52. $LFIX Routine 15-61
Example 15-53. $LMAX Routine 15-61
Example 15-54. $LMIN Routine 15-62
Example 15-55. $LOCATESPTHDR Routine 15-63
Example 15-56. $LOCKPAGE Routine 15-64

HP pTAL Reference Manual—523746-006


xxiv
Contents Examples (continued)

Examples (continued)
Example 15-57. $MAX Routine 15-64
Example 15-58. $MIN Routine 15-65
Example 15-59. $MOVEANDCXSUMBYTES Routine 15-66
Example 15-60. $MOVENONDUP Routine 15-68
Example 15-61. $NUMERIC Routine 15-68
Example 15-62. $OCCURS Routine With Nonstructure Arrays 15-70
Example 15-63. $OCCURS Routine With Structure Arrays 15-71
Example 15-64. $OCCURS Routine With Template Structure Arrays 15-71
Example 15-65. $OFFSET Routine 15-72
Example 15-66. $OFFSET Routine 15-72
Example 15-67. $OFFSET Routine Applied to a Template Structure 15-73
Example 15-68. Parameters Passed Conditionally and Unconditionally 15-74
Example 15-69. Parameters Omitted Conditionally and Unconditionally 15-75
Example 15-70. Parameters Passed Conditionally 15-75
Example 15-71. $OPTIONAL Routine for a Front-End Interface 15-75
Example 15-72. $OVERFLOW Routine 15-77
Example 15-73. $PARAM Routine 15-77
Example 15-74. $POINT Routine 15-78
Example 15-75. $READBASELIMIT Routine 15-79
Example 15-76. $READCLOCK Routine 15-80
Example 15-77. $READSPT Routine 15-81
Example 15-78. $READTIME Routine 15-81
Example 15-79. $SCALE Routine 15-82
Example 15-80. Using the $SCALE Routine to Maintain Precision 15-83
Example 15-81. $SGBADDR_TO_EXTADDR Routine 15-83
Example 15-82. $SGBADDR_TO_SGWADDR Routine 15-84
Example 15-83. $SGWADDR_TO_EXTADDR Routine 15-85
Example 15-84. $SGWADDR_TO_SGBADDR Routine 15-85
Example 15-85. $SPECIAL Routine 15-86
Example 15-86. $STACK_ALLOCATE Routine 15-87
Example 15-87. $TRIGGER Routine 15-88
Example 15-88. $TYPE Routine 15-89
Example 15-89. $UDBL Routine 15-90
Example 15-90. $UDIVREM16 Routine 15-91
Example 15-91. $UDIVREM32 Routine 15-92
Example 15-92. $UNLOCKPAGE Routine 15-93
Example 15-93. $WADDR_TO_BADDR Routine 15-94
Example 15-94. $WADDR_TO_EXTADDR Routine 15-94

HP pTAL Reference Manual—523746-006


xxv
Contents Examples (continued)

Examples (continued)
Example 15-95. $WRITEPTE Routine 15-95
Example 15-96. $XADR Routine 15-96
Example 16-1. Compiler Command Lines 16-2
Example 16-2. Naming a Compilation Unit 16-13
Example 16-3. Declaring a Named Data Block 16-13
Example 16-4. Data Block and Variable With the Same Name 16-13
Example 16-5. Declaring a Private Data Block 16-14
Example 16-6. Declaring Unblocked Data 16-14
Example 17-1. Compilation Commands With Compiler Directives 17-2
Example 17-2. Pushing and Popping a Directive Stack 17-5
Example 17-3. DEFINETOG, IF, and ENDIF Directives 17-7
Example 17-4. DEFINETOG, IFNOT, and ENDIF Directives Directive 17-7
Example 17-5. SETTOG, IF, and ENDIF Directives 17-7
Example 17-6. SETTOG, IFNOT, and ENDIF Directives 17-7
Example 17-7. SETTOG, RESETTOG, IF, and ENDIF Directives 17-8
Example 17-8. MYPROG Source File for Example 17-9 Through
Example 17-12 17-10
Example 17-9. Saving Global Data Declarations and Data Initializations 17-10
Example 17-10. Retrieving Global Data Declarations and Data Initializations 17-11
Example 17-11. Checking the Syntax of Global Data Declarations 17-11
Example 17-12. Recompiling MYPROG After Correcting Errors 17-11
Example 17-13. Original SAVEGLOBALS Compilation Source File 17-12
Example 17-14. New GLOBALS Source File 17-12
Example 17-15. Corrected SAVEGLOBALS Compilation Source File 17-13
Example 17-16. DEFEXPAND Directive 17-27
Example 17-17. FIXERRS Macro 17-32
Example 17-18. ERRORFILE Directive 17-32
Example 17-19. ERRORS Directive 17-33
Example 17-20. GP_OK, NOGP_OK, PUSHGP_OK, and POPGP_OK
Directive 17-39
Example 17-21. IF Directive Without Matching ENDIF Directive 17-41
Example 17-22. IF Directive With Matching ENDIF Directive 17-42
Example 17-23. INNERLIST and NOINNERLIST Directives 17-43
Example 17-24. Listing Source Code But Not System Declarations 17-45
Example 17-25. File for OPTIMIZEFILE Directive 17-48
Example 17-26. OVERFLOW_TRAPS Compiler Directive 17-50
Example 17-27. PAGE Directive 17-51
Example 17-28. PRINTSYM Directive 17-52

HP pTAL Reference Manual—523746-006


xxvi
Contents Examples (continued)

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 64-
Bit 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. Parentheses’ Effect on Operator Precedence 5-4
Figure 5-2. Ending Address After Comparing INT Strings 5-27
Figure 5-3. Ending Address After Comparing Strings of Data Type STRING and
INT 5-28
Figure 9-1. Alignment of SHARED8 Structure With Base Alignment of 8 9-10
Figure 9-2. Well-Aligned and Misaligned SHARED8 Structures With Base Alignment
of 8 9-11
Figure 9-3. Alignment of a SHARED8 Structure With Base Alignment of 4 9-12
Figure 9-4. Well-Aligned and Misaligned SHARED8 Structures With Base Alignment
of 4 9-13
Figure 11-1. Indirect Array 11-8
Figure 11-2. Equivalenced Simple Variables 11-10
Figure 11-3. The Object and Address Types of a Pointer 11-13
Figure 11-4. Equivalenced Simple Pointer Declaration 11-14
Figure 11-5. Equivalenced Definition Structure for CISC Architecture 11-19
Figure 16-1. Compiling and Linking pTAL Programs 16-1

HP pTAL Reference Manual—523746-006


xxvii
Contents Figures (continued)

Figures (continued)
Figure 16-2. Creating a Loadfile on TNS/E for TNS/E 16-8
Figure 16-3. Creating Loadfiles on TNS/R for TNS/R 16-9
Figure 16-4. Creating a Loadfile on TNS for TNS/R 16-10
Figure 16-5. Producing Hybrid Loadfiles 16-11

Tables
Table i. Related Manuals xxxiv
Table ii. System Manuals xxxiv
Table iii. Programming Manuals xxxiv
Table iv. Program Development Manuals xxxv
Table 1-1. EpTAL, pTAL, and TAL Compiler Characteristics 1-2
Table 1-2. HP NonStop Operating Systems 1-2
Table 2-1. Special Characters 2-2
Table 2-2. Reserved Keywords 2-3
Table 2-3. Nonreserved Keywords 2-3
Table 2-4. Delimiters 2-4
Table 2-5. Operators 2-5
Table 2-6. Base Address Symbols 2-7
Table 2-7. Indirection Symbols 2-7
Table 2-8. Identifier Classes 2-9
Table 2-9. Variable Types 2-10
Table 3-1. Storage Units 3-1
Table 3-2. Data Types 3-1
Table 3-3. Operations by Data Type 3-4
Table 3-4. Data Types and Their Address Types 3-5
Table 3-5. Valid Address Conversions 3-9
Table 4-1. TNS/R Native Atomic Misalignment Handling Methods 4-3
Table 5-1. Precedence of Operators 5-3
Table 5-2. Operands in Arithmetic Expressions 5-5
Table 5-3. Arithmetic Expressions 5-6
Table 5-4. Signed Arithmetic Operators 5-6
Table 5-5. Signed Arithmetic Operand and Result Types 5-6
Table 5-6. Unsigned Arithmetic Operators 5-8
Table 5-7. Unsigned Arithmetic Operand and Result Types 5-9
Table 5-8. Bitwise Logical Operators 5-10
Table 5-9. Valid Address-Type Comparisons 5-11
Table 5-10. Valid Address Expressions 5-13
Table 5-11. Conditional Expressions 5-16

HP pTAL Reference Manual—523746-006


xxviii
Contents Tables (continued)

Tables (continued)
Table 5-12. Conditions in Conditional Expressions 5-16
Table 5-13. Results of NOT, OR, and AND Operators 5-17
Table 5-14. Signed Relational Operators 5-18
Table 5-15. Unsigned Relational Operators 5-19
Table 5-16. Special Expressions 5-20
Table 5-17. Bit Operations 5-31
Table 5-18. Bit-Shift Operators 5-34
Table 9-1. Kinds of Structures 9-1
Table 9-2. Structure Items 9-3
Table 9-3. Base Alignment and Field Alignment Relationships 9-9
Table 9-4. Field Alignment of Substructures 9-19
Table 9-5. Variable Alignment 9-22
Table 9-6. Data Accessed by Simple Pointers 9-49
Table 9-7. Addresses in Simple Pointers 9-50
Table 9-8. Addresses in Structure Pointers 9-53
Table 10-1. Address Types 10-6
Table 10-2. Object Data Types and Their Addresses 10-7
Table 11-1. Equivalenced Variables 11-1
Table 11-2. Equivalenced Variable Terminology 11-1
Table 11-3. Valid Equivalenced Variable Declarations 11-2
Table 11-4. Data Types for Equivalenced Variables 11-13
Table 12-1. Summary of Statements 12-1
Table 13-1. Hardware Indicators 13-1
Table 14-1. Formal Parameter Specification 14-14
Table 15-1. Built-In Routines for Atomic Operations 15-4
Table 15-2. pTAL Privileged Routines 15-11
Table 15-3. Built-In Type-Conversion Routines 15-12
Table 15-4. Built-In Address-Conversion Routines 15-14
Table 15-5. Built-In Character-Test Routines 15-14
Table 15-6. Built-In Minimum and Maximum Routines 15-15
Table 15-7. Built-In Arithmetic Routines 15-15
Table 15-8. Built-In Carry and Overflow Routines 15-15
Table 15-9. Built-In FIXED-Expression Routines 15-15
Table 15-10. Built-In Variable-Characteristic Routines 15-16
Table 15-11. Built-In Procedure-Parameter Routines 15-16
Table 15-12. Miscellaneous Built-In Routines 15-16
Table 15-13. Built-In Routines for Nonatomic Operations 15-17
Table 15-14. $OCCURS for Nonstructure Arrays 15-69

HP pTAL Reference Manual—523746-006


xxix
Contents Tables (continued)

Tables (continued)
Table 15-15. $OCCURS for Structure Arrays and Arrays Within Structures 15-70
Table 16-1. Completion Codes 16-6
Table 17-1. Compiler Directives by Category 17-14
Table 17-2. Compiler Directives by Name 17-17
Table 17-3. Data Block Names 17-21
Table 18-1. pTAL Cross Compiler Platforms 18-1

HP pTAL Reference Manual—523746-006


xxx
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
What’s New in This Manual New and Changed Information

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 transaction-
oriented 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
About This Manual Additional Information

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
About This Manual Additional Information

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 Documents the data alignment
Addendum 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 Documents the data alignment
Addendum 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
About This Manual Additional Information

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 machine-
level interactive debugger
nld Manual Explains how to use the nld utility to link
and change the attributes of TNS/R non-
PIC 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 non-
PIC)
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
About This Manual Notation Conventions

Table iv. Program Development Manuals (page 3 of 3)


Manual Description
SCF Reference Manual for the Kernel Describes the Subsystem Control Facility
Subsystem (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 machine-
level 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
About This Manual Syntax Diagram Conventions

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
KEYWORD
lowercase.
VST412.vsd

item Replace item with a value that fits its description, which follows the
syntax diagram.
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
About This Manual Syntax Diagram Conventions

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
About This Manual Syntax Diagram Conventions

• 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 block-name 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
About This Manual Notation for Messages

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
About This Manual Change Bar Notation

% 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
Introduction to pTAL EpTAL, pTAL, and TAL Compilers

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 On Guardian platforms, object files have the
file code 700 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
Introduction to pTAL pTAL Applications

For more information:


Topic Source
Itanium® chips used in TNS/E Intel Itanium Architecture Software Developer’s Manual
systems
RISC chips used in TNS/R MIPS RISC Architecture by Gerry Kane and Joe Heinrich
systems
TNS/R or TNS/E architecture System description manual for your system
Compiling pTAL source Section 16, Compiling and Linking pTAL Programs
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

° Conversion routines that allow data transfer between HP software and other
applications

° Procedures that are callable from programs written in other languages

° 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
Introduction to pTAL pTAL Features

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
Introduction to pTAL Recursion

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
Introduction to pTAL Pointers

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
Introduction to pTAL System Procedures

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 run-
time 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
Introduction to pTAL pTAL and the CRE

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
Language Elements Character Set

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
Language Elements Keywords

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
Language Elements Delimiters

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)


Character
Symbol Representation Uses
! Exclamation mark Begins and optionally ends a comment
-- Two consecutive Begins a comment
hyphens
, Comma Separates fields of information, such as in declarations,
statements, directives, and constant lists
; Semicolon • Terminates data declarations
• Separates statements
• Separates declaration options
. Period Separates identifier levels in a qualified structure item
identifier
<n :n > Angle brackets Delimits a bit field in a bit operation
: Colon • Denotes a statement label
• Denotes a procedure entry point
• Denotes an ASSERT statement assert level
• Denotes a parameter pair
() Parentheses • 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
[n :n ] Square brackets Delimit the bounds specification in the declaration of an
array, structure, or substructure

HP pTAL Reference Manual—523746-006


2 -4
Language Elements Operators

Table 2-4. Delimiters (page 2 of 2)


Character
Symbol Representation Uses
-> Hyphen plus right • Begins one or more labels in a labeled CASE
angle bracket 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 The first quotation mark indicates that the second
quotation marks quotation mark is not a delimiter in a character string
= Equal sign • Used in LITERAL declarations
• Used in equivalence variable declarations
• Used in redefinition declarations
= body # Equal sign and hash Delimit the body in a DEFINE declaration
mark
‘,’ Single quotation Delimit a comma that is not a delimiter in a DEFINE
marks 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

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
Language Elements Operators

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
Arithmetic expression + 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
Relational expression < 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

HP pTAL Reference Manual—523746-006


2 -6
Language Elements Base Address Symbols

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 Declares ...
. (period) • An array or structure as having standard direct addressing
• A simple pointer or structure pointer
.EXT • 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
Language Elements Declarations

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
Language Elements Identifiers

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
Language Elements Variables

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
Language Elements Scope

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; ! j has local scope and is visible everywhere in
! procedure p from this point forward.
subproc s; ! 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; ! This i is global
proc p;
begin
int i; ! This i is local to procedure p, different
! from global variable i, and makes access to
! global variable i impossible ("hides" it).
i := i + 1D; ! ERROR: local variable i is INT(16)
end;

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
Language Elements Constants

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 Values the Data Type Can Represent
STRING Byte • 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 Representation Data Types

Table 3-2. Data Types (page 2 of 2)


Data Type Storage Unit1 Values the Data Type Can Represent
INT Word • String of one or two ASCII characters
INT(16)2
• 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 Doubleword 32-bit floating-point number in the range
REAL(32)4 ±8.6361685550944444E-78 through
±1.15792089237316192E, precise to approximately
6.5 significant decimal digits.
FIXED Quadrupleword 64-bit fixed-point number. For FIXED, FIXED(0),
FIXED(0) FIXED (*), and INT(64) the range is
INT(64)3 -9,223,372,036,854,775,808 through
FIXED(-19 to -1) +9,223,372,036,854,775,807.
FIXED(1 to 19)
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
Data Representation Specifying Data Types

Specifying Data Types


The syntax for specifying the data type in a variable declaration is:

STRING

INT

REAL ( width )
UNSIGNED ( width )
FIXED

( fpoint )

*
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 Representation Data Type Aliases

*(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


INT or INT(32) or
UNSIGNED UNSIGNED REAL or
Operation STRING (1-16) (17-31) FIXED 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
Data Representation Address Types

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 .s; STRING BADDR Byte
INT .i; INT WADDR Word
INT(32) .j; INT(32) WADDR Word
REAL .r; REAL WADDR Word
REAL(64) .s; REAL(64) WADDR Word
FIXED .f; FIXED WADDR Word
UNSIGNED(n) .u; UNSIGNED WADDR Word
STRUCT .t; none WADDR Word
SUBSTRUCT .v; none BADDR Byte
addr-type 2 .a; address_type 3 WADDR Word
STRING .EXT s; STRING EXTADDR Byte
INT .EXT i; INT EXTADDR Byte
INT(32) .EXT j; INT(32) EXTADDR Byte
REAL .EXT r; REAL EXTADDR Byte
REAL(64) .EXT s; REAL(64) EXTADDR Byte
FIXED .EXT f; FIXED EXTADDR Byte
UNSIGNED(n) .EXT u; UNSIGNED EXTADDR Byte
STRUCT .EXT t; none EXTADDR Byte
SUBSTRUCT .EXT v; none EXTADDR Byte
addr-type 2 .EXT a; address_type 3 EXTADDR Byte
STRING .SG s; STRING SGBADDR Byte
INT .SG i; INT SGWADDR Word
INT(32) .SG j; INT(32) SGWADDR Word
REAL .SG r; REAL SGWADDR Word
REAL(64) .SG s; REAL(64) SGWADDR Word
FIXED .SG f; FIXED SGWADDR Word
UNSIGNED(n) .SG u; UNSIGNED SGWADDR Word
addr-type 2 .SG a; address_type 3 SGWADDR Word
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
Data Representation Address Types

Table 3-4. Data Types and Their Address Types (page 2 of 2)


Pointer Declaration Data Type Address Type Storage Unit1
STRING .SGX s; STRING SGXBADDR Byte
INT .SGX i; INT SGXWADDR Word
INT(32) .SGX j; INT(32) SGXWADDR Word
REAL .SGX r; REAL SGXWADDR Word
REAL(64) .SGX s; REAL(64) SGXWADDR Word
FIXED .SGX f; FIXED SGXWADDR Word
UNSIGNED(n) .SGX u; UNSIGNED SGXWADDR Word
addr-type 2 .SGX a; address_type 3 SGXWADDR Word
PROC p; PROC PROCADDR Doubleword
PROCPTR p(); END PROCPTR PROCADR Doubleword
PROCPTR
procedure e; PROC PROCADDR Doubleword
ENTRY
STRING v ='p':="ab"; STRING CBADDR Byte
INT v ='p':="ab"; INT CWADDR Word
SUBPROC SUBPROC CWADDR Word
Subprocedure ENTRY e; CWADDR Word
LABEL 1; LABEL CWADDR Word
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
Data Representation Storing Addresses in Variables

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
Data Representation Converting Between Address Types

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
Data Representation Using Indexes to Access Array Elements

Table 3-5. Valid Address Conversions


FROM
S S P
S G S G E R
C C G X G X X O
B W B W B B W W T C
A A A A A A A A A A
D D D D D D D D D D
D D D D D D D D D D
TO R R R R R R R R R R INT INT(32)
BADDR = R R R
WADDR R = R R
CBADDR =
CWADDR =
SGBADDR = = R R I
SGXBADDR = = R R I
SGWADDR R R = = I
SGXWADDR R R = = I
EXTADDR R R E E R R R R = I
PROCADDR =
INT I I I I = E
INT(32) I E =
Key to Symbols = 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] ! This statement is equivalent to
@p := @p '+' 4; ! 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; ! Increment WADDR pointer by four 16-bit words
@p := 4 '+' @p; ! Increment WADDR pointer by four 16-bit words
@p := @p[2];

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; ! Decrement WADDR pointer by four 16-bit words
@p := 4 '-' @p; ! 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; ! Unsigned arithmetic on WADDRs
@p := 4 '+' @p; ! Unsigned arithmetic on WADDRs
@e := @e + 8D; ! 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
Data Representation Constants

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
Data Representation Character String

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"; ! OK
s := "ab"; ! OK: same as s := "b"
s := "abc"; ! ERROR: too big
i := "a"; ! OK
i := "ab"; ! OK: same as s := "b"
i := "abc"; ! ERROR: too big

HP pTAL Reference Manual—523746-006


3- 13
Data Representation STRING Numeric

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
Data Representation INT Numeric

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
Data Representation INT(32) Numeric

INT(32) Numeric
Representation Signed or unsigned 32-bit integer
Range -2,147,483,648 through 4,294,967,295

ns
integer D
ns
+ base %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
Data Representation FIXED Numeric

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
Data Representation FIXED Numeric

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
Data Representation REAL and REAL(64) Numeric

REAL and REAL(64) Numeric

integer . fraction
+
-

E exponent
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
Data Representation REAL and REAL(64) Numeric

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 2.0L0
0.2E1 0.2L1
20.0E-1 20.0L-1
-17.2 -17.2E0 -17.2L0
-1720.0E-2 -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
Data Representation Constant Lists

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

[ constant-list-seq ]

repetition-factor *

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
Data Representation Constant List Alignment Specification

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
Data Representation Constant List Alignment Specification

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", "a" "b"
%20D]; c[0]
!Mixed constant list "c" "d"

c[1] 1D

c[2] 3D

"X" "Y"
c[3]
"Z" 0

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
Data Alignment Misalignment Tracing Facility

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
Data Alignment Misalignment Handling

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 After rounding down a misaligned address, the system proceeds to access
(default) 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
Data Alignment Misalignment Handling

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 An expression, consisting of operands and 398 + num / 84
expression arithmetic operators, that produces a single 10 LOR 12
numeric value.
Address An expression containing relational operators, IF @p = 0 THEN ...
expression that allows you to compare addresses, or
compare an address to a constant.
Constant An arithmetic expression that contains only 398 + 46 / 84
expression constants, LITERALs, and DEFINEs as operands.
Conditional An expression establishing the relationship a < c
expression between values and resulting in a true or false a OR b
value. A conditional expression consists of
relational conditions and conditional operators.

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
Expressions Data Types of 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
Expressions Operator Precedence

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 1
@ Address of identifier
+ Unary plus
- Unary minus
<...> Bit extraction 2
* Signed multiplication 3
/ Signed division
'*' Unsigned multiplication
'/' Unsigned division
'\' Unsigned remainder
+ Signed addition 4
- Signed subtraction
'+' Unsigned addition
'-' Unsigned subtraction
LOR Bitwise logical OR
LAND Bitwise logical AND
XOR Bitwise exclusive OR

HP pTAL Reference Manual—523746-006


5 -3
Expressions Operator Precedence

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) (a OR b) AND c

Result Result
Result
VST003.vsd

HP pTAL Reference Manual—523746-006


5 -4
Expressions Arithmetic 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, var[10]
pointer, structure data item, or equivalenced variable,
with or without @ or an index
Constant A character string or numeric constant 103375
LITERAL The identifier of a named constant file_size
Function The invocation of a procedure that returns a value $LEN (x)
invocation
expression Any expression x := y
(expression) Any expression, enclosed in parentheses (x := y)
Code space item The identifier of a procedure, subprocedure, or label @label_a
prefixed with @ or a read-only array optionally prefixed
with @, with or without an index

HP pTAL Reference Manual—523746-006


5 -5
Expressions Signed Arithmetic Operators

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
Expressions Scaling of FIXED Operands

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 The system adjusts the smaller fixed-point to match the larger fixed-point.
subtraction 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
Expressions Using FIXED(*) Variables

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; ! f1 = 1234
f2 := f1; ! f2 = 1234.000
f1 := f2; ! f1 = 1234000
f2 := f1; ! f2 = 1234000.000
f1 := f2; ! f1 = 1234000000
f2 := f1; ! f2 = 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 alpha '+' beta
UNSIGNED(1-16)
'-' Unsigned subtraction STRING, INT, or alpha '-' beta
UNSIGNED(1-16)
'*' Unsigned multiplication STRING, INT, or alpha '*' beta
UNSIGNED(1-16)

HP pTAL Reference Manual—523746-006


5 -8
Expressions Unsigned Arithmetic Operators

Table 5-6. Unsigned Arithmetic Operators (page 2 of 2)


Operator Operation Operand Type Example
'/' Unsigned division INT(32) or UNSIGNED alpha '/' beta
(17-31) dividend and
STRING, INT, or
UNSIGNED(1-16) divisor
'\' Unsigned remainder* INT(32) or UNSIGNED alpha '\' beta
(17-31) dividend and
STRING, INT, or
UNSIGNED(1-16) divisor
* 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


Result
Operator Operand Type Operand Type Type Example
'+' '-' 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) STRING, INT, or INT dbwd '\' word1
or INT(32) dividend UNSIGNED(1-16)
divisor

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
Expressions Bitwise Logical Operators

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 STRING, INT, or 1 LOR 1 = 1 10 LOR 12 = 14
logical OR UNSIGNED(1-16) 1 LOR 0 = 1 10 1 0 1 0
0 LOR 0 = 0 12 1 1 0 0
__ _ _ _ _
14 1 1 1 0
LAND Bitwise STRING, INT, or 1 LAND 1 = 1 10 LAND 12 = 8
logical UNSIGNED(1-16) 1 LAND 0 = 0 10 1 0 1 0
ADD 0 LAND 0 = 0 12 1 1 0 0
__ _ _ _ _
8 1 0 0 0
XOR Bitwise STRING, INT, or 1 XOR 1 = 0 10 XOR 12 = 6
exclusive UNSIGNED(1-16) 1 XOR 0 = 1 10 1 0 1 0
OR 0 XOR 0 = 0 12 1 1 0 0
__ _ _ _ _
6 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
Expressions Comparing Addresses

• 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


Extended Addresses Non-Extended Addresses
Operators Unsigned relational operators: Unsigned relational operators:
none '<', '=', '>', '<=', '<>', '>='
Signed relational operators: Signed relational operators:
<, =, >, <=, <>, >= =, <>
Abbreviated forms Testing address type as true or Testing address type as true or
false: false:
IF @p THEN IF @p THEN
IF NOT @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
Expressions Extended Addresses

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 ... ! OK: e and @i are both EXTADDR
IF @i >= 0D THEN ... ! OK: @i is EXTADDR, 0D is 32 bits
IF e = 0D THEN ... ! OK
IF e <> 0D THEN ... ! OK
IF e THEN ... ! OK
IF NOT e THEN ... ! OK
IF e > i THEN ... ! ERROR: e is EXTADDR, i is INT
IF e '<' @i THEN ... ! 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 ... ! OK: @s is BADDR, b is BADDR
IF @s = @b THEN ... ! ERROR: @s is BADDR, @b is WADDR

HP pTAL Reference Manual—523746-006


5- 12
Expressions Nonextended Addresses

• 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 ... ! OK
IF @p = 100D THEN ... ! 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 word-
oriented (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
Expressions Constant Expressions

Table 5-10. Valid Address Expressions (page 2 of 2)


Template Result Type Examples
EXTADDR relational INT EXTADDR b1, b2;
EXTADDR INT i;
IF b1 < b2 THEN ...;
i := b1 < b2;
relational must be a signed relational
operation (<, =, >, <=, <>, >=).
atype relational INT BADDR b1;
CONSTANT INT i;
IF b1 '>' 100 THEN ...;
i := b1 '<>' nil;
relational must be an unsigned
relational operation ('<', '=', '>', '<=', '<>',
'>=') or signed equal or not equal (=, <>).
EXTADDR relational INT EXTADDR b1;
CONSTANT 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
Expressions Conditional 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
Expressions Conditional 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 Two conditions connected by a If a = b THEN ...
expression relational operator. The result type
is INT; a -1 if true or a 0 if false.
The example is true if A equals B.
Group Unsigned comparison of a group IF a = b FOR 20 WORDS THEN ...
comparison of contiguous elements with
expression another. The result type is INT; a
-1 if true or a 0 if false. The
example compares 20 words of
two INT arrays.
(conditional A conditional expression enclosed IF NOT (b OR c) THEN ...
expression) 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.
Arithmetic An arithmetic, assignment, CASE, IF x THEN ...
expression 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.
Relational A signed or unsigned relational IF < THEN ...
operator 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 an arithmetic expression has a result other than INT, use a signed relational expression.

HP pTAL Reference Manual—523746-006


5- 16
Expressions NOT, OR, and AND Operators

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 STRING, INT, or True/False NOT a
for false state UNSIGNED(1-16)
OR Disjunction; produces STRING, INT, or True/False a OR b
true state if either UNSIGNED(1-16)
adjacent condition is
true
AND Conjunction; produces STRING, INT, or True/False a AND b
true state if both UNSIGNED(1-16)
adjacent conditions are
true

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
Expressions Relational Operators

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
Expressions Relational Operators

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), True/False
UNSIGNED (1-16)
'=' Unsigned equal to STRING, INT, True/False
UNSIGNED (1-16)
'>' Unsigned greater than STRING, INT, INT(32), True/False
UNSIGNED (1-16)
'<=' Unsigned less than or equal to STRING, INT, INT(32), True/False
UNSIGNED (1-16)
'>=' Unsigned greater than or equal to STRING, INT, INT(32), True/False
UNSIGNED (1-16)
'<>' Unsigned not equal to STRING, INT, INT(32), True/False
UNSIGNED (1-16)

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
Expressions Special 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
Expressions CASE

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 BEGIN expression-1


;

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
Expressions CASE

• 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; int i;
fixed(2) f2; fixed(2) f2;
fixed(3) f3; fixed(3) f3;
fixed(3) proc p; fixed(3) proc p;
begin begin
return if i then f2 return if i then $scale(f2,1);
else f3; else f3;
end end
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; ! If a is 0, assign value of b to X.
c; ! If a is 1, assign value of c to X.
d; ! If a is 2, assign value of d to X.
OTHERWISE -1; ! If a is any other value,
END; ! assign -1 to x.

HP pTAL Reference Manual—523746-006


5- 22
Expressions IF

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; int i;
fixed(-2) f2; fixed(-2) f2;
fixed(-3) f3; fixed(-3) f3;
fixed(-4) f4; fixed(-4) f4;
fixed(-2) proc p; fixed(-2) proc p;
begin begin
return case i of return case i of
begin begin
f3; $scale(f3,1);
f2; f2;
otherwise f4 otherwise $scale(f4,2)
end end
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
Expressions Group Comparison

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 relational-operator

var-2 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 read-
only array.
HP pTAL Reference Manual—523746-006
5- 24
Expressions Group Comparison

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 STRING Bytes
(including those declared in structures) INT Words
INT(32) or REAL Doublewords
FIXED or REAL(64) Quadruplewords
Structure Not applicable Words
Substructure Not applicable Bytes
Structure pointer STRING Bytes
INT Words

HP pTAL Reference Manual—523746-006


5- 25
Expressions Group Comparison

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, STRING Bytes
simple pointer (including INT Words
those declared in INT(32) or REAL Doublewords
structures) FIXED or REAL(64) Quadruplewords
Structure Not applicable Structure
(For structure pointers, occurrences
STRING and INT have
meaning only in group
comparison expressions
and move statements.)
Substructure Not applicable Substructure
occurrences
Simple variable, array, STRING Bytes
simple pointer (including INT Words
those declared in INT(32) or REAL Doublewords
structures) FIXED or REAL(64) Quadruplewords

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
Expressions Group Comparison

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
Expressions Group Comparison

Figure 5-2. Ending Address After Comparing INT Strings (page 2 of 2)

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 x[0:1] := ["AB","CD"];
STRING y[0:1] := ["A","C"];
STRING p;
INT q;
IF x = y FOR 1 WORDS -> @p THEN ... ;
q := p; ! Assign "BC" to q
END;

User Data Segment A B C D A C

X Y

VST132.vsd

HP pTAL Reference Manual—523746-006


5- 28
Expressions Group Comparison

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
Expressions Group Comparison

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 ... ; ! Compare var[0] to one byte
IF var = 0 THEN ... ; ! Compare var[0:1] to two bytes or
! one 16-bit word

HP pTAL Reference Manual—523746-006


5- 30
Expressions Bit Operations

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 int-
expression 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
Expressions Bit Extractions

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 i;
UNSIGNED(4) j;
STRING k;
INT(32) 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
Expressions Bit Shifts

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
Expressions Bit Shifts

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 Zeros fill vacated bits from the right
through bit 0
'>>' 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
Expressions Bit Shifts

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 = 0 010 111 010 101 000
'<<' 2 = 1 011 101 010 100 000
2. This unsigned right shift shows how zeros fill the vacated bits from the left:
Initial value = 1 111 111 010 101 000
'>>' 2 = 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 = 1 111 010 101 000 000
>> 3 = 1 111 111 010 101 000
4. These examples show multiplication and division by powers of two:
a := b << 1; ! Multiply by 2
a := b << 2; ! Multiply by 4
a := b >> 3; ! Divide by 8
a := b >> 4; ! 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]; ! INT array
STRING .p := @a[0] '<<' 1; ! Initialize STRING simple
! pointer with byte address
p[3] := 0; ! 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; ! INT variable
b := b '<<' 8; ! Shift right-byte value into left byte

HP pTAL Reference Manual—523746-006


5- 35
Expressions Bit Shifts

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
LITERALs and DEFINEs Declaring Literals

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 = -1,
false = 0,
buffer_length = 80,
table_size = 128,
table_base = %1000,
entry_size = 4,
timeout = %100000D,
CR = %15,
LF = %12;
All constants supplied by compiler:
LITERAL a, ! Compiler assigns 0
b, ! Compiler assigns 1
c; ! Compiler assigns 2

HP pTAL Reference Manual—523746-006


6 -2
LITERALs and DEFINEs Declaring DEFINEs

Example 6-1. Literal Declarations (page 2 of 2)


Two constants specified, six supplied by compiler:
LITERAL d, ! Compiler assigns 0
e, ! Compiler assigns 1
f, ! Compiler assigns 2
g = 0,
h, ! Compiler assigns 1
i = 17,
j, ! Compiler assigns 18
k; ! Compiler assigns 19
LITERAL identifier in array declaration:
LITERAL length = 50; ! Length of array
INT buffer[0:length - 1]; ! 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
LITERALs and DEFINEs Declaring 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
LITERALs and DEFINEs Calling 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; ! Structure item has same
END; ! 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
LITERALs and DEFINEs How the Compiler Processes DEFINEs

Example 6-4. Parenthesized and Nonparenthesized DEFINE Bodies


DEFINE expr = (5 + 2) #;
j := expr * 4; ! Expands to: (5 + 2) * 4;
! assigns 28 to j
DEFINE expr = 5 + 2 #;
j := expr * 4; ! 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
LITERALs and DEFINEs Passing Actual Parameters to 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
LITERALs and DEFINEs Passing Actual Parameters to 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
LITERALs and DEFINEs Passing Actual Parameters to DEFINEs

Example 6-13. Checking a Condition Code


INT error;
INT file;
INT .buffer[0:50];
INT count_written;
INT 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
Simple Variables Declaring 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
Simple Variables Specifying Simple Variable Address Types

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 a value in the range 1 through 31
(simple variable, parameter, or function result)
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; ! A pointer: address type is WADDR
INT i; ! 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
Simple Variables Examples

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"; ! Character string
STRING z := 255; ! Byte value
INT a := "AB"; ! Character string
INT b := 5 * 2; ! Expression
INT c := %B110; ! Word value
INT(32) dblwd2 := %B1011101D; ! Doubleword value
INT(32) dblwd3 := $DBL(%177775); ! Built-in routine
REAL flt1 := 365335.6E-3; ! Doubleword value
REAL(64) flt2 := 2718.2818284590452L-3; ! Quadrupleword value
WADDR w;
EXTADDR e;
INT t;
STRING s;
INT ro_wd = 'p' := 3;
STRING ro_b = 'p' := "A";
BADDR ba := @s;
WADDR wa := @t;
CWADDR cwa := @ro_wd;
CBADDR cba := @ro_b;
SGWADDR sgwa := 0;
SGBADDR sgnq := 1;
EXTADDR ea := $DBL (1);

Example 7-3. Effect of fpoint on FIXED Simple Variables


FIXED(-3) f := 642987F; ! Stored as 642; accessed as 642000
FIXED(3) g := 0.642F; ! Stored as 642, accessed as 0.642
FIXED(2) h := 1.234F; ! Stored as 123; accessed as 1.23

HP pTAL Reference Manual—523746-006


7 -5
Simple Variables Examples

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; !Any expression allowed
INT local2 := global * local; ! in local or sublocal
FIXED local3 := $FIX(local2); ! initialization
!Lots of code
END; ! 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 i;
VOLATILE UNSIGNED(3) mask;
VOLATILE STRING 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
Arrays Declaring 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
Arrays Declaring 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
Arrays Declaring 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]; ! Four-element array
INT .array_b[0:49]; ! Fifty-element array
UNSIGNED(1) flags[0:15]; ! Array of 16 one-bit elements

Example 8-2. Declaring Arrays and Initializing Them With Constants


INT a_array[0:3] := -1; ! Store -1 in element [0];
! values in elements [1:3] are undefined
INT b_array[0:1] := "abcd"; ! Store one character per byte

HP pTAL Reference Manual—523746-006


8 -4
Arrays Declaring 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; ! Length of array
STRING buffer[0:len - 1] := len * [" "]; ! 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]; ! Initialize global array
PROC my_procedure;
BEGIN
STRING b[0:1] := ["A","B"]; ! Initialize local standard array
FIXED EXT c[0:3]; ! Cannot initialize local
! extended indirect array
SUBPROC my_subproc;
BEGIN
INT d[0:2] := ["Hello!"]; ! Initialize sublocal array
! Lots of code
END;
END;

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
Arrays Declaring Read-Only 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
Arrays Declaring Read-Only 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' := [2,3,4]; ! OK
INT .j = 'P' := [5,6,7]; ! Compiler reports a warning
STRING k = 'P' := ["abc"]; ! OK
STRING .l = 'P' := ["ccc"]; ! Compiler reports a warning
END;

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
Arrays Using Constant Lists in Array Declarations

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 read-
only 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 = 'P' := "abcd"; ! OK
INT q[0:3] = 'P' := "abcdabcd"; ! OK
STRING r = 'P' := "abcd"; ! OK
STRING s[0:3] = 'P' := "abcd"; ! OK
STRING t = 'P' := [1,2,3]; ! 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]; ! OK
STRING w[0:3] = 'P' := [1,2,3,4]; ! OK
INT x = 'P' := "abc"; ! ERROR: Initialization size
! must be an integral
! multiple of array's base
! type size

HP pTAL Reference Manual—523746-006


8 -8
Arrays Nonstring 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 .a[0:3] := [0,1,2]; ! OK: Init string is shorter than array
INT .a[0:3] := [0,1,2,3]; ! OK: Init string is right length
INT .a[0:3] := [0,1,2,3,4]; ! ERROR: Init string is too long
INT .a[0:3] := [%H1234567812345678%F]; !OK: Init string is right length

HP pTAL Reference Manual—523746-006


8 -9
Arrays Nonstring 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 16-
byte 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
Structures Structure Layout

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 BEGIN-
END 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
Structures Overview of Structure Alignment

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 Structures Aligned at Odd-Byte Boundaries

• 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
Structures SHARED2

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
Structures PLATFORM

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
Structures Differences Between PLATFORM and AUTO

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
Structures Base Alignment

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
Structures Structure Alignment Examples

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 filler i32 s1 s2 filler f k filler


0 2 4 6 8 10 12 14 16 18 20 22 24 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
Structures Structure Alignment Examples

Figure 9-2. Well-Aligned and Misaligned SHARED8 Structures With Base


Alignment of 8

i filler i32 s1 s2 filler f k filler


0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Misaligned fields: none

i filler i32 s1 s2 filler f k filler


0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Misaligned fields: i32, f

i filler i32 s1 s2 filler f k filler


0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Misaligned fields: f

i filler i32 s1 s2 filler f k


0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Misaligned fields: i32, f

i filler i32 s1 s2 filler f


0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Misaligned fields: none

VST009.vsd

HP pTAL Reference Manual—523746-006


9- 11
Structures Structure Alignment Examples

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 FIELDALIGN(SHARED8); ! Base alignment is 4
BEGIN
STRING s1 ! Begins at offset 0
FILLER 3; ! 3 bytes of filler required
INT(32) i32a; ! Begins at offest 4
STRING s2 ! Begins at offset 8
STRING s3 ! Begins at offset 9
FILLER 2; ! 2 bytes of filler required
INT(32) i32b; ! Begins at offest 12
INT k; ! Begins at offest 16
FILLER 2; ! Must pad to multiple of base alignment
END; ! Total length of s2: 20 bytes

s1 filler i32a s2 s3 filler i32b k filler


0 2 4 6 8 10 12 14 16 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
Structures Array Alignment in 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 filler i32a s2 s3 filler i32b k filler


0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Misaligned fields: none

s1 filler i32a s2 s3 filler i32b k filler


0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
Misaligned fields: i32a, i32b

s1 filler i32a s2 s3 filler i32b k filler


0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30
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
Structures Array Alignment in 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); ! s1 is SHARED2
BEGIN ! Alignment is 2
INT i;
FILLER 2;
INT(32) j;
END;

Example 9-3. SHARED8: 4-Byte Alignment


STRUCT s2[0:9] FIELDALIGN(SHARED8); ! s2 is SHARED8
BEGIN ! Alignment is 4
INT i;
FILLER 2;
INT(32) j;
END;

HP pTAL Reference Manual—523746-006


9- 14
Structures Structure Alignment

Example 9-4. 8-Byte Alignment and 4-Byte Alignment


STRUCT s3[0:9] FIELDALIGN(SHARED8); ! s3 is SHARED8
BEGIN ! Alignment is 8
STRUCT s4[0:4]; ! s4 is SHARED8
BEGIN ! Alignment is 4
INT i;
FILLER 2;
INT(32) j;
END;
REAL(64) k;
END;

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); ! Base alignment of structure is
BEGIN ! 2 because of INT c
STRING a;
STRING b;
INT c; ! c is field with widest
END; ! alignment: 2
STRUCT s2 FIELDALIGN(SHARED8); ! Base alignment of structure is
BEGIN ! 4 because of INT(32) c
STRING a;
STRING b;
FILLER 2;
INT(32) c; ! c is field with widest
END; ! alignment: 4
STRUCT s3 FIELDALIGN(SHARED8); ! Base alignment of structure is
BEGIN ! 8 because of FIXED c
STRING a;
STRING b;
FILLER 6;
FIXED c; ! c is field with widest
END; ! alignment: 8

HP pTAL Reference Manual—523746-006


9- 15
Structures Substructure Alignment

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; ! Specified alignment of ss is SHARED8,
BEGIN ! inherited from s
INT(32) m;
INT n;
FILLER 2; ! Alignment of substructure ss is 4
END; ! FILLER 2 makes total length of ss 8
INT j;
STRING t[0:2];
FILLER 3; ! Alignment of structure s is 4: declare
END; ! 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
Structures Substructure Alignment

Example 9-7. SHARED8 Structures With SHARED2 Substructures


STRUCT t_s2(*) FIELDALIGN(SHARED2); ! Base alignment of t_s2
BEGIN ! is 2
INT(32) j;
END;
STRUCT t_s8(*) FIELDALIGN(SHARED8); ! Base alignment of t_s8
BEGIN ! is 4
INT(32) j;
END;

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); ! Reference alignment is 2
INT .p3(t_s8); ! 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
Structures Substructure Alignment

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); ! OK
BEGIN
FIXED i;
END;
STRUCT s2 FIELDALIGN(SHARED2); ! OK
BEGIN-
INT(32) i; ! OK
STRUCT sub (s1); ! WARNING: SHARED8
END; ! 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
Structures Alignment Considerations for Substructures

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

Substructure Structure Field Alignment


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); ! ERROR: Substructure cannot be
BEGIN ! FIELDALIGN(AUTO)
...
END;
END;

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
Structures FIELDALIGN Clause

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 FIELDALIGN(AUTO)
architecture
Shared between pTAL and TAL programs FIELDALIGN(SHARED2)
Shared by program modules written in different programming FIELDALIGN(PLATFORM)
languages and running on the same architecture
Shared between TNS, TNS/R, and TNS/E architecture with FIELDALIGN(SHARED8)
optimal performance on TNS/R and TNS/E architecture

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
Structures SHARED2 Parameter

• 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; ! Global pointer
PROC p;
BEGIN
@ptr := @str.F32; ! str.F32 might or might not be aligned
! at a 32-bit address. REFALIGNED
... := ptr + 3D; ! directive ensures that pTAL
! generates conservative code for
END; ! references to ptr.

HP pTAL Reference Manual—523746-006


9- 21
Structures SHARED8 Parameter

Example 9-13. Byte Offsets (Decimal) of Fields of a SHARED2 Structure


STRUCT s1 FIELDALIGN(SHARED2);
BEGIN
INT i; ! i begins at byte offset: 0
INT(32) j; ! j begins at byte offset: 2
STRING s1; ! s1 begins at byte offset: 6
UNSIGNED(3) u1; ! u1 begins at byte offset: 8
UNSIGNED(2) u2; ! u2 begins at byte offset: 8 + 3 bits
STRING s2; ! s2 begins at byte offset: 10
FIXED f; ! f begins at byte offset: 12
INT k; ! k begins at byte offset: 20
END;

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 2-byte field [INT or UNSIGNED(1-16)] must be an even


number, except that contiguous UNSIGNED fields can be packed.

° 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.
• 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 Notes
STRING 1
INT 2
* 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
Structures SHARED8 Parameter

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 Multiple UNSIGNED fields can be packed into a
doubleword.
FIXED 8
REAL(64) 8
* 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
Structures Alignment of Fields

• 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
Structures Optimizing Structure Layouts

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
Structures Structure Length

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 FIELDALIGN(SHARED8);
BEGIN
FIXED i; ! Structure's widest field is 8 bytes
INT(32) j; ! j is 4 bytes FILLER 4
FILLER 4; ! Pad with 4 bytes
END;
STRUCT s2 FIELDALIGN(SHARED8);
BEGIN
INT(32) i; ! Structure's widest field is 4 bytes
INT j; ! j is 2 bytes
FILLER 2; ! Pad with 2 bytes
END;

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
Structures Alignment of UNSIGNED(17-31) Fields

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
Structures REFALIGNED Clause

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); ! Standard pointer with REFALIGNED
! clause
INT. EXT e REFALIGNED(8); ! An extended pointer
END;

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
Structures Default Reference Alignment

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); ! Reference alignment is 2
INT .p2(s2); ! Reference alignment is 8
INT .p3(s3); ! 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
Structures REFALIGNED(2)

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; ! Suboptimal access
a := p4.i; ! Suboptimal access
a := p5.i; ! Suboptimal access
END;

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
Structures REFALIGNED(8)

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 well-
aligned. 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
Structures Code Generation for Structure References

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
Structures VOLATILE Attribute

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; ! A simple VOLATILE field
VOLATILE INT .EXT b; ! A VOLATILE extended pointer
VOLATILE INT .c REFALIGNED(2); ! A VOLATILE standard pointer
END; ! with a REFALIGNED clause

Declaring Definition Structures


STRUCT identifier
.

.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
Structures Declaring Definition 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
Structures Declaring Template 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 identifier ( * )

STRUCTALIGN ( MAXALIGN )

structure-layout ;

field-alignment

VST625.vsd

identifier
is the identifier of the template structure.

HP pTAL Reference Manual—523746-006


9- 35
Structures Declaring Template 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
Structures Declaring Template 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 (*); ! Template structure
BEGIN ! Structure layout
INT item;
FIXED(2) price;
INT quantity;
END;

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
Structures Declaring Referral 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.

STRUCT identifier ( 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
Structures Declaring Referral 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 (*); ! Declare template structure
BEGIN
STRING name[0:19];
STRING addr[0:29];
INT acct;
END;
STRUCT .customer (record) [1:50]; ! Declare referral structure

HP pTAL Reference Manual—523746-006


9- 39
Structures Declaring Simple Variables in 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:

type identifier ;

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]; ! Declare definition structure
BEGIN
INT item; ! Declare three simple variables
FIXED(2) price; ! within structure layout
INT quantity;
END;

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
Structures Declaring Arrays in 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; ! Declare definition structure
BEGIN
STRING name[0:19]; ! Declare arrays within the structure
STRING addr[0:29]; ! layout
INT acct;
END;

HP pTAL Reference Manual—523746-006


9- 41
Structures Declaring Substructures

Example 9-34. Using a Zero-Length Array to Initialize a Structure


STRUCT s;
BEGIN
STRING a[0:-1]; ! @a[0] is the same as @b
INT 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
Structures Definition Substructures

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
Structures Definition Substructures

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]; ! Two warehouses
BEGIN
STRUCT inventory [0:49]; ! Definition substructure
BEGIN ! 50 items in each warehouse
INT item_number;
FIXED(2) price;
INT on_hand;
END;
END;

HP pTAL Reference Manual—523746-006


9- 44
Structures Referral Substructures

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.

STRUCT identifier ( 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
Structures Declaring Filler

Example 9-36. Declaring a Referral Substructure


STRUCT temp(*); ! Template structure --
BEGIN ! no space allocated
STRING a[0:2];
INT b;
STRING c;
END;
STRUCT .ind_struct; ! Definition structure --
BEGIN ! space allocated
INT header[0:1];
STRING abyte;
STRUCT abc (temp) [0:1]; ! Declare referral substructure
END; ! 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
Structures Declaring Filler

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; ! Last occurrence
STRUCT .x[1:last];
BEGIN
STRING byte[0:2];
FILLER 1; ! Document word-alignment pad byte
INT word1;
INT word2;
INT(32) integer32;
FILLER 30; ! Place holder for unused space
END;

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; ! State = 0, 1, 2, or 3
BIT_FILLER 12; ! Place holder for unused space
END;

HP pTAL Reference Manual—523746-006


9- 47
Structures Declaring Simple Pointers in 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 )

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
Structures Using Simple Pointers

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; ! Standard simple pointer
STRING .EXT ext_pointer; ! Extended simple pointer
END;

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
Structures Assigning Addresses to Pointers in 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
Structures Declaring Structure Pointers in 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 )

VST628.vsd

HP pTAL Reference Manual—523746-006


9- 51
Structures Declaring Structure Pointers in 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
Structures Declaring Redefinitions

Table 9-8. Addresses in Structure Pointers


Addressing STRING or
Mode INT Attribute Kind of Address
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
* 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
Structures Simple Variable

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
Structures Array

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; ! Redefinition
END;

Array
An array redefinition associates a new array with a previous item at the same BEGIN-
END 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
Structures Definition Substructure

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; ! Redefine INT array as INT(32) array
END;

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 field-alignment

= previous-identifier ; 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
Structures Definition Substructure

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
Structures Definition Substructure

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; ! b starts on odd byte
BEGIN
STRING y;
END;
STRUCT c = b; ! Redefine b as c, also on odd byte
BEGIN
STRING z;
END;
END;

HP pTAL Reference Manual—523746-006


9- 58
Structures Referral Substructure

Example 9-46. Definition Substructure Redefinition


STRUCT mystruct;
BEGIN
STRUCT mysub1;
BEGIN
INT int_var;
END;
STRUCT mysub2 = mysub1; ! Redefine mysub1 as mysub2
BEGIN
STRING string_var;
END;
END;

Referral Substructure
A referral substructure redefinition associates a new referral substructure with a
previous item at the same BEGIN-END level of a structure.

STRUCT identifier ( 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
Structures Referral Substructure

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(*); ! Template structure
BEGIN
STRING a[0:2];
INT b;
STRING c;
END;
STRUCT .ind_struct; ! Definition structure
BEGIN
INT header[0:1];
STRING abyte;
STRUCT abc (temp) [0:1];
STRUCT xyz (temp) [0:1] = abc; ! Redefine abc as xyz
END;

HP pTAL Reference Manual—523746-006


9- 60
Structures Simple Pointer

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
Structures Simple 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.

Example 9-48. Simple Pointer Redefinition


STRUCT my_struct;
BEGIN
STRING var[0:5]; ! Simple variable
STRING .EXT ext_pointer = var; ! Redefine var as simple
! pointer, ext_pointer
END;

HP pTAL Reference Manual—523746-006


9- 62
Structures Structure Pointer

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 identifier
VOLATILE INT .

.EXT

.SG

.SGX

( referral )

REFALIGNED ( 2 )

= 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
Structures Structure Pointer

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; ! Redefinition
INT(32) ext_link_addr;
INT .EXT ext_link (record) = ext_link_addr; ! Redefinition
END;

HP pTAL Reference Manual—523746-006


9- 64
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
Pointers Overview of Pointer Declaration

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 )

;
:= 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
Pointers Overview of Pointer Declaration

• 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
Pointers Declaring VOLATILE 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
Pointers Structure

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; ! Field m is never treated as volatile
VOLATILE INT n; ! Field n is always treated as volatile
END;
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
Pointers Address Types

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


Address Pointer
Data Type Type Target Data Size Example
BADDR Byte 16-bit address to 1-byte- 32 STRING .s;
aligned data
WADDR Word 16-bit address to 2-byte- 32 INT .i;
aligned data
CBADDR Byte 16-bit address to 1-byte- 32 STRING s ='P':="A";
aligned, read-only data
CWADDR Word 16-bit address to 2-byte- 32 INT i = 'P' := 123;
aligned, read-only data
SGBADDR Byte 16-bit address to 1-byte- 16 STRING .SG s;
aligned, 'SG'-relative
data
SGWADDR Word 16-bit address to 2-byte- 16 INT .SG i;
aligned, 'SG'-relative
data
SGXBADDR Byte 32-bit address to 1-byte- 32 STRING .SGX s;
aligned, 'SG'-relative
data
SGXWADDR Word 32-bit address to 2-byte- 32 INT .SGX i;
aligned, 'SG'-relative
data
EXTADDR Byte 32-bit address to data 32 INT .EXT x;
PROCADDR N.A. First address of 32 PROC x;
procedure code BEGIN
END;

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
Pointers Address Types

Example 10-3. Determining Address Types


INT .j; ! Pointer: address type is WADDR
INT i; ! 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
Pointers Address Types

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
Pointers BADDR and WADDR

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; ! Variable: address type is WADDR
INT .b; ! Pointer: address type is WADDR
STRING .c; ! Pointer: address type is BADDR
INT(32) d[0:9]; ! Direct array: address type is WADDR
INT .e[0:9]; ! Indirect array: address type is 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 .SG s; ! s is 16 bits
INT .SG i; ! i is 16 bits
STRING .SGX t; ! t is 32 bits
INT .SGX j; ! j is 32 bits

HP pTAL Reference Manual—523746-006


10- 9
Pointers PROCADDR (Procedures, Procedure Pointers, and
Procedure Entry Points)

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; ! Address type of q is PROCADDR
pa := @p; ! Address type of p is PROCADDR
pa := @p1; ! Address type of p1 is PROCADDR
END;

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
Pointers EXTADDR

Example 10-7. CBADDR and CWADDR


INT sa = 'P' := [1,2,3,4]; ! Address type of sa is CWADDR
STRING sb = 'P' := ["ABCD"]; ! Address type of sb is CBADDR
PROC p;
BEGIN
LABEL lab1;
SUBPROC subp1;
BEGIN
CWADDR cw;
CBADDR cb;
ENTRY ent1;
ent1:
lab2:
cw := @subp1; ! Address type of @subp1 is CWADDR
cw := @lab1; ! Address type of @lab1 is CWADDR
cw := @lab2; ! Address type of @lab2 is CWADDR
cw := @ent1; ! Address type of @ent1 is CWADDR
cw := @sa; ! Address type of @sa is CWADDR
cb := @sb; ! Address type of @sb is CBADDR
END;
lab1:
END;

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 .EXT i;
STRING .EXT s;
INT .EXT g = 'SG' + 0;
REAL .EXT r;

HP pTAL Reference Manual—523746-006


10 -11
Pointers Declaring Simple 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 )

;
:= 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
Pointers Declaring Simple 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
Pointers Initializing Simple 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
Pointers Initializing Simple 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
Pointers Declaring Structure 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
Pointers Initializing Structure 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
Pointers Initializing Structure Pointers

Example 10-15. Declaring and Initializing a Structure Pointer, Using $OFFSET


STRUCT t (*); ! Template structure
BEGIN
INT k;
END;
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; ! STRING ptr
! initialized
! with converted
! byte address of
! astruct[1]
ptr.s2 := %4; ! Access STRING structure item

HP pTAL Reference Manual—523746-006


10 -18
Pointers Initializing Structure 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); ! Declare substructure
INT age;
END;
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; ! Structure pointer
END; ! contains address of
! array

HP pTAL Reference Manual—523746-006


10 -19
Pointers Declaring System Global 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 variable
Simple pointer Simple pointer
Structure Structure
Structure pointer 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 The equivalenced variable is a simple variable, direct array, direct
declaration 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 The equivalenced variable is a standard indirect array or standard
declaration indirect structure. Standard indirect items can be equivalenced
only to other standard indirect items.

HP pTAL Reference Manual—523746-006


11- 1
Equivalenced Variables Declaring Equivalenced Variables

Table 11-2. Equivalenced Variable Terminology (page 2 of 2)


Term Definition
Extended The equivalenced variable is an extended indirect array or
equivalent declaration extended indirect structure. Extended indirect items can be
equivalenced only to other extended indirect items.
Standard pointer The equivalenced variable is a pointer to data.
equivalent declaration
Extended pointer The equivalenced variable is a pointer to data in an EXTADDR.
equivalent declaration

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 Equivalenced Previous Variable
Variable Category Variable Variable Example Category
Direct Simple Variable INT i; Direct or Pointer
Direct array INT i[0:3];
Direct structure STRUCT s;
BEGIN
INT i;
END;
Indirect Indirect array INT .a[0:3]; Indirect
Indirect structure STRUCT .s;
BEGIN
INT i;
END;
Extended Extended array INT .EXT a[0:3]; Extended
Extended structure STRUCT .EXT s;
BEGIN
INT i;
END;

HP pTAL Reference Manual—523746-006


11- 2
Equivalenced Variables Declaring Equivalenced Variables

Table 11-3. Valid Equivalenced Variable Declarations (page 2 of 2)


Equivalenced Equivalenced Previous Variable
Variable Category Variable Variable Example Category
Standard Pointer Standard pointer INT .p; A pointer, simple
Standard structure INT .s(t); variable, indirect
pointer array, or indirect
structure
Extended Pointer Extended pointer INT .EXT e; Direct or Extended
Extended structure INT .EXT s(t); with the same
pointer 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 a; ! a is a simple variable, and cannot be indexed
INT b; ! "Previous variable" for the next decl
INT c = b; ! b and c can be indexed
INT d = c; ! 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]; ! OK: b and c appear in equivalenced declaration
d[2] := c[1]; ! OK: c and d appear in equivalenced declaration
d[2] := a; ! OK: d appears in equivalenced declaration
! and can be indexed.
a[1] := d; ! ERROR: a cannot be indexed

HP pTAL Reference Manual—523746-006


11- 3
Equivalenced Variables Memory Allocation

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; ! Increment second word of a
p[1] := p[1] + 1; ! Increment second word of p (= a)
w := @a; ! Assign address of first word of a to w
w := @p; ! 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
Equivalenced Variables Declaring Nonstructure 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 previous-
identifier.

referral
is the identifier of a previously declared structure, structure layout, or structure
pointer.

HP pTAL Reference Manual—523746-006


11- 5
Equivalenced Variables Declaring Nonstructure 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
Equivalenced Variables Memory Usage for Nonstructured 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 h;
FIXED i;
INT j = i; ! OK: j is smaller than i
INT(32) k = j; ! OK: k is 32 bits, i is 64 bits
FIXED l = h; ! 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 i; ! i is 64 bits
INT(32) j[0:1] = i; ! OK: j is 64 bits and coincident with i
INT k[0:1] = i; ! OK: k is 32 bits and contained within i
INT m[0:3] = k; ! OK: Although m is 64 bits and k is
! 32 bits, pTAL requires only that
! m be contained within i, not k.
INT x[0:15];
FIXED y = x[10]; ! 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
Equivalenced Variables Indirect Arrays

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 10
1001 20
1002 30
1003 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 Variables Equivalenced 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
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 Variables Equivalenced Simple Pointers

Figure 11-2. Equivalenced Simple Variables


INT w[0:1];
STRING b = w[0];
INT(32) d = b;

w[0] B[0] B[1]


D
w[1] B[2] B[3]

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 Variables Equivalenced Simple Pointers

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 previous-
identifier.

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 Variables Equivalenced Simple Pointers

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]; ! Indirect array
INT .b; ! Standard pointer
INT .c = a; ! OK: Equivalence a pointer to an indirect
! array (c is read-only)
INT .d[0:3] = b; ! ERROR: Cannot equivalence an indirect item
! to a pointer
@c := @c + 1; ! 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 Variables Equivalenced Simple Pointers

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 Variables Equivalenced Simple Pointers

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; ! a is a pointer to an INT
FIXED .b = a; ! 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
Equivalenced Variables Equivalencing PROCADDR Variables and
PROCPTR 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) ! Default reference alignment is 8
INT .p REFALIGNED(2); ! Reference alignment of p is 2
INT .q REFALIGNED(8) = p; ! Reference alignment of q is 8
INT .r REFALIGNED(2) = p; ! Reference alignment of r is 2
INT .s = p; ! Reference alignment of s is 8
INT .t; ! Reference alignment of t is 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; ! a is a procedure pointer
END PROCPTR;
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; ! e is a procedure pointer equivalenced to
END PROCPTR = a; ! another procedure pointer
PROCPTR f; ! f is a procedure pointer equivalenced to a
END PROCPTR = b; ! procedure address

HP pTAL Reference Manual—523746-006


11 -15
Equivalenced Variables Declaring Equivalenced Definition Structures

Declaring Equivalenced Definition Structures


An equivalenced definition structure declaration associates a new structure with a
previously declared variable.

STRUCT identifier ( referral )


.

.EXT

.SG

.SGX

= previous-identifier
field-alignment

;
[ index ] structure-layout
+ offset
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
Equivalenced Variables Declaring Equivalenced Definition Structures

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
Equivalenced Variables Declaring Equivalenced Definition Structures

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
Equivalenced Variables Declaring Equivalenced Definition Structures

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
Equivalenced Variables Structure Variants

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; ! v2 is equivalenced to v1
BEGIN ! v2 is 4 bytes
INT .EXT e;
END;
END;

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
Equivalenced Variables Memory Usage for Structured 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 FIELDALIGN(SHARED2); ! Structure a is 3 bytes
BEGIN
STRING i;
STRING j;
STRING k;
END;
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 FIELDALIGN(SHARED2) = b;
BEGIN
STRING i;
STRING j;
STRING k;
END;

HP pTAL Reference Manual—523746-006


11 -21
Equivalenced Variables FIELDALIGN Clause

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 Variables Equivalenced Simple Variable

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 Variables Equivalenced Definition Structure

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.

STRUCT identifier = 'SG'


.EXT

.SG

.SGX

; structure-layout ;
[ index ]
+ offset
-

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 Variables Equivalenced Referral Structure

+
-
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.

STRUCT identifier ( referral )


.SG

.SGX

.EXT

= 'SG' ;
[ index ]
+ offset
-

VST703.vsd

HP pTAL Reference Manual—523746-006


11 -25
Equivalenced Variables Equivalenced Referral Structure

.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 Variables Equivalenced Simple Pointer

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 Variables Equivalenced Structure Pointer

+
-
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
INT .SG

.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 Variables Equivalenced Structure Pointer

.
.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 Variables Equivalenced Structure Pointer

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 ASSERT Conditionally calls a procedure
control 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 Assignment Stores a value in a variable
transfer 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 DROP Removes either a label (from the symbol table) or
allocation 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
Statements Using Semicolons in 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
Statements ASSERT

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 assertion-
level and an error-handling procedure.
2. Put an ASSERT statement at each place where you want to execute the error-
handling 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
Statements Assignment

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 assert-
level, 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
Statements Assignment

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 i := 3;
STRING s;
UNSIGNED(12) u1;
UNSIGNED(24) u2;
s := i + 1; ! OK: Assignment of INT to STRING
i := s + %H20; ! OK: Assignment of STRING to INT
u1 := i + s; ! OK: INT + STRING
u2 := i; ! ERROR: INT and UNSIGNED(17-31) are not
! assignment-compatible

HP pTAL Reference Manual—523746-006


12- 5
Statements Pointer Assignment

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 := i1; ! Copy i1 to i2
s := i1; ! Assign 16-bit INT to 8-bit STRING
i1 := s; ! Assign 8-bit STRING to 16-bit INT
IF i1 = i2 THEN; ! 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; ! OK: No bits are lost in assignment
u := i; ! WARNING: Most significant bit of i could
! be lost
u := j; ! 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
Statements Assigning Numbers to FIXED Variables

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
Statements Examples

Examples

Example 12-4. Assignment Statements


INT array[0:2]; ! Array
INT .ptr; ! Simple pointer
REAL real_var; ! 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 int1;
INT int2;
INT int3;
INT var := 16;
int1 := int2 := int3 := var; ! Assignment that contains
! assignment expressions
int1 := var; ! Separate assignments
int2 := var;
int3 := var;

HP pTAL Reference Manual—523746-006


12- 8
Statements Bit-Deposit Assignment

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
Statements CALL

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 = %b1111111111111111
old.<10:11> := 0; ! old = %b1111111111001111
3. The bit deposit assignment sets bit <8>, the leftmost bit of strng, to 0:
STRING strng := -1; ! strng = %b11111111
strng.<8> := 0; ! 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 = %b1010101010101010
var.<7:12> := %577; ! %77 = %b0000000101111111
! var = %b1010101111111010
5. The bit deposit assignment replaces bits <7:8> of new with bits <8:9> of old:
INT new := -1; ! new = %b1111111111111111
INT old := 0; ! old = %b0000000000000000
new.<7:8> := old.<8:9>; ! 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
Statements CALL

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
Statements CASE

Example 12-7. CALL Statement


PROC p (a, b, c);
INT(32) a;
REAL b;
REAL(64) c;
BEGIN
END;
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 ! In this unlabeled CASE statement,
; ! the semicolon creates an alternative
END;

HP pTAL Reference Manual—523746-006


12 -12
Statements Labeled CASE

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.

CASE selector OF BEGIN case-alternative


;

END
OTHERWISE -> ;
statement-2

VST041.vsd

selector
is an INT or INT (32) value arithmetic expression that uniquely selects the case-
alternative 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 case-
alternative 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
Statements Labeled CASE

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 ! Execute CASE
BEGIN
apple -> CALL p1;
orange -> CALL p2;
prune -> CALL p3;
OTHERWISE -> CALL p4; ! Execute this alternative
END;

HP pTAL Reference Manual—523746-006


12 -14
Statements Unlabeled CASE

Example 12-10. Labeled CASE Statement


INT location;
LITERAL bay_area, los_angeles, hawaii, elsewhere;
PROC area_proc (area_code);
INT area_code; ! Declare selector as
BEGIN ! formal parameter
CASE area_code OF ! Selector is area_code
BEGIN
408, 415 ->
location := bay_area;
213, 818 ->
location := los_angeles;
808 ->
location := hawaii;
OTHERWISE ->
location := elsewhere;
END; ! End CASE statement
END; ! 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
Statements Unlabeled CASE

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
Statements DO-UNTIL

Example 12-12. Unlabeled CASE Statement


INT selector;
INT var0;
INT var1;
CASE selector OF
BEGIN
var0 := 0; ! Executes if selector=0
var1 := 1; ! Executes if selector=1
OTHERWISE
CALL error_handler; ! Executes if selector is not 0 or 1
END;

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
Statements DO-UNTIL

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 ! Compound statement to execute in
array_a[index] := 0; ! DO loop
index := index + 1;
END
UNTIL index > limit; ! 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 DO-
UNTIL statement.

HP pTAL Reference Manual—523746-006


12 -18
Statements DROP

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
Statements Dropping Temporary Variables

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 := initial-value TO 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
Statements Nested

limit
is an arithmetic expression that terminates the loop. If index is INT, initial-
value 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
Statements Optimized

• 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; ! p1 has standard FOR statement
BEGIN
INT i;
x := 0;
FOR i := 1 to f() DO ... ; ! f is called 10 times
! i=11 here
RETURN x; ! p1 returns 10
END;
INT PROC q;
BEGIN
x := y + 1;
RETURN 10;
END;

HP pTAL Reference Manual—523746-006


12 -22
Statements GOTO

Example 12-20. Standard and Optimized FOR Statements (page 2 of 2)


INT PROC p2; ! p2 has optimized FOR statement
BEGIN
USE i;
y := 0;
FOR i := 1 to q() DO ... ; ! q is called 1 time
! i=10 here
RETURN x; ! p2 returns 1
END;

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; ! Declare local label
INT a;
INT b := 5;
calc_a : ! Place label at local statement
a := b * 2;
! Lots of code
GOTO calc_a; ! Local branch to local label
END;

HP pTAL Reference Manual—523746-006


12 -23
Statements Nonlocal

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; ! Nonlocal goto
if x > 10 goto L2; ! Local goto
return 1;
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
Statements GOTO and Target Statements With Different
Trapping States

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 block-
level 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; ! ERROR: Cannot branch from a BEGIN-END
END; ! block that does not specify a trapping
END; ! attribute to a BEGIN-END block that
! does

HP pTAL Reference Manual—523746-006


12 -25
Statements IF

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
Statements Testing Address Types

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
Statements Move

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 FOR count


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
Statements Move

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 STRING Bytes
(including structure item) INT Words
INT(32) or REAL Doublewords
FIXED or REAL(64) Quadruplewords
Structure Not applicable Words
Substructure Not applicable Bytes
Structure pointer STRING Bytes
INT 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 Bytes
Array INT Words
INT(32) or REAL Doublewords
Simple pointer FIXED or REAL(64) Quadruplewords
(including structure
item)
Structure Not applicable Structure occurrences
Substructure Not applicable Substructure
occurrences
Structure Pointer STRING Structure occurrences
(STRING and INT INT
have meaning only
in group
comparison
expressions and
move statements.)

HP pTAL Reference Manual—523746-006


12 -29
Statements Move

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
Statements Move

Example 12-26. MOVE Statement Copying to an Array


LITERAL len = 10; ! Length of array
LITERAL num = 5; ! Number of elements
STRING .array[0:len - 1]; ! Destination array
STRING .next_addr; ! 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]; ! Copy one byte
x[0] ':=' 0; ! 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]; ! Source structure
BEGIN
INT a, b, c;
END;
STRUCT .d (s) [0:copies - 1]; ! Destination structure
PROC p;
BEGIN
d ':=' s FOR copies ELEMENTS; ! Word move of three
END; ! structure occurrences

HP pTAL Reference Manual—523746-006


12 -31
Statements Destination Shorter Than Source

Example 12-29. MOVE Statement Copying a Substructure


LITERAL copies = 3; ! Number of occurrences
STRUCT .s;
BEGIN
STRUCT s_sub[0:copies - 1]; ! Source substructure
BEGIN
INT a, b;
END;
END;
STRUCT .d (s); ! Destination substructure
! is within structure d
PROC p;
BEGIN
d.s_sub ':=' s.s_sub FOR copies ELEMENTS; !Byte move of three
END; ! 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
Statements $FILL8, $FILL16, and $FILL32 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 ':=' f FOR 8 BYTES; ! OK: g is global
n ':=' m FOR 8 BYTES; ! OK: n is an array
n[3] ':=' m FOR 8 BYTES; ! OK: n is an array element
r ':=' m FOR 8 BYTES; ! OK: r is a reference param
i ':=' m FOR 8 BYTES; ! Warning
END;

$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 • 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 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
Statements RETURN

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
Statements Functions

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); ! Function with return type INT
INT nuff;
INT more;
BEGIN
IF nuff < more THEN ! IF statement
RETURN nuff * more ! Return a value
ELSE
RETURN 0; ! Return a different value
END;

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; ! Return a value and a condition code
END;

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
Statements Procedures and Subprocedures

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; ! Return to caller
! Lots more code
END;

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
Statements Condition Codes

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
Statements Condition Codes

Example 12-38. Procedure With RETURNSCC (page 2 of 2)


PROC q;
BEGIN
CALL p;
IF < THEN ... ! OK: p returns a condition code
END;

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 ! Returns a condition code
ELSE IF i = 1 THEN 0 ! based on the value returned
ELSE 1
END;

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 < max_val THEN -1
ELSE
IF i = max_val THEN 0
ELSE 1;
RETURN i, cc_result; ! Return a function value and a
END; ! 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
Statements Condition Codes

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; ! Return i and set the condition code
END; ! based on the numeric value of i

HP pTAL Reference Manual—523746-006


12 -39
Statements SCAN and RSCAN

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); ! Return the value of i and set the
END; ! 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); ! ERROR: Cannot specify an explicit
END; ! 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.

SCAN variable WHILE test-char

RSCAN UNTIL

-> next-addr

VST053.vsd

SCAN
indicates a left-to-right search.

HP pTAL Reference Manual—523746-006


12 -40
Statements SCAN and RSCAN

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
Statements Determining What Stopped a Scan

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 test character not found
IF NOT $CARRY THEN ... ; ! 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; ! OK
SCAN s until " " -> u; ! OK

HP pTAL Reference Manual—523746-006


12 -42
Statements Crossing Variable Boundaries

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 ! Target character was not found
BEGIN
...
END;

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
Statements P-Relative Arrays

Example 12-49. Scanning Data in a P-Relative Array


STRING s = 'P' := ! STRING P-relative array s
[ 1, "msg1.",
2, "msg2.",
3, "msg3.",
0 ];
STRING .t_start, ! Start address of msg
.t_end; ! End address of msg
INT c := 3, ! Value to scan for in s
z := "."; ! 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' := [ ! STRING P-relative array s
1, "msg1.",
2, "msg2.",
3, "msg3.",
0 ];
CBADDR t_start, ! Start address of msg
t_end; ! End address of msg
INT c := 3, ! Value to scan for in s
z := -1; ! 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
Statements USE

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
Statements WHILE

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 Meaning
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
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 Procedure or Overrides the
Attribute subprocedure [NO]OVERFLOW_TRAPS
directive
[EN|DIS]ABLE_OVERFLOW_TRAPS Block Overrides both the
Block Attribute [NO]OVERFLOW_TRAPS
directive and the
[NO]OVERFLOW_TRAPS
procedure attribute

HP pTAL Reference Manual—523746-006


13- 1
Hardware Indicators [NO]OVERFLOW_TRAPS Procedure Attribute

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; ! Disable traps for x
BEGIN
...
END;
PROC y; ! Traps for y are still enabled
BEGIN
...
END;
PROC z NOOVERFLOW_TRAPS; ! Disable traps for z
BEGIN
SUBPROC s OVERFLOW_TRAPS; ! Enable traps for s
BEGIN
...
END;
...
s;
... ! Traps for z are still disabled
END; ! 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 Hardware Indicators After Assignments

Example 13-2. ENABLE_OVERFLOW_TRAPS and


DISABLE_OVERFLOW_TRAPS Block Attributes
PROC p;
BEGIN: ENABLE_OVERFLOW_TRAPS ! Enable traps for block
...
END;
PROC q;
BEGIN
SUBPROC q1;
BEGIN: DISABLE_OVERFLOW_TRAPS ! Disable traps for block
...
END;
...
END;
PROC r;
BEGIN: ENABLE_OVERFLOW_TRAPS
CALL p; ! Call p with traps enabled
END;
PROC s;
BEGIN: DISABLE_OVERFLOW_TRAPS
CALL p; ! Call p with traps disabled
END;

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
Hardware Indicators $CARRY

° $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; ! $CARRY can be tested after this statement
i := j - k; ! $CARRY can be tested after this statement
• Unsigned integer addition or subtraction
INT i, j, k;
i := j '+' k; ! $CARRY can be tested after this statement
i := j '-' k; ! $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
Hardware Indicators Condition Codes

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); ! Condition code is not accessible
° An expression whose value is an address type (for example, WADDR or
EXTADDR):
INT i;
INT .p;
@p := @i; ! 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; ! Right side is a floating-point number;
! condition is code not accessible
° A constant or constant expression:
INT a;
a := 2 << 3; ! 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
Hardware Indicators Condition Codes

• 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"; ! P is an INT function but the
END; ! expression in the RETURN statement
! yields a single byte
PROC p1;
BEGIN
INT i;
i := p; ! Condition code is accessible because
END; ! 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; ! Declare a local simple variable
i := i + 1; ! Condition code accessible
END;
° The address cell of a local pointer:
INT i;
INT .ptr; ! Declare a local pointer
@ptr := f(i); ! 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
Hardware Indicators Condition Codes

° A global variable:
INT g;
PROC p;
BEGIN
INT i := 0;
g := i; ! Condition code is not accessible
END;
° A pointer:
INT .p;
INT i := 0;
p := i; ! 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 Hardware Indicators in Conditional Expressions

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; ! OK: Left and right sides are simple
i := i + 1; ! 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; ! ERROR: Left side is reference parameter
a[i] := a[i+1]; ! ERROR: Left side has index
s.s1[0] := i; ! ERROR: Left side has field and index
s.s2 := i; ! ERROR: Left side has field reference
i.<0:8> := i; ! ERROR: Left side has bit selection
i := str; ! ERROR: Right side is 1-byte item
i := $ABS(i); ! ERROR: Right side is call to
! built-in routine
@k := @k + 1D; ! ERROR: Right side is address type
r := r + 1.0E0; ! ERROR: Right side is floating-point type
END;

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 Hardware Indicators in Conditional Expressions

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 () ! Sets condition code indicator
until = ; ! OK
do
begin
...
call p ();
end
until = ; ! OK
do
begin
...
call q ();
end
until > ; ! ERROR: last statement in do-until statement
! does not set condition indicator
int i := 0;
...
do
begin
...
i := i + 1;
end
until $overflow; ! 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 Hardware Indicators in Conditional Expressions

Example 13-5. Hardware Indicators in WHILE Statements (page 2 of 2)


call p (); ! Sets condition code indicator
while >= do ! OK
call p (); ! Sets condition code indicator
call p (); ! Sets condition code indicator
while > do ! OK
begin
...
call p (); ! Sets condition code indicator
end;
call q (); ! Doesn't set the condition code indicator
while > do ! ERROR: statement preceding WHILE
begin ! and last statement of WHILE
... ! must both set condition code indicator
call p (); ! Sets condition code indicator
end;
call p (); ! Sets the condition code indicator
while >= do ! ERROR: statement preceding WHILE
begin ! and last statement of WHILE
... ! must both set condition code indicator
call q (); ! Doesn't set condition code indicator
end;
int i;
...
i := i + 1;
while not $overflow do ! ERROR: not a condition code indicator
begin
...
i := i + 1;
end;

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; !ERROR: invalid in IF expression
• Assign the value of a hardware indicator to a variable in an assignment statement
INT i;
i := >; ! 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 Hardware Indicators in Conditional Expressions

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... ! OK: hardware indicator tested
! immediately
a := a - 1;
BEGIN
IF < THEN ... ! ERROR: intervening BEGIN is invalid
...
a := a + 1;
END;
IF $CARRY THEN ... ! ERROR: intervening END is invalid
CALL WRITEREAD(...);
firstchar := str_buff;
IF <= THEN... ! ERROR: intervening assignment
! statement is invalid
CALL WRITEREAD(...);
IF < THEN ... ! 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
Hardware Indicators Nesting Condition Code Tests

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 ! OK: >= is a relational operator
IF > THEN ...
• An expression that consists only of a condition code
i := i + 1;
IF >= THEN ! OK: >= is a condition code
IF > THEN...
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 ... ! ERROR: cannot test $OVERFLOW in
! nest of IF statements
i := i + 1;
IF $CARRY THEN ! ERROR: cannot test $CARRY in
IF > THEN ... ! nest of IF statements

HP pTAL Reference Manual—523746-006


13 -12
Hardware Indicators Nesting Condition Code Tests

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 ... ! ERROR: invalid to test $CARRY here
END
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 ! OK to test $CARRY here
BEGIN
IF temp < 100 THEN ...
END
ELSE ... ! 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 ! Root operator (<=) is
BEGIN ! relational operator
IF < THEN ! OK: test if condition was
... ! "less than"
ELSE
END;
IF (i < -1) OR (i > 1) THEN
BEGIN
IF < THEN ! ERROR: root operator of IF
... ! statement is Boolean,
END; ! not relational

HP pTAL Reference Manual—523746-006


13 -13
Hardware Indicators Using Hardware Indicators Across Procedures

• 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 ... ! OK: e1 and e2 are EXTADDR values
END;
IF w1 '<>' w2 THEN
BEGIN
IF < THEN ... ! OK: Original test is unsigned
END;
IF w1 <> w2 THEN
BEGIN
IF < THEN ... ! ERROR: cannot test condition code
END; ! 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
Hardware Indicators Returning a Condition Code to the Calling Procedure

Example 13-6. Testing a Hardware Indicator Set in a Calling Procedure


PROC b(status); ! Called procedure
INT status;
BEGIN
IF status <> 0 THEN ... ! Test parameter value from PROC a
END;
PROC a; ! Calling procedure
BEGIN
INT i, j, k;
...
j := i;
IF <> THEN k := 1 ! Test hardware indicator and set k
ELSE k := 0;k
CALL b(k); ! Call PROC b, passing k
END;

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
Hardware Indicators Returning the Value of $OVERFLOW or $CARRY to
the Calling Procedure

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; ! Calling procedure
BEGIN
INT rtn_ovfl;
CALL q(rtn_ovfl); ! q returns rtn_ovfl
IF rtn_ovfl = 0 THEN ... ! Test value of rtn_ovfl
END;
PROC q(ovfl); ! Called procedure
INT .ovfl;
BEGIN
INT i := 32767;
i := i + 1;
IF $OVERFLOW THEN ! Test hardware indicator and
ovfl := 1 ! set ovfl
ELSE
ovfl := 0;
END; ! 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 Procedure Declarations
Pointers

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

parameter-list proc-attribute
,

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 Procedure Declarations
Pointers

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 Procedure Declarations
Pointers

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; ! var is a global INT
WADDR PROC p(i), RETURNSCC,; ! Attributes: empty, RETURNSCC,
! and empty
INT .i;
BEGIN
RETURN @var, i+1; ! Return address and
END; ! 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 Procedure Attributes
Pointers

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; ! This MAIN procedure is MAIN
BEGIN ! in the object file
CALL this_proc;
CALL that_proc;
END;
PROC main_proc2 MAIN; ! This MAIN procedure is not MAIN
BEGIN ! in the object file
CALL some_proc;
END;

HP pTAL Reference Manual—523746-006


14- 5
Procedures, Subprocedures, and Procedure Procedure Attributes
Pointers

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 Procedure Attributes
Pointers

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 Parameters and VARIABLE and EXTENSIBLE
Pointers 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) ! EXTERNAL declaration for
LANGUAGE COBOL; ! HP COBOL procedure
STRING .a, .b, .c;
EXTERNAL;
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-name-


spec 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 VARIABLE, EXTENSIBLE and RETURNSCC
Pointers 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 Formal Parameter Specification
Pointers

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 )

VST636.vsd

HP pTAL Reference Manual—523746-006


14 -10
Procedures, Subprocedures, and Procedure Formal Parameter Specification
Pointers

param-type
is the parameter type of the formal parameter and can be one of the following:

STRING
INT

REAL ( width )
UNSIGNED ( 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 Formal Parameter Specification
Pointers

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 )
FIXED

( fpoint )

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 Formal Parameter Specification
Pointers

.
.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 Formal Parameter Specification
Pointers

Table 14-1. Formal Parameter Specification


Formal Parameter Characteristics
Expected Actual Declare Formal Indirection
Parameter Parameter As: Parameter Type Symbol Referral
Simple variable A value or reference STRING* Value, no; No
parameter INT reference,
INT(32) yes
REAL
REAL(64)
FIXED(n)
FIXED(*)
Simple variable A value parameter UNSIGNED No No
Array or A reference STRING Yes No
simple pointer parameter INT
INT(32)
REAL
REAL(64)
FIXED(n)
Definition structure, A reference INT or STRING Yes Yes
referral structure, or parameter
structure pointer
Referral structure or A reference STRUCT Yes Yes
structure pointer parameter
Constant A value parameter INT No No
expression** INT(32)
(including UNSIGNED
@identifier ) REAL
REAL(64)
FIXED(n)
Procedure A value parameter PROC No No
PROC(32)
* 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 Formal Parameter Specification
Pointers

Example 14-3. Function With Value and Reference Formal Parameters


PROC mult (var1, var2);
INT var1, ! Value parameter
.var2; ! Reference parameter
BEGIN
var2 := var2 + var1; ! Manipulate parameters
END;

Example 14-4. Reference Structure as a Formal Reference Parameter


STRUCT template (*); ! Template structure
BEGIN
INT a;
INT b;
END;
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 Using STRUCT as a Formal Parameter
Pointers

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 (*); ! Template
BEGIN
INT a;
INT b;
END;
PROC p (i, j);
INT i;
STRUCT .j (s); ! Declare j by referring to template s
BEGIN
...
END;

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 Procedure Body
Pointers

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 Procedure Body
Pointers

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 ! Procedure body
INT a, ! Local declarations
b;
...
END;
PROC second;
BEGIN ! Procedure body
...
CALL first; ! Call first procedure
...
END;

Example 14-7. FORWARD Declaration for a Procedure


INT g2;
PROC procb (param1); ! FORWARD declaration for procb
INT param1;
FORWARD;
PROC proca;
BEGIN
INT i1 := 2;
CALL procb (i1); ! Call procb
END;
PROC procb (param1); ! Body for procb
INT param1;
BEGIN
g2 := g2 + param1;
END;

HP pTAL Reference Manual—523746-006


14 -18
Procedures, Subprocedures, and Procedure Subprocedure Declarations
Pointers

Subprocedure Declarations
You can declare subprocedures within procedures, but not within subprocedures.

SUBPROC identifier
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 Subprocedure Declarations
Pointers

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 Subprocedure Body
Pointers

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 INT var;
(always direct)
Direct array INT array[0:5];
Read-only array INT ro_array = 'P' := [0,1,2,3,4,5];
Simple variable INT var;
(always direct)
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 Entry-Point Declarations
Pointers

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 Procedure Entry-Point Identifiers
Pointers

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; ! Declare entry-point identifiers
ENTRY add_1;
INT m2 := 1;
g2 := g2 + m2;
add_2: ! Location of entry-point identifier add_2
g2 := g2 + m2;
add_1: ! Location of entry-point identifier add_1
g2 := g2 + m2;
END;
PROC mymain MAIN; ! Main procedure
BEGIN
CALL add_1 (to_this); ! Call entry point add_1
END;

HP pTAL Reference Manual—523746-006


14 -23
Procedures, Subprocedures, and Procedure Subprocedure Entry-Point Identifiers
Pointers

Example 14-10. FORWARD Declarations for Entry Points


INT to_this := 314;
PROC add_1 (g2); ! FORWARD entry-point identifier
INT .g2; ! declaration
FORWARD;
PROC add_2 (g2); ! FORWARD entry-point identifier
INT .g2; ! declaration
FORWARD;
PROC add_3 (g2); ! FORWARD procedure declaration
INT .g2;
FORWARD;
PROC mymain MAIN; ! Main procedure declaration
BEGIN
CALL add_1 (to_this); ! Call entry-point identifier
END;
PROC add_3 (g2); ! Body for FORWARD procedure
INT .g2;
BEGIN
ENTRY add_2; ! Declare entry-point identifiers
ENTRY add_1;
INT m2 := 1;
g2 := g2 + m2;
add_2: ! Location of entry-point identifier
g2 := g2 + m2; ! add_2
add_1: ! Location of entry-point identifier
g2 := g2 + m2; ! add_1
END;

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 Subprocedure Entry-Point Identifiers
Pointers

• 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 ! call do_write_op (buf);
! read_op ! call do_read_op (buf);
! writeread_op ! call writeread_op (buf);
! readwrite_op ! call readwrite_op (buf);
end;
end;

HP pTAL Reference Manual—523746-006


14 -25
Procedures, Subprocedures, and Procedure Procedure Pointers
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 procptr-name
return-type

formal-param-names attributes ;

formal-param-spec 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 Procedure Pointers
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 Procedure Pointers
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 Declaring PROCPTR Variables
Pointers

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, prev-
identifier must be 16 bits. On TNS/R and TNS/E architecture, prev-
identifier 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 Declaring PROCPTR in Structures
Pointers

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; ! Declare PROC p in a
INT i, .EXT j; ! FORWARD declaration
FORWARD;
PROCPTR a (i, j) EXTENSIBLE,CALLABLE; ! Declare PROCPTR a and
INT i, .EXT j; ! initialize it to point
END PROCPTR := @p; ! to PROC p
FIXED PROCPTR b (str : length); ! Declare FIXED PROCPTR b
STRING .str; ! with one
INT length; ! parameter pair
END PROCPTR;
PROCPTR c (p); ! Declare PROCPTR c
REAL PROCPTR p(x); ! with one parameter, p,
REAL x; ! a PROCPTR
END PROCPTR;
REAL PROCPTR d (x); ! Declare REAL PROCPTR d
REAL x; ! with one
END PROCPTR; ! REAL parameter
PROCPTR e(i); ! Declare PROCPTR e
INT i; ! Equivalence e to d
END PROCPTR = 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 Declaring PROCPTR in Structures
Pointers

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 Declaring PROCPTRs as Formal Parameters
Pointers

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); ! OK
CALL b(@a); ! ERROR: @ character is not valid
CALL c(a); ! ERROR: @ character is required
CALL c(@a); ! OK: @ character is required
END;

HP pTAL Reference Manual—523746-006


14 -32
Procedures, Subprocedures, and Procedure Assignments to PROCPTRs
Pointers

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; ! OK: PROCADDR variable is assigned PROC addr
@pp1 := @p; ! OK: Left side is PROCPTR, right side is PROC
@pp1 := @pp2; ! ERROR: pp1 has two parameters, pp2 has one
@pp1 := @pp3; ! ERROR: pp1 specifies RETURNSCC, pp3 does not
paddr := @pp2; ! OK: paddr is a PROCADDR variable
@pp1 := paddr; ! OK: paddr is a PROCADDR variable

HP pTAL Reference Manual—523746-006


14 -33
Procedures, Subprocedures, and Procedure Assignments to PROCPTRs
Pointers

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; ! Declare PROC p in a
INT i, .EXT j; ! FORWARD declaration
FORWARD;
PROCPTR a (i, j) EXTENSIBLE,CALLABLE; ! Declare PROCPTR a and
INT i, .EXT j; ! initialize it to
END PROCPTR; ! point to PROC p
PROCPTR c (p);
REAL PROCPTR p (x);
REAL x;
END PROCPTR;
END PROCPTR;
REAL PROCPTR d (x); ! Declare REAL PROCPTR d
REAL x; ! with REAL parametera
END PROCPTR;
@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 Dynamically Selected Procedure Calls
Pointers

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 Dynamically Selected Procedure Calls
Pointers

Example 14-20. Dynamically Selected Procedure Call


LITERAL dev_6530, dev_3270, dev_dove;
STRUCT s1 [dev_6530:dev_dove]; ! Array of PROCPTRs
BEGIN
PROCPTR d(device, param);
INT device, param;
END PROCPTR;
END;
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 Labels in Procedures
Pointers

Labels in Procedures
A label is the target location of a GOTO statement.

LABEL identifier ;
,

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 Labels in Procedures
Pointers

HP pTAL Reference Manual—523746-006


14 -38
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); ! OK: data type of b is BADDR
$BUILT_IN_1(@s); ! OK: address type of @s is BADDR
$BUILT_IN_1(s); ! 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 ( var , mask ,

value ) ;

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 assignment-
compatible 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, INT(32) value
or REAL(64), or
UNSIGNED(1-31) value
EXTADDR or PROCADDR
address
$DBLL Two INT values INT(32) value
$DBLR INT, INT(32), FIXED, REAL, Rounded INT(32) value
or REAL(64) value
$DFIX INT(32) value FIXED(fpoint ) value
$EFLT INT, INT(32), REAL(64) value
FIXED(fpoint ), REAL, or
REAL(64) value
$EFLTR INT, INT(32), Rounded REAL(64) value
FIXED(fpoint ), or REAL,
or REAL(64) value
$FIX INT, INT(32), REAL, signed FIXED value
REAL(64), or FIXED value
$FIXD FIXED value INT(32) value
$FIXEDTOASCII Absolute value of a FIXED ASCII value
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, Rounded FIXED value
REAL(64), or 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), REAL value
FIXED(fpoint ), REAL, or
REAL(64) value
$FLTR INT, INT(32), Rounded REAL value
FIXED(fpoint ), REAL, or
REAL(64) value
$HIGH Upper 16 bits of an INT(32) INT value
or EXTADDR value
$IFIX Signed INT value FIXED(fpoint ) value
$INT INT, INT(32), FIXED, INT value
UNSIGNED (1-31), REAL, or
REAL(64) value
Some address types
$INT_OV Same as $INT, but sets $OVERFLOW in some cases
$INTR Low-order 16 bits of an INT, Rounded INT value
INT(32), or FIXED 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 EXTADDR address
address
$SGBADDR_TO_SGWADDR SGBADDR or SGXBADDR SGWADDR address
address
$SGWADDR_TO_EXTADDR SGWADDR or SGXWADDR EXTADDR address
address
$SGWADDR_TO_SGBADDR SGWADDR or SGXWADDR SGBADDR address
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 $MIN $MAX
REAL(64)

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 Returns the current setting of the system clock
$READSPT*,** Returns (copies) an entry from the Segment Page Table
(SPT)
$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
* 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 $OVERFLOW
argument
$ALPHA Tests for an alphabetic character
$ASCIITOFIXED Converts an ASCII value to a FIXED Condition code
value $OVERFLOW
$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 Condition code
EXTADDR address
$BADDR_TO_WADDR Converts a BADDR address to a Condition code
WADDR address
$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
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 Can Set ...
$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) $OVERFLOW
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 $OVERFLOW
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 Condition code
$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 32-
bit value, respectively
$FIX Converts its argument to a FIXED
value
$FIXD Converts a FIXED value to an INT(32) $OVERFLOW
value
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 $OVERFLOW
FIXED value to an ASCII value
$FIXEDTOASCIIRESIDUE Converts the absolute value of a $OVERFLOW
FIXED value to an ASCII value and
returns the value of the residue
$FIXI Converts a FIXED value to a signed $OVERFLOW
INT value
$FIXL Converts a FIXED value to an $OVERFLOW
unsigned INT value
$FIXR Converts its argument to a rounded $OVERFLOW
FIXED value
$FLT Converts its argument to a REAL
value
$FLTR Converts its argument to a rounded $OVERFLOW
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 $OVERFLOW
indicator in some cases
$INTERROGATEHIO2,3 Stores cause and status information Condition code
from a high-priority I/O interrupt
$INTERROGATEIO1,2,3 Stores cause and status information Condition code
from an I/O interrupt
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 $OVERFLOW
INT, INT(32), or FIXED value to an
INT value
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 $CARRY
Page Table (SPT)
$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 Condition code
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
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 Can Set ...
$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 $CARRY
Segment Page Table (SPT)
$READTIME Returns the number of microseconds
since the last cold load
$SCALE Moves the position of the implied $OVERFLOW
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
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 $OVERFLOW
divisor to produce an INT quotient and
INT remainder
$UDIVREM32 Divides an INT(32) dividend by an INT $OVERFLOW
divisor to produce an INT(32) quotient
and INT remainder
$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 $CARRY
$XADR Converts a standard address to an
EXTADDR address
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 ( bufferaddr , maxdigits ,

remainingdigits qvaluein , qvalueout ) ;

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 binary-
coded 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 buffer_len = 100;
STRING .buffer[ 0:buffer_len - 1 ]; ! Buffer to convert
STRING .ptr := @buffer; ! pointer to buffer
INT maxdigits;
INT remainingdigits;
FIXED qvaluein;
FIXED qvalueout;
$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]; ! Declare four occurrences of a
BEGIN ! structure
UNSIGNED(1) flags[0:15];
UNSIGNED(2) status;
BIT_FILLER 14;
END;
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 ( checksum , bufferaddr ,

wordcount ) ;

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 , maxwords ,

duplicationcount ) ;

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 buffersize = 100;
INT .EXT buffer[ 0:buffersize-1 ];
INT maxwords;
INT 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 := $DBL(e); ! OK: e is type EXTADDR
j := $DBL(@i); ! OK: @i is type EXTADDR
j := $DBL(i); ! OK: i is type INT
j := $DBL(@j); ! ERROR: @j is type WADDR
j := $DBL(@e); ! 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); ! Return 2d
dblnum := $DBLR (realnum); ! 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 ( channel , lprmcommand ,

lacsubcommand , rdstdevstatus ,

channel-status ) ;

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 channel;
INT lprm_command;
INT lac_subcommand;
INT rdst_dev_status;
INT 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); ! ERROR: x is STRING,
END; ! 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); ! ERROR: x is INT, not EXTADDR
END;

$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 ( qvalue , bufferaddr ,

maxdigits ) ;

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 buffer_len = 100;
FIXED val;
STRING .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 ( qvalue , bufferaddr

, maxdigits , qresidue ) ;

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 buffer_len = 100;
FIXED val;
STRING .buffer[ 0:buffer_len - 1 ];
FIXED 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); ! Return -1F
rndfnum := $FIXR (realnum); ! 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.

$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

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) b;
INT .EXT c;
EXTADDR d;
a := $HIGH(b); ! OK: b is INT(32)
a := $HIGH(@c); ! OK: @c is EXTADDR
a := $HIGH(@b); ! ERROR: @b is WADDR
a := $HIGH(c); ! ERROR: c is INT
a := $HIGH(d); ! 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 := $INT(a); ! OK: a is INT
i := $INT(@a); ! OK: @a is SGWADDR
i := $INT(b); ! OK: b is SGXBADDR
i := $INT(i); ! OK: i is INT
i := $INT(@b); ! ERROR: @b is WADDR
i := $INT(@i); ! ERROR: @i is WADDR
i := $INT(@e); ! OK: @e is EXTADDR
END;

$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 := 32767;
INT(32) k := 32768;
i := $INT(j); ! INT never sets overflow
IF $OVERFLOW THEN ... ! $OVERFLOW is false
i := $INT(k); ! INT never sets overflow
IF $OVERFLOW THEN ... ! $OVERFLOW is false
i := $INT_OV(j);
IF $OVERFLOW THEN ... ! $OVERFLOW is false
i := $INT_OV(k);
IF $OVERFLOW THEN ... ! $OVERFLOW is true

$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 ( select , rank-channel

, ric-int-cause , rist-int-cause , 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 select;
INT rank_channel;
INT ric_interrupt_status;
INT rist_interrupt_cause;
INT 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 ( select , rank-channel

, ric-int-cause , 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 select;
INT rank_channel;
INT ric_interrupt_status;
INT rist_interrupt_cause;
INT 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 ( headersize , virtaddr ,

sptbase ) ;

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 ( only-if-locked , lock-count ,

virtaddr ) ;

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 ( checksum ,

destaddr , srcaddr , 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 checksum;
INT .EXT source;
INT .EXT dest;
INT(32) 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 ( destaddr , srcaddr ,

maxwords , lastword ) ;

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]; 10
$OCCURS (a);
Value parameter or simple variable INT a; 1
$OCCURS (a);
Reference parameter or pointer INT .a; 1
$OCCURS (a);
Array element using constant index INT a[0:9]; 1
$OCCURS (a[3]);
Array element using expression in index INT a[0:9]; 1
$OCCURS (a[j]);

HP pTAL Reference Manual—523746-006


15 -69
Built-In Routines $OCCURS

Table 15-15. $OCCURS for Structure Arrays and Arrays Within Structures
$OCCURS
$OCCURS Argument Example Returns
Unindexed structure array or STRUCT s [0:9];
substructure array BEGIN
or STRUCT
BEGIN
an element of a structure array or INT
substructure array, END;
or END;
an array that is a field within a $OCCURS (s); 10
structure or substructure $OCCURS (a[7]); 1
$OCCURS (a[7].t); 8
$OCCURS (a[7].t[3]); 1
$OCCURS (a[7].t[3].i); 5
$OCCURS (a[7].t[3].i[v]); 1
Entire structure STRUCT s;
or BEGIN
INT f;
nonarray field of a structure or END;
substructure 1
$OCCURS (s); 1
$OCCURS (s.f);
Structure template STRUCT s;
BEGIN
INT f[0:9];
END;
Compile-time err
$OCCURS (s); 10
$OCCURS (s.f); 1
$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 := $OCCURS(a); ! OK: a is an entire array
i := $OCCURS(i); ! OK: $OCCURS returns 1
i := $OCCURS(x); ! OK: $OCCURS returns 1
i := $OCCURS(a[3]); ! WARNING: $OCCURS returns 1
i := $OCCURS(a[i]); ! WARNING: $OCCURS returns 1
i := $OCCURS(r); ! WARNING: $OCCURS returns 1
i := $OCCURS(y); ! WARNING: $OCCURS returns 1
END;

HP pTAL Reference Manual—523746-006


15 -70
Built-In Routines $OFFSET

Example 15-63. $OCCURS Routine With Structure Arrays


INT i;
STRUCT s[0:9];
BEGIN-
STRUCT t[0:7];
BEGIN
INT i[0:4];
INT f;
END;
END;
i := $OCCURS(s); ! OK: s is an entire array
i := $OCCURS(s[7].t); ! OK: t is an entire array
i := $OCCURS(s[7].t[3].i); ! OK: i is an entire array
i := $OCCURS(s[7].t[3].f); ! OK: $OCCURS returns 1
i := $OCCURS(s[7]); ! WARNING: $OCCURS returns 1
i := $OCCURS(s[7].t[3]); ! WARNING: $OCCURS returns 1
i := $OCCURS(s[7].t[3].i[v]); ! 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); ! ERROR: Template structure not OK
i := $OCCURS(s.f); ! OK: f is an array
i := $OCCURS(s.f[5]); ! 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); ! Declare structure pointer
END; ! that points to structure tt
INT x;
x := $OFFSET (st.j); ! x gets 2
x := $OFFSET (tt.s); ! x gets 6
x := $OFFSET (st.st_ptr.s); ! 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) ); ! These two calls are
CALL p1 (n); ! indistinguishable
END;

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) ); ! These two calls are
CALL p1 ( ); ! indistinguishable
END;

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), ! Pass s:i if i < 9
$OPTIONAL (j > 2, j) ); ! Pass j if j > 2
END;

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, If size is not an integral multiple of 32,
$STACK_ALLOCATE rounds size up to $STACK_ALLOCATE rounds size up to
the next integral multiple of 8. the next integral multiple of 32.
The returned value is aligned to an 8-byte The returned value is aligned to a 32-byte
boundary. 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 ( dividend , divisor ,

quotient , remainder ) ;

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); ! Report error

HP pTAL Reference Manual—523746-006


15 -90
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); ! Report error
IF $OVERFLOW THEN.... ! No warning or error

Example 15-90. $UDIVREM16 Routine


INT(32) dividend;
INT divisor;
INT quotient;
INT 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 ( dividend , divisor ,

quotient , remainder ) ;

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); ! Report error
IF $OVERFLOW THEN.... ! No warning or error

Example 15-91. $UDIVREM32 Routine


INT(32) dividend;
INT divisor;
INT(32) quotient;
INT 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..

$UNLOCKPAGE ( unlockcount , 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 unlockcount;
EXTADDR 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 ( ptetag , pageframe ,

abs ) :

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 ptetag;
INT(32) pageframe;
EXTADDR 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 ... pTAL Source File n

Compiler Compiler Compiler

Nonexecutable Nonexecutable Nonexecutable


...
Object File 1 Object File 2 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 On Guardian platforms, object files have the
file code 700 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
NOCALL_SHARED (error)
pTAL CALL_SHARED ld PIC
NOCALL_SHARED (default) nld Non-PIC

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 CALL_SHARED
directive (default) directive

TNS/R Nonexecutable TNS/R Nonexecutable


Object Code (non-PIC) Object Code (PIC)

nld ld

TNS/R Executable TNS/R Executable


Object Code (non-PIC) 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 TNS & TNS/E


Executable Object Code Executable Object Code
(PIC) (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. NAME declaration
2. Unblocked global data declarations
3. BLOCK declarations
4. 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; ! Declare private global data block
INT term_num; ! Declare global data
LITERAL msg_buf = 79;
END BLOCK;

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; ! Declare var
INT .ptr := @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 ! Name second section
BLOCK default_vol; ! Declare named block
INT .vol_array [0:7],
.out_array [0:34];
END BLOCK;
?SECTION msglits ! Name third section
BLOCK msg_literals; ! Declare named block
LITERAL msg_eof = 0,
msg_open = 1,
msg_read = 2;
END 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) ! Specify implicit block
?SOURCE calcsrc(default) ! 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 Using the Code Coverage Tool

HP pTAL Reference Manual—523746-006


16 -18
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 ! Test toggle for on state
PROC skipped; ! Find it off, skip procedure
BEGIN
...
END;
?ENDIF scanner ! 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; ! Find it off, compile procedure
BEGIN
...
END;
?ENDIF emitter ! End of compiled procedure

Example 17-5. SETTOG, IF, and ENDIF Directives


?SETTOG keep ! Create & turn on toggle
...
?IF keep ! Test toggle for on state
PROC kept; ! Find it on, compile procedure
BEGIN
...
END;
?ENDIF keep ! End of compiled procedure

Example 17-6. SETTOG, IFNOT, and ENDIF Directives


?SETTOG (done, nested) ! Create & turn on toggles
?IFNOT done ! Test toggle for off state
PROC skipped; ! Find it on, skip procedure
BEGIN
...
END;
?ENDIF done ! 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) ! Turn on toggles
?SETTOG versn3 ! Turn on toggle
?RESETTOG (versn2, 7) ! Turn off toggles
...
?IF versn2 ! Test toggle for on state
PROC version_2; ! Find it off,
BEGIN ! skip procedure
...
END;
?ENDIF versn2 ! 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 Effect in Same USEGLOBALS Compilation
USEGLOBALS • Retrieves global data declarations
• Suppresses compilation of text lines and SOURCE directives
(but not other directives) until BEGINCOMPILATION appears
BEGINCOMPILATION 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 BEGINCOMPILATION 1 Marks the point in the source file where
input 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
Compiler DEFEXPAND Expands DEFINEs in the compiler listing
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
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 ASSERTION Conditionally executes a debugging procedure
content 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 DEFINETOG Defines toggles without changing their settings
compilation 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
Run-time SYMBOLS Generates a symbol table for a symbolic
environmen debugger
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 assertion-level ,
=

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 BEGINCOMPILATION

Default: None
Placement: • Anywhere in the source file (not in the compilation command)
• Must be the last directive on the directive line
Scope: Applies until another ASSERTION overrides it
Dependencies: Has no effect without the ASSERT statement
References: ASSERT on page 12-3

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: None
Placement: • In the source file between the last global data declaration and the
first procedure declaration, including any EXTERNAL and
FORWARD declarations
• Can appear only once in a compilation unit
Scope: Applies to all source code that follows it in the compilation unit
Dependencies: • 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)
References: • 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; _GLOBAL A
BEGIN
INT i;
END
int .ext a [0:9] $_GLOBAL A
struct .ext a; $_GLOBAL A
begin
int i;
end;

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: • 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
References: 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: • 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
Dependencies: 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 COLUMNS

Default: COLUMNS 132


Placement: • 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
Scope: 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: None
References: • 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: • DEFEXPAND applies to subsequent code it until it is overridden by
NODEFEXPAND
• NODEFEXPAND applies to subsequent code until it is overridden by
DEFEXPAND
Dependencies: DEFEXPAND has no effect if NOLIST or SUPPRESS is active
References: • 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 ! List expanded DEFINEs
DEFINE increment (x) = x := x + 1#; ! Expanded DEFINE
DEFINE decrement (y) = y := y - 1#; ! Expanded DEFINE
! Other global data declarations

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: • Can appear only once in a compilation
• Must precede any TARGET directive and any nondirective lines
Scope: Applies to the compilation unit
Dependencies: None
References: TARGET on page 17-68

ENDIF
ENDIF identifies the end of code that is to be conditionally compiled.

ENDIF toggle-name

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 ERRORFILE

Default: 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.

ERRORFILE file-name
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: None
Placement: • 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.

ERRORS num-messages
=

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 ! Stop compiling when 10 errors are found
!Global declarations

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: EXPORT_GLOBALS
Placement: • Can appear any number of times in a compilation unit
• Must appear before the first procedure is compiled
• Cannot appear within BLOCK declarations
Scope: Applies to the compilation unit, except that NOEXPORT_GLOBALS
does not affect a compilation’s private data block, which is always
exported
Dependencies: • 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.
References: • 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: • Can appear only once in a compilation unit
• Must precede all declarations of data, blocks, and procedures
Scope: Applies to the compilation unit
Dependencies: None

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 externally-
defined 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: • GMAP has no effect if NOLIST, NOMAP, or SUPPRESS is active
• NOGMAP suppresses the global map even if MAP is active
References: • 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: pTAL compiler: GP_OK


EpTAL compiler: NOGP_OK
Placement: Anywhere except inside a data block or inside a procedure declaration
Scope: • 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 Implicitly Sets Implicitly Resets


pTAL • RISC1 _TNS_E_TARGET
• TARGETSPECIFIED
EpTAL • _TNS_E_TARGET RISC1
• TARGETSPECIFIED

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: None
Placement: • 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: • INNERLIST applies to subsequent statements it until it is overridden
by NOINNERLIST
• NOINNERLIST applies to subsequent statements until it is
overridden by INNERLIST
Dependencies: INNERLIST has no effect if NOLIST or SUPPRESS is active
References: • 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.

LINES num-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: • LIST applies to subsequent code it until it is overridden by NOLIST
• NOLIST applies to subsequent code until it is overridden by LIST
Dependencies: LIST has no effect if SUPPRESS is active
References: SUPPRESS on page 17-65

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: • MAP applies to subsequent code it until it is overridden by NOMAP
• NOMAP applies to subsequent code until it is overridden by MAP
Dependencies: MAP has no effect if NOLIST or SUPPRESS is active
References: • 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 Possible Values
Identifier class • VAR
• SUBPROC
• ENTRY
• LABEL
• DEFINE
• LITERAL
Type • Data type
• Structure
• Substructure
• Structure pointer
Addressing mode • Direct
• Indirect
Subprocedure, entry, or label offset
Text of LITERALs and DEFINEs

HP pTAL Reference Manual—523746-006


17 -46
Compiler Directives OPTIMIZE

OPTIMIZE
OPTIMIZE level
=

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. optimize-
level 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 Issues a warning when filename :
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:
• OVERFLOW_TRAPS procedure attribute
• ENABLE_OVERFLOW_TRAPS block attributes
References: See Managing Overflow Traps on page 13-1

Example 17-26. OVERFLOW_TRAPS Compiler Directive


?OVERFLOW_TRAPS ! Correct
PROC p;
BEGIN
?NOOVERFLOW_TRAPS ! Incorrect: OVERFLOW_TRAPS must appear
... ! between procedure declarations
END;
?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: • 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)
References: • 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: • PRINTSYM applies to subsequent declarations until overridden by
NOPRINTSYM
• NOPRINTSYM applies to subsequent declarations until overridden
by PRINTSYM
Dependencies: • 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)
References: • 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 ! Turn off symbol listing
INT i;
INT j;
?PRINTSYM ! Turn on symbol listing
INT k;

HP pTAL Reference Manual—523746-006


17 -52
Compiler Directives REFALIGNED

REFALIGNED
REFALIGNED ( 2 )

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: • ROUND applies to subsequent code until overridden by NOROUND
• NOROUND applies to subsequent code until overridden by ROUND
Dependencies: None

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: • 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)
References: • 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 SETTOG

Default: 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: 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
• 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 ( section-name )

assign-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 Section Names

Default: None
Placement: • Only in the source file (not in the compilation command)
• Must be the last directive on the directive line
Scope: Applies to the source file
Dependencies: • 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)
References: • 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. The MAIN file F sources in file F1.
2. File F1 sources in file F2.
3. File F2 sources in file F3.
4. File F3 sources in file F4.
5. File F4 sources in file F5.
6. File F5 sources in file F6.
7. 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_; ! Call procedures listed
END; ! 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: • 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)
References: • 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

NOWARN warning-number

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: • 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.
Dependencies: 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
Platform System
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
PC command line TNS/R3 ptal Yes Yes Yes
TNS/E2 eptal No Yes Yes
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 eptal.exe
nld.exe eld.exe
ld.exe
cmplr ptaldvr.dll eptalcom.exe
ptalc.dll
uopt.dll
ugen.dll
as1.dll
nld.dll
ld.dll
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 case-
sensitive.

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 Linking must be performed as a separate
one step. step after compilation.
Provides a GUI-based interface for you to You must specify the run-time libraries to the
select linker options. linker.

pTAL cross compiler linking is performed with one of the cross linkers:
Cross Linker Cross Compilers Directive Object Code
nld NonStop pTAL -nocall_shared* Non-PIC
ptal
ld NonStop pTAL -call_shared** PIC
ptal
eld NonStop pTAL -call_shared PIC
eptal
* 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.
This cross linker can
If an archive contains one use the archive as an
or more ... 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 )
FIXED

( fpoint )

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
integer D
ns
+ base %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
-

. fraction %F

VST005.vsd

More information: FIXED Numeric on page 3-17

REAL and REAL(64) Numeric

integer . fraction
+

E exponent
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

[ constant-list-seq ]

repetition-factor *

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

CASE selector OF BEGIN expression


;

END
OTHERWISE expression ;

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

var-2 FOR count


count-unit
constant
[ constant ]

constant-list

-> next-addr

VST015.vsd

More information: Group Comparison on page 5-24

Bit Extraction
ns
int-expression

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

STRUCT identifier
.

.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 identifier ( * )

STRUCTALIGN ( 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

STRUCT identifier ( 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 identifier ;

VOLATILE ,

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

STRUCT identifier

structure-layout ;

field-alignment range

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

STRUCT identifier ( 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 )

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 )

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

STRUCT identifier
range field-alignment

= previous-identifier ; 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

STRUCT identifier ( 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 )

= 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 identifier
VOLATILE INT .

.EXT

.SG

.SGX

( referral )

REFALIGNED ( 2 )

= 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 )

;
:= 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

STRUCT identifier ( referral )


.

.EXT

.SG

.SGX

= previous-identifier
field-alignment

;
[ index ] structure-layout
+ offset
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

STRUCT identifier = 'SG'


.EXT

.SG

.SGX

; structure-layout ;
[ index ]
+ offset
-

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

STRUCT identifier ( 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
INT .SG

.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

PROC identifier
type public-name-spec

parameter-list proc-attribute
,

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

SUBPROC identifier
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 )

VST636.vsd

HP pTAL Reference Manual—523746-006


A -33
Syntax Summary Procedure and Subprocedure

param-type

STRING

INT

REAL ( width )
UNSIGNED ( 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 )
FIXED

( fpoint )

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 procptr-name
return-type

formal-param-names attributes ;

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 assert-level : 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

ns ns ns >
variable . < left-bit
ns ns ns
: right-bit

:= 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

CASE selector 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 := initial-value TO limit


DOWNTO

DO

BY step statement

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 FOR count


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

SCAN variable WHILE test-char

RSCAN UNTIL

-> 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 ( var , mask ,

value ) ;

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 ( bufferaddr , maxdigits ,

remainingdigits qvaluein , qvalueout ) ;

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 ( checksum , bufferaddr ,

wordcount ) ;

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 ( scraddr , maxwords ,

duplicationcount ) ;

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 ( channel , lprmcommand ,

lacsubcommand , rdstdevstatus ,

channel-status ) ;

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 ( qvalue , bufferaddr ,

maxdigits ) ;

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 ( qvalue , bufferaddr

, maxdigits , qresidue ) ;

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 ( select , rank-channel

, ric-int-cause , 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 ( select , rank-channel

, ric-int-cause , 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

$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

More information: $LMIN on page 15-61

$LOCATESPTHDR
Note. The EpTAL compiler does not support this routine.

$LOCATESPTHDR ( headersize , virtaddr ,

sptbase ) ;

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 ( only-if-locked , lock-count ,

virtaddr ) ;

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 ( checksum ,

destaddr , srcaddr , 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 ( destaddr , srcaddr ,

maxwords , lastword ) ;

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 ( dividend , divisor ,

quotient , remainder ) ;

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 ( dividend , divisor ,

quotient , remainder ) ;

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.

$UNLOCKPAGE ( unlockcount , 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 ( ptetag , pageframe ,

abs ) :

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 assertion-level ,
=

procedure-name

VST123.vsd

Default: None
Placement: • Anywhere in the source file (not in the compilation command)
• Must be the last directive on the directive line
Scope: Applies until another ASSERTION overrides it
Dependencies: Has no effect without the ASSERT statement
References: ASSERT on page A-40

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
• Can appear only once in a compilation unit
Scope: Applies to all source code that follows it in the compilation unit
Dependencies: • 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
References: • 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: • 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
References: 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: • 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
Dependencies: 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 columns-value

VST127.vsd

Default: COLUMNS 132


Placement: • 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
Scope: 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: None
References: • 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: • DEFEXPAND applies to subsequent code it until it is overridden by
NODEFEXPAND
• NODEFEXPAND applies to subsequent code until it is overridden by
DEFEXPAND
Dependencies: DEFEXPAND has no effect if NOLIST or SUPPRESS is active
References: • 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: 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: • 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: • Can appear only once in a compilation
• Must precede any TARGET directive and any nondirective lines
Scope: Applies to the compilation unit
Dependencies: None
References: TARGET on page A-117

More information: DO_TNS_SYNTAX on page 17-28

ENDIF
See IF, IFNOT, and ENDIF on page A-100.

ERRORFILE

ERRORFILE file-name
define-name
assign-name

VST137.vsd

Default: None
Placement: • 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

ERRORS num-messages
=

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: EXPORT_GLOBALS
Placement: • Can appear any number of times in a compilation unit
• Must appear before the first procedure is compiled
• Cannot appear within BLOCK declarations
Scope: Applies to the compilation unit, except that NOEXPORT_GLOBALS
does not affect a compilation’s private data block, which is always
exported
Dependencies: • 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.
References: • 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: • Can appear only once in a compilation unit
• Must precede all declarations of data, blocks, and procedures
Scope: Applies to the compilation unit
Dependencies: None

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: • GMAP has no effect if NOLIST, NOMAP, or SUPPRESS is active
• NOGMAP suppresses the global map even if MAP is active
References: • 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: pTAL compiler: GP_OK


EpTAL compiler: NOGP_OK
Placement: Anywhere except inside a data block or inside a procedure declaration
Scope: • 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 Implicitly Sets Implicitly Resets


pTAL • RISC1 _TNS_E_TARGET
• TARGETSPECIFIED
EpTAL • _TNS_E_TARGET RISC1
• TARGETSPECIFIED

pTAL
Compiler IF pTAL IFNOT pTAL
pTAL or EpTAL True False
TAL False True

HP pTAL Reference Manual—523746-006


A-101
Syntax Summary IF, IFNOT, and ENDIF

Default: None
Placement: • 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: • INNERLIST applies to subsequent statements it until it is overridden
by NOINNERLIST
• NOINNERLIST applies to subsequent statements until it is
overridden by INNERLIST
Dependencies: INNERLIST has no effect if NOLIST or SUPPRESS is active
References: • 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

LINES num-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: • LIST applies to subsequent code it until it is overridden by NOLIST
• NOLIST applies to subsequent code until it is overridden by LIST
Dependencies: LIST has no effect if SUPPRESS is active
References: SUPPRESS on page A-115

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: • MAP applies to subsequent code it until it is overridden by NOMAP
• NOMAP applies to subsequent code until it is overridden by MAP
Dependencies: MAP has no effect if NOLIST or SUPPRESS is active
References: • LIST on page A-104
• SUPPRESS on page A-115

More information: MAP on page 17-45

OPTIMIZE

OPTIMIZE level
=

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

OPTIMIZEFILE filename

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:
• OVERFLOW_TRAPS procedure attribute
• ENABLE_OVERFLOW_TRAPS block attributes
References: 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:
• NOLIST or SUPPRESS is active
• The list file is a terminal
References: • 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: • PRINTSYM applies to subsequent declarations until overridden by
NOPRINTSYM
• NOPRINTSYM applies to subsequent declarations until overridden
by PRINTSYM
Dependencies: • PRINTSYM has no effect if NOLIST or SUPPRESS is active
• PRINTSYM interacts with SAVEGLOBALS and USEGLOBALS
References: • 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 )

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: 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 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: • ROUND applies to subsequent code until overridden by NOROUND
• NOROUND applies to subsequent code until overridden by ROUND
Dependencies: None

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: • 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
References: • 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 section-name

VST171.vsd

Default: 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

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: 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
• 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: • Only in the source file (not in the compilation command)
• Must be the last directive on the directive line
Scope: Applies to the source file
Dependencies: • Interacts with COLUMNS
• Interacts with SECTION (see Section Names on page 17-61)
• Interacts with the directives referenced in the next row
References: • 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: • 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.
References: • 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

NOWARN warning-number

VST675.vsd

Default: WARN
Placement: Anywhere
Scope: • 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.
Dependencies: 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:
D-Series C-Series
Omitted File-Name Parts Partial File Name System 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 ! Equivalent to ?SOURCE $a.b.cat
?SOURCE cc ! Equivalent to ?SOURCE $a.b.zebra
?SOURCE bb ! 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 SSV7, $aa.b3
ASSIGN SSV10, $aa.grplip
ASSIGN SSV8, mylib
ASSIGN SSV20, $cc.divlib
ASSIGN trig, $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 (SSV7)
$default-volume.mylib.unpack (SSV8)
$aa.grplib.unpack (SSV10)
$cc.divlib.unpack (SSV20)
$default-volume.default-subvolume.unpack
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 • TNS/E object code
• Non-PIC (default) or PIC • PIC
• Object files have file code • Object files have file code
700 on Guardian platform 800 on Guardian platform
• Preemptable • 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 Syntax error Accepted in template structure declarations
with MAXALIGN attribute (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 • If size is not an
integral multiple of 8, integral multiple of 16,
$STACK_ALLOCATE $STACK_ALLOCATE
rounds size up to the rounds size up to the
next integral multiple of next integral multiple of
8. 16.
• The returned value is • The returned value is
aligned to an 8-byte aligned to a 16-byte
boundary. boundary.
$UNLOCKPAGE routine Not supported
$TRIGGER routine 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 Issues a warning when filename
for errors in filename meets one of the Conditions: on
page C-3
OVERFLOW_TRAPS Default
NOOVERFLOW_TRAPS Default
SRL Not accepted
TARGET Default and only Default and only accepted option
accepted option is is _TNS_E_TARGET
TNS_R_ARCH

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 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

HP pTAL Reference Manual—523746-006


C- 3
Differences Between the pTAL and EpTAL Compilers Compiler Directives

HP pTAL Reference Manual—523746-006


C- 4
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 /* For 16-bit return value */
val_cc_combo.parts.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 bit-
deposit 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 odd-
byte 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 Addresses (continued)
in structure pointers
ABS routine 15-22/15-23 description of 10-17
Absolute value 15-22
within structures 9-52
Actual parameters
nonextended 5-12
description of 12-11
of structures declared in
checking for presence of 15-77 subprocedures 9-39
in CALL statement 12-10 types of
of DEFINEs 6-7/6-9 See Address types
Addition operator
Address-conversion routines 15-14
signed (+) Aliases for data types 3-4
in arithmetic expression 5-5 Alignment
operand types for 5-6 base 9-9
precedence of 5-3 of constant lists 3-22/3-23
unsigned (’+’) of data 4-1/4-3
in arithmetic expression 5-5 of structure fields 9-5/9-13
operand types for 5-8 of structures
precedence of 5-3 in depth 9-15
result types for 5-9 overview 9-4/9-5
with INT(32) operands 5-11 of substructures 9-16/9-19
Address misalignment ALPHA routine 15-23/15-24
causes of 4-1 AND operator
handling 4-3 description of 5-17
tracing facility for 4-1/4-2 condition codes and 5-18
Address symbols, base 2-7 in conditional expression 5-15
Address types operand types for 5-17
description of 3-5/3-6 precedence of 5-4
converting 3-7/3-9 truth table for 5-15
stored in pointers 10-5/10-11 Angle brackets (< >) 2-4
Addresses ar utility 18-6
See also Data addresses Architecture and RVUs 1-2
arrays of 8-2 Arguments 17-3
as parameters to built-in See also Parameters
routines 15-2/15-3 Arithmetic expressions 5-5/5-6
assignment of 16-15 Arithmetic operators
extended 5-12 signed
in simple pointers 10-14, 10-17 description of 5-6/5-7
in arithmetic expressions 5-5

HP pTAL Reference Manual—523746-006


Index -1
Index A

Arithmetic operators (continued) Assignments


unsigned description of 12-4/12-6
description of 5-8/5-11 bit-deposit 12-9/12-10
in arithmetic expressions 5-5 character string 12-7
Arithmetic overflow testing 15-76 expressions in 5-20/5-21
Arrays FIXED variable 12-7
description of 8-1 hardware indicators after 13-3/13-8
alignment of, in structures 9-13/9-15 initial 7-1
as parameters 14-13, 14-14 move statement 12-28/12-33
data type of 15-88 number 12-7
declaring of addresses 16-15
in structures 9-40/9-41 pointer 12-6
read-only 8-6/8-7 procedure pointer 14-33/14-34
read-write 8-2/8-5 Asterisk (*)
elements of as multiplication operator
accessing 3-9 See Multiplication operator
number of 15-69 in compiler listing 17-42
length of in constant lists 2-5
in bits 15-28 in template structures 9-36
in bytes 15-59 in value parameter 2-6
nonstring 8-9 in $ASCIITOFIXED routine 15-25
number of elements of 15-69 in $FIXEDTOASCII routine 15-45
of addresses 8-2 in $FIXEDTOASCIIRESIDUE
redefining 9-55/9-56 routine 15-46, 15-47
ASCII characters to prevent scaling
set of 2-2 of FIXED initialization value 3-4
testing for of FIXED parameter 14-11/14-12
alphabetic 15-23 Atomic operations
numeric 15-68 description of 15-4
special (nonalphanumeric) 15-85 data misalignment and 4-1, 4-3
ASCIITOFIXED routine 15-24/15-25 ATOMIC_ADD routine 15-5
ASSERT statement 12-3/12-4 ATOMIC_AND routine 15-6
ASSERTION directive 17-19/17-20 ATOMIC_DEP routine 15-7/15-8
ASSIGN command ATOMIC_GET routine 15-8
description of B-7 ATOMIC_OR routine 15-9
ordinary B-8 ATOMIC_PUT routine 15-10
search subvolume (SSV) B-9/B-10 Attributes
Assignment operator (:=) 5-4 block 13-2/13-3
See also Assignments procedure 14-5/14-9
SCF user interface 4-3

HP pTAL Reference Manual—523746-006


Index -2
Index B

AUTO parameter Bit operations (continued)


description of 9-7 logical 5-10
compared to PLATFORM precedence of 5-3
parameter 9-8 shift 5-33/5-35
FIELDALIGN clause and 9-5/9-6 BITLENGTH routine 15-28
AXADR routine 15-26 BITOFFSET routine 15-29
Bitwise logical operators 5-10
B Bit-deposit assignment
statement 12-9/12-10
Backslash (\)
BIT_FILLER declaration 9-46/9-47
See Remainder operator (’\’)
Block attributes 13-2/13-3
BADDR address type BLOCKGLOBALS directive 17-21/17-22
description of 10-6 Blocks, data
converting 3-9 See Global data, blocked
parameters of 14-11 Boolean expressions
STRING pointers of 10-9 See Conditional expressions
BADDR_TO_EXTADDR Brackets
routine 15-26/15-27
angle (< >) 2-4
BADDR_TO_WADDR routine 15-27
square ([ ]) 2-4
Base address symbols 2-7
Built-in routines 15-1
Bases of constants 2-12
See also Atomic operations
BEGIN keyword
See also Nonatomic operations
in compound statement 12-2
BY keyword in FOR statement 12-20
in procedure 14-17
Bytes 3-1
in structure 9-3
in subprocedure 14-21
BEGINCOMPILATION directive C
description of 17-20 C procedure attribute 14-5
and global data CALL statement 12-10/12-12
declarations 17-8/17-13 CALLABLE procedure attribute 14-5, 14-6
SOURCE directive and 17-63 CALL_SHARED directive 17-22
BEGIN-END construct CARRY routine
See Compound statements description of 15-30
Bit fields after assignments 13-4
description of 3-1 atomic operation that can set 15-4
delimiting 2-4 in nested IF statements 13-12/13-13
Bit operations nonatomic operations that can
description of 1-6, 5-31 set 15-20/15-22
bit-deposit assignment returning its value to calling
statement 12-9/12-10 procedure 13-16
extraction 5-31/5-32 CASE expressions 5-21/5-22

HP pTAL Reference Manual—523746-006


Index -3
Index C

CASE statement Compilation command


description of 12-12 description of 16-4/16-6
empty 12-12 with compiler directives 17-1
labeled 12-13/12-15 Compilation units, naming 16-13
unlabeled 12-15/12-17 Compiler directives
CBADDR address type interpretation and processing of 17-1
description of 10-6 specifying
converting 3-9 in compilation command line 17-1
parameters of 14-11 in source code 17-2/17-3
pointers of 10-10 summary of 17-13/17-19
Character set for pTAL 2-2 Compiler input directives 17-14
Character string constants 3-12/3-13 Compiler listing
Character-test routines 15-14 asterisk (*) in 17-42
CHECKSHIFTCOUNT directive 17-23 conditionally compiled lines and 17-42
CHECKSUM routine 15-31/15-32 directives that affect 17-14
COBOL procedure attribute 14-5 Compiler listing directives 17-14
Code Coverage Tool 16-17 Compilers
CODECOV directive 17-24 comparison of EpTAL, pTAL, and
Codes TAL 1-2
completion 16-6 differences between pTAL and
condition EpTAL C-1/C-3
See Condition codes Completion codes 16-6
Colon (:) 2-4 Compound statements
COLUMNS directive syntax of 12-2/12-3
description of 17-24/17-25 within DEFINE bodies 6-4
SOURCE directive and 17-62 Concatenation operator (&) 12-30
Comma (,) 2-4 Condition codes
Commands See also Hardware indicators
ASSIGN after assignments 13-4/13-8
See ASSIGN command AND operator and 5-18
compilation atomic operations that can set 15-4
See Compilation command C/C++ procedures on TNS/E and D-1
DEFINE group comparisons and 5-29/5-30
See DEFINEs nesting 13-12/13-14
Deploy 18-7 nonatomic operations that
Comments, delimiters for 2-4 alter 15-17/15-22
Common run-time environment (CRE) NOT operator and 5-18
services 1-7 OR operator and 5-18
COMP routine 15-32
Compatibility of pTAL and TAL 1-1

HP pTAL Reference Manual—523746-006


Index -4
Index D

Condition codes (continued) Cross compilers


returning ar utility and 18-6
with RETURN statement 12-35 compiling with 18-5
with RETURNSCC attribute debugging and 18-6, 18-7
in procedure 14-5/14-8 documentation for 18-8
in subprocedure 14-19/14-20 features of 18-1
testing after function calls 12-35/12-36 file extension for 18-1
Conditional compilation directives 17-17 from PC command line 18-3
Conditional expressions in ETK 18-2
description of 5-15/5-17 linking and 18-5
hardware indicators in 13-8/13-12 PC-to-NonStop host transfer tools
Constant expressions for 18-7
description of 5-14 platforms for 18-1
as parameters 14-14 CWADDR address type
in data type specifications 3-3 description of 10-6
Constant lists converting 3-9
description of 3-21/3-22 parameters of 14-11
aligning 3-22/3-23 pointers of 10-10
in array declarations 8-8/8-9 C-series RVU 1-2
in move statement 12-28 C/C++ procedures D-1
Constants
See also LITERALs D
comparing to data addresses 3-11 Data
description of 2-12 alignment of 4-1/4-3
in expressions blocks of
See Constant expressions See Global data, blocked
lists of global
See Constant lists See System global data
numeric bases of 2-12 misaligned
Continuation lines 17-3 See Address misalignment
Conventions for syntax diagrams -xxxvii/-xl operations on 1-6
Conversion representation of 3-1
between address types 3-7/3-9
scanning 12-1
between addresses and numbers 3-7
sets of 1-5
implicit 3-8
system global
Copy operation (move
See System global data
statement) 12-28/12-33
COUNTDUPS routine 15-33/15-34 transferring
CRE services 1-7 statements for 12-1

HP pTAL Reference Manual—523746-006


Index -5
Index D

Data (continued) Declarations


types of description of 2-8
See Data types array
Data addresses See Arrays, declaring
arithmetic operations on 3-10/3-11 BIT_FILLER 9-46/9-47
comparing DEFINE 6-3/6-5
description of 5-11 entry point 14-22/14-25
extended addresses 5-12 equivalenced
nonextended addresses 5-12/5-14 See Equivalenced variables,
to constants 3-11 declaring
to procedure pointers 3-11 external 17-63
computing distance between 3-11 FILLER 9-46/9-47
converting to numbers 3-7 function
decrementing 3-10 See Procedures, declaring
incrementing 3-10 global
storing in variables 3-7 See Global data
Data allocation statements 12-1 LITERAL 6-1/6-3
Data types NAME 16-13
See also Address types pointer
aliases for 3-4 See Pointers, declaring
changing, with group procedure
comparisons 5-27/5-28 See Procedures, declaring
obtaining 15-88 simple variable
of expressions 5-2 See Simple variables, declaring
pTAL structure
description of 3-1/3-2 See Structures, declaring
compared to TAL 1-5 sublocal 14-21
specifying 3-3/3-4 subprocedure
DBL routine 15-34/15-35 See Subprocedures, declaring
DBLL routine 15-35 substructure
DBLR routine 15-36 See Substructures, declaring
Debugging Default misalignment handling method 4-3
cross compilers and 18-6, 18-7 Default target file 16-6
Enterprise Toolkit (ETK) and 18-6 DEFAULTS DEFINE B-7
OPTIMIZE directive and 17-47 DEFEXPAND directive
with ASSERTION directive and description of 17-26/17-27
ASSERT statement 12-3/12-4 output of 6-6
Decimal point, implied position of 6-4
See Implied decimal point
DEFINE files 18-1
DEFINE tool 18-7
HP pTAL Reference Manual—523746-006
Index -6
Index E

DEFINEs Division operator (continued)


calling 6-5/6-6 unsigned (’⁄ ’)
CLASS attributes of B-5 in arithmetic expression 5-5
declaring 6-3/6-5 operand types for 5-9
expansion of 6-6 precedence of 5-3
how compiler processes 6-6 result types for 5-9
LITERAL declarations and 6-1 with INT(32) and FIXED
names of B-5 operands 5-11
parameters of DLLs (dynamic-link libraries) 16-12
actual 6-7/6-9 DO keyword
formal 6-3 in DO-UNTIL statement 12-17
substituting file names for B-5 in FOR statement 12-20
DEFINETOG directive 17-27/17-28 in WHILE statement 12-45
Definition structures, declaring Dollar sign ($) 2-5
equivalenced 11-24/11-25 Doublewords 3-1
not equivalenced 9-33/9-35 DOWNTO keyword 12-20
DO-UNTIL statement
Definition substructures
description of 12-17/12-19
declaring 9-42/9-44
hardware indicators in 13-8
redefining 9-56/9-59
DO_TNS_SYNTAX directive 17-28/17-29
Delimiters 2-4/2-5
DROP statement 12-19/12-20
Deploy command 18-7
Dynamically selected procedure
DFIX routine 15-36/15-37
calls 14-35/14-36
Diagnostics directives 17-15
Dynamic-link libraries (DLLs) 16-12
Directive stacks 17-4/17-5
D-series RVU 1-2
DISABLE_OVERFLOW_TRAPS block
attribute 13-2/13-3
Disk file names E
description of B-1/B-2 EFLT routine 15-37
as compiler directive arguments 17-3 EFLTR routine 15-38, 15-38/15-39
ASSIGN command and B-7 eld utility
internal B-4 ar utility and 18-7
logical B-4 migrating to TNS/E and D-1
partial B-3/B-4 Ellipsis (...) 12-13
parts of B-2/B-3 ELSE keyword 12-26
substituting for DEFINE commands B-5 Embedded SQL/MP or SQL/MX 1-3
Division operator Empty CASE statement 12-12
signed (⁄ ) EMS (Event Management Service) 4-2
in arithmetic expression 5-5 ENABLE_OVERFLOW_TRAPS block
attribute 13-2/13-3
operand types for 5-6
precedence of 5-3

HP pTAL Reference Manual—523746-006


Index -7
Index E

END keyword ERRORFILE directive 17-30/17-32


in compound statement 12-2 ERRORS directive 17-33
in procedure 14-17 ETK
in structure 9-3 See Enterprise Toolkit (ETK)
in subprocedure 14-21 Event Management Service (EMS) 4-2
ENDIF directive 17-29/17-30 EXCHANGE routine 15-39
Enterprise Toolkit (ETK) Exclamation mark (!) 2-4
cross compilers and 18-2 Executable statements
debugging and 18-6 See Statements
DEFINE files and 18-1 EXECUTEIO routine 15-40/15-41
online help for 18-8 Exporting program names 16-12
EXPORT_GLOBALS directive 17-34
Entry points
Expressions
declaring 14-22/14-25
description of 5-1
procedure 10-10
arithmetic 5-5/5-6
subprocedure 10-10
as parameters to built-in routines 15-3
Equal sign
as delimiter 2-5 assignment 5-20/5-21
Boolean (conditional) 5-15/5-17
as equal operator
CASE 5-21/5-22
signed (=)
conditional 5-15/5-17
in conditional expression 5-18
constant
operand types for 5-18
description of 5-14
precedence of 5-4
as parameters 14-14
without operands 5-19
in data type specifications 3-3
unsigned (’=’)
data types of 5-2
in conditional expression 5-18
group comparison
operand types for 5-19
precedence of 5-4 See Group comparison expressions
IF 5-23/5-24
with INT(32) operands 5-10
special 5-20
without operands 5-19
EXTADDR address type
Equivalenced variables
description of 10-6
description of 11-1/11-2
comparing 5-12
declaring
converting 3-9
description of 11-2/11-3
parameters of 14-11
nonstructure 11-5/11-15
pointers of 10-11
system global 11-22/11-29
EXTADDR_TO_BADDR routine 15-41
memory allocation for 11-4
EXTADDR_TO_WADDR routine 15-42
Error messages
EXTDECS file 17-63
logging to a file 17-30
Extended addresses 5-12
maximum allowed 17-33
Extended parameters 14-16

HP pTAL Reference Manual—523746-006


Index -8
Index F

EXTENSIBLE procedure attribute 14-5, FIXED data type


14-7 See also FIXED variables
External declarations 17-63 built-in routines for 15-15
EXTERNAL keyword constants of 3-17/3-18
in procedure declaration 14-2, 14-4 functions that return values of 14-12
in procedure entry-point obtaining
declaration 14-23
with $DFIX routine 15-36
Extracting bits 5-31/5-32
with $FIX routine 15-44
with $FIXD routine 15-44
F with $FIXR routine 15-48
FAIL misalignment handling method 4-3 with $IFIX routine 15-52
FIELDALIGN clause with $LFIX routine 15-60
description of 9-20 parameters of 14-11, 14-12
role in field alignment 9-5/9-6 rounding and 15-13
FIELDALIGN directive FIXED variables
description of 9-20, 17-35 See also FIXED data type
role in field alignment 9-5/9-6 assigning numbers to 12-7
File IDs B-3 rounding 17-55
File names
scaling
See Disk file names
description of 5-7
Files
when assigning numbers to 12-7
DEFINE 18-1
using 5-8
EXTDECS 17-63
FIXEDTOASCII routine 15-45/15-46
input 16-3
FIXEDTOASCIIRESIDUE
map of 17-36 routine 15-46/15-47
OBJECT 16-6 FIXED(0) data type
object See FIXED data type
See Object files Fixed-point scaling 12-7
output 16-3 FIXERRS macro 17-30/17-32
source FIXI routine 15-47/15-48
See Source files FIXL routine 15-48
target 16-6 FIXR routine 15-48/15-49
temporary B-7 FLT routine 15-49/15-50
FILL16 procedure 15-42/15-43 FLTR routine 15-50
FILL32 procedure 15-42/15-43 FMAP directive 17-36
FILL8 procedure 15-42/15-43 FOR keyword
FILLER declaration 9-46/9-47 in FOR statement 12-20
FIX routine 15-44 in move statement 12-28
FIXD routine 15-44/15-45

HP pTAL Reference Manual—523746-006


Index -9
Index G

FOR statement
description of 12-20/12-21
G
Global data
nested 12-21
See also System global data
optimized 12-22
blocked
standard 12-21
allocating 16-15
Formal parameters
declaring 16-12/16-15
indirection symbols and 2-7
SECTION directive and 16-16
of DEFINEs 6-3
sharing 16-16
of procedures 14-3, 14-10
SOURCE directive and 16-16
of subprocedures 14-10, 14-19
map of 17-37
passing by reference 2-7
saving and using 17-8/17-13
procedure pointers as 14-26, 14-32
unblocked 16-14
specifying 14-10/14-15
Global scope 2-10
FORTRAN procedure attribute 14-5
GLOBALIZED directive 17-36
FORWARD keyword
GMAP directive 17-37
in procedure declaration 14-2, 14-4
GOTO statement 12-23/12-25
in procedure entry-point
declaration 14-23 GP_OK directive 17-38/17-39
Greater than operator
in subprocedure declaration 14-19,
14-21 signed (>)
in subprocedure entry-point in conditional expression 5-18
declaration 14-24 operand types for 5-18
fpoint precedence of 5-4
changing 15-82 without operands 5-19
obtaining 15-78 unsigned (’>’)
rounding 17-55 in conditional expression 5-18
scaling 12-7 operand types for 5-19
specifying 15-60 precedence of 5-4
FREEZE routine 15-51 with INT(32) operands 5-10
Functions without operands 5-19
See also Procedures Greater than or equal operator
See also Routines signed (>=)
atomic in conditional expression 5-18
See Atomic operations operand types for 5-18
definition of 14-1 precedence of 5-4
RETURN statement and 12-34 without operands 5-19
with two return values D-1/D-3 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 Identifiers


unsigned (’>=’) (continued) listing (continued)
with INT(32) operands 5-10 with PRINTSYM directive 17-52
without operands 5-19 saving 17-66
Group comparison expressions IF and IFNOT directives 17-39/17-42
description of 5-24/5-27 IF expressions 5-23/5-24
for changing data types 5-27/5-28 IF statement
testing 5-29/5-30 See also Conditional expressions
description of 12-26/12-27
H hardware indicators in 13-8
IFIX routine 15-52/15-53
HALT routine 15-51
Implicit address conversion 3-8
Hardware indicators
Implied decimal point
See also Condition codes
ignoring
across procedures 13-14/13-16
with $FIXD routine 15-45
after assignments 13-3/13-8
with $FIXI routine 15-47
built-in routines and 15-4
with $FIXL routine 15-48
in conditional expressions 13-8/13-12
in data type declarations 3-3
list of 13-1
in formal parameters 14-12
Hash mark (#) 2-5
in simple variable declarations 7-2
HIGH routine 15-52
moving 15-82
HP TACL commands
description of B-4 obtaining
with $DFIX routine 15-37
ASSIGN
with $IFIX routine 15-53
See ASSIGN command
with $LFIX routine 15-60
DEFINE
parentheses and 2-4
See DEFINEs
IN file option 16-4
RUN 16-4
Indexes, accessing array elements with 3-9
Hybrid executable object files 16-11
Indirection symbols 2-7
Hyphen (-)
Initialization
followed by hyphen (-) 2-4
of exported data 17-34
followed by right angle bracket (>) 2-5
of read-only arrays 8-7
of simple pointers 10-14/10-16
I of structure pointers 10-17/10-19
Identifiers scope and 2-11
description of 2-8/2-9 INNERLIST directive 17-42/17-43
classes of 2-9 Input files 16-3
listing Instruction codes, listing 17-42
with GMAP directive 17-37
with MAP directive 17-45

HP pTAL Reference Manual—523746-006


Index- 11
Index K

INT data type Keywords (continued)


constants of 3-15 nonreserved 2-3/2-4
converting 3-9 reserved 2-3
functions that return values of 14-12
high-order word of 15-52 L
parameters of 14-11, 14-12 Labeled CASE statement 12-13/12-15
rounding and 15-13 Labels
signed value of 15-47 address types of 10-10
unsigned value of 15-48 dropping 12-19
$INTR routine and 15-58 in procedures 14-37
INT routine 15-53/15-54 LAND operator
Internal file names B-4 in arithmetic expression 5-5
INTERROGATEHIO routine 15-55/15-56 operand types for 5-10
INTERROGATEIO routine 15-57/15-58 precedence of 5-3
INTERRUPT procedure attribute 14-5, 14-6
with INT(32) operands 5-10
INTR routine 15-58/15-59
$ATOMIC_AND routine and 15-6
INT(16) data type
$ATOMIC_DEP routine and 15-7
See INT data type
LANGUAGE procedure attribute 14-5/14-8
INT(32) address type
ld utility 18-7
bitwise logical operators and 5-10/5-11
Least significant byte 3-1
converting 3-9
Left-to-right move (:=) 12-28
obtaining
LEN routine 15-59/15-60
with $DBLL routine 15-35 Length parameters
with $DBLR routine 15-36 in CALL statements 12-11
with $UDBL routine 15-89 in declarations
unsigned operators and 5-10/5-11 procedure 14-3
INT(32) data type procedure pointer 14-28
constants of 3-16/3-17 subprocedure 14-20
rounding and 15-13 passing conditionally 15-74
INT(64) data type Less than operator
See INT data type signed (<)
INT_OV routine 15-54/15-55 in conditional expression 5-18
INVALID_FOR_PTAL directive 17-43
operand types for 5-18
Itanium architecture
precedence of 5-4
See TNS/E architecture
without operands 5-19
unsigned (’<’)
K in conditional expression 5-18
Keywords operand types for 5-19
description of 2-2 precedence of 5-4
in syntax diagrams -xxxviii
HP pTAL Reference Manual—523746-006
Index -12
Index M

Less than operator Logical operators


unsigned (’<’) (continued) bitwise 5-10
with INT(32) operands 5-10 in arithmetic expressions 5-5
without operands 5-19 with INT(32) operands 5-10
Less than or equal operator longjmp() instruction 9-1
signed (<=) Loops
in conditional expression 5-18 FOR
operand types for 5-18 See FOR statement
precedence of 5-4 WHILE
without operands 5-19 See WHILE statement
unsigned (’<=’) LOR operator
in conditional expression 5-18 in arithmetic expression 5-5
operand types for 5-19 operand types for 5-10
precedence of 5-4 precedence of 5-3
with INT(32) operands 5-10 with INT(32) operands 5-10
without operands 5-19 $ATOMIC_DEP routine and 15-7
LFIX routine 15-60/15-61 $ATOMIC_OR routine and 15-9
Libraries
dynamic-link (DLLs) 16-12 M
user 17-65 MAIN procedure attribute 14-5
LINES directive 17-44 MAP DEFINE B-6
Linking MAP directive 17-45/17-46
description of 16-7/16-11 MAX routine 15-64
cross compilers and 18-5 MAXALIGN attribute 9-37
LIST directive Maximum routines 15-15
description of 17-44/17-45 Messages, error
SOURCE directive and 17-62 See Error messages
LITERAL declarations 6-1/6-3 MIN routine 15-64/15-65
LMAX routine 15-61 Minimum routines 15-15
LMIN routine 15-61/15-62 Minus sign (-)
Local GOTO statement 12-23 as subtraction operator
Local scope 2-10 See Subtraction operator
LOCATESPTHDR routine 15-62/15-63 as unary operator
LOCKPAGE routine 15-63/15-64 operand types for 5-6
Logical file names precedence of 5-3
ASSIGN command and B-7
syntax of 5-5
compiler directives that accept 17-3
MISALIGNLOG attribute (SCF)
in place of disk file names B-4 misalignment handling and 4-3
misalignment tracing facility and 4-1

HP pTAL Reference Manual—523746-006


Index -13
Index N

Misalignment Nonlocal GOTO statement 12-24


See Address misalignment Nonreserved keywords 2-3/2-4
Mnemonics, listing 17-42 NonStop EpTAL 18-2
Modular programming 1-6 NonStop operating systems 1-2
Most significant byte 3-1 NonStop pTAL 18-2
Move statement 12-28/12-33 NonStop Series
MOVEANDCXSUMBYTES See TNS architecture
routine 15-65/15-66 NonStop Series/Itanium
MOVENONDUP routine 15-67/15-68 See TNS/E architecture
Multiplication operator NonStop Series/RISC
signed (*) See TNS/R architecture
description of 2-6 Nonstring arrays 8-9
in arithmetic expression 5-5 NOOVERFLOW_TRAPS procedure
operand types for 5-6 attribute
precedence of 5-3 description of 13-2
unsigned (’*’) in procedure 14-5, 14-8
description of 2-6 in subprocedure 14-19, 14-20
operand types for 5-8 Not equal operator
precedence of 5-3 signed (<>)
result types for 5-9 in conditional expression 5-18
with INT(32) operands 5-11 operand types for 5-18
precedence of 5-4
N without operands 5-19
unsigned (’<>’)
NAME declarations 16-13
in conditional expression 5-18
Named toggles 17-6
operand types for 5-19
Naming compilation units 16-13
precedence of 5-4
NATIVEATOMICMISALIGN attribute
(SCF) 4-3 with INT(32) operands 5-10
Nesting condition codes 13-12/13-14 without operands 5-19
Next address NOT operator
in move statement 12-28 description of 5-17
in RSCAN statement 12-40 condition codes and 5-18
in SCAN statement 12-40 in conditional expression 5-15
nld utility 18-7 operand types for 5-17
Node names B-2 precedence of 5-4
NOname directive truth table for 5-15
See name directive Null statement 12-2
Nonatomic access 4-3 Numbers, converting to data addresses 3-7
Nonatomic operations 15-11, 15-17/15-22 NUMERIC routine 15-68
Nonextended addresses 5-12 Numeric toggles 17-6

HP pTAL Reference Manual—523746-006


Index -14
Index O

O Operators (continued)
logical
OBJECT file 16-6 description of 5-10
Object files
in arithmetic expressions 5-5
content directives for 17-16
NOT
creating 16-7/16-11
description of 5-17
generating 16-4
condition codes and 5-18
hybrid 16-11
OR
linking 16-7/16-11
description of 5-17
OCCURS routine 15-69/15-71
condition codes and 5-18
Odd-byte references 10-14, 10-17
precedence of 5-3/5-4
OF keyword
relational
in labeled CASE statement 12-13
See Relational operators
in unlabeled CASE statement 12-15
signed
OFFSET routine
description of 15-71/15-73 See Signed operators
structure pointers and 10-18 unsigned
Online help for cross compilers 18-8 See Unsigned operators
Operands OPTIMIZE directive 17-47
in arithmetic expressions 5-5 OPTIMIZEFILE directive 17-47/17-49
scaling FIXED 5-7 Optional parameters 15-73/15-76
OPTIONAL routine 15-73/15-76
Operating systems 1-2
OR operator
Operations
description of 5-17
See also Operators
atomic condition codes and 5-18
in conditional expression 5-15
See Atomic operations
operand types for 5-17
bit
precedence of 5-4
See Bit operations
truth table for 5-15
data 1-6
OTHERWISE keyword
listed by data type 3-4
in labeled CASE statement 12-13
nonatomic
in unlabeled CASE statement 12-15
See Nonatomic operations
OUT file option 16-4
Operators
Output files 16-3
description of 2-5/2-6
Overflow
AND
managing
description of 5-17
generally 13-1/13-3
condition codes and 5-18
GOTO statement and 12-24/12-25
arithmetic
testing 15-76
See Arithmetic operators
concatenation (&) 12-30

HP pTAL Reference Manual—523746-006


Index -15
Index P

OVERFLOW routine Period (.)


description of 15-76/15-77 in bit-deposit assignment
after assignments 13-3/13-4 statement 12-9
atomic operation that can set 15-4 in formal parameters 14-10, 14-13
in nested IF statements 13-12/13-13 in pointers
nonatomic operations that can procedure 14-28
set 15-17/15-22 simple 10-12
returning its value to calling structure 10-16
procedure 13-16 in structure item identifiers 2-4
OVERFLOW_TRAPS in structures
directive 17-49/17-50
equivalenced definition 11-24
OVERFLOW_TRAPS procedure attribute
referral 9-38
description of 13-2
PIC
in procedure 14-5, 14-8
See Position-independent code (PIC)
in subprocedure 14-19, 14-20
PLATFORM parameter
description of 9-7
P compared to AUTO parameter 9-8
PAGE directive 17-51 FIELDALIGN clause and 9-5/9-6
Page heading 17-51 Plus sign (+)
PARAM routine 15-77 as addition operator
PARAM SWAPVOL command B-7 See Addition operator
Parameters as unary operator
See also Arguments in arithmetic expression 5-5
actual operand types for 5-6
See Actual parameters precedence of 5-3
extended 14-16 POINT routine 15-78
formal Pointers
See Formal parameters description of 1-6
of built-in routines 15-2/15-3 address types stored in 10-5/10-11
optional 15-73/15-76 allocation of 10-1
referencing 14-16 assignment statements with 12-6
Parentheses declaring
as delimiters 2-4 overview 10-2/10-4
implied decimal point and 2-4 procedure
operator precedence and 5-4 See Procedure pointers,
Partial file names declaring
description of B-3/B-4 simple
ASSIGN SSV command and B-9 See Simple pointers, declaring
PASCAL procedure attribute 14-5
PC-to-NonStop host transfer tools 18-7

HP pTAL Reference Manual—523746-006


Index -16
Index P

Pointers Procedure pointers


declaring (continued) description of 14-26/14-29
structure address types of 10-10
See Structure pointers, assignments to 14-33/14-34
declaring comparing to data addresses 3-11
system global declaring
See System global data, as formal parameters 14-32
declaring, pointers as variables 14-29/14-30
VOLATILE 10-4 in structures 14-30/14-31
procedure for dynamically selected procedure
See Procedure pointers calls 14-35/14-36
simple Procedures
See Simple pointers description of 1-4, 14-1
stepping 3-10 See also Functions
structure See also Routines
See Structure pointers address types of 10-10
testing for nonzero values 3-12 as parameters 14-14
POPname directive attributes of 14-5/14-9
See name directive bodies of 14-17/14-18
Position-independent code (PIC) 17-22 callable 14-6
Pound sign (#) 2-5 converting from variable to
Precedence of operators 5-3/5-4 extensible 14-7
PRINTSYM directive 17-52 C/C++ D-1
PRIV procedure attribute 14-5/14-6 declaring 14-2/14-4
Private data area 1-4 dynamically selected calls
PRIVATE keyword 16-14 to 14-35/14-36
Privileged mode 15-1/15-2 extensible 14-7
Privileged routines 15-11/15-12 EXTERNAL declaration of 14-2, 14-4
PROC address type 14-11/14-12
formal parameter specification
PROC keyword 14-2 in 14-10/14-15
PROCADDR address type FORWARD declaration of 14-2, 14-4
description of 10-6 labels in 14-37
comparing to PROCPTR 3-11 languages of 14-8
converting 3-9 main 14-5
parameters of 14-11 resident 14-6
pointers of 10-10 scope of 2-10/2-11
PROCADDR routine 15-78/15-79 system 1-7
Procedure calls (CALL
that return condition codes 12-37, 14-8
statement) 12-10/12-12
Procedure entry points 10-10 typed
See Functions

HP pTAL Reference Manual—523746-006


Index -17
Index Q

Procedures (continued) Read-only arrays


using hardware indicators address types of 10-10
across 13-14/13-16 constant lists in 8-8
variable 14-7 declaring 8-6/8-7
with RETURN statements 12-34 REAL data type
with two return values D-1/D-3 functions that return values of 14-12
Procedure-parameter routines 15-16 numeric constants of 3-19/3-20
PROCPTRs obtaining
See Procedure pointers with $FLT routine 15-49
PROC(32) address type 14-11 with $FLTR routine 15-50
Program control statements 12-1 parameters of 14-11
pTAL language REAL(32) data type
applications 1-3 See REAL data type
character set for 2-2 REAL(64) data type
compatibility with TAL 1-1 numeric constants of 3-19/3-20
elements of 2-1 obtaining
features of 1-4/1-6 with $EFLT routine 15-37
services for 1-7 with $EFLTR routine 15-38
syntax of Records
See Syntax See Structures
Punctuation characters in syntax Recursion 1-5
diagrams -xxxviii
Redefinitions
PUSHname directive
array 9-55/9-56
See name directive
pointer
P-relative arrays
simple 9-61/9-62
See Read-only arrays
structure 9-63/9-64
rules for 9-53
Q simple variable 9-54/9-55
Quadruplewords 3-1 substructure
Question mark (?) 2-5 definition 9-56/9-59
Quotation mark (") 2-5 referral 9-59/9-60
See also Single quotation mark (’) REFALIGNED clause
with simple equivalenced
R pointers 11-15
READBASELIMIT routine 15-79 with structure pointers 9-27/9-32
READCLOCK routine 15-80 REFALIGNED directive 17-53
READSPT routine 15-80/15-81 Referral structures, declaring
READTIME routine 15-81 equivalenced 11-25/11-26
not equivalenced 9-38/9-39

HP pTAL Reference Manual—523746-006


Index -18
Index S

Referral substructures Rounding (continued)


declaring 9-45 type-conversion routines and 15-13
redefining 9-59/9-60 Routines
Relational operators See also Functions
in conditional expressions 5-18 See also Procedures
signed address-conversion 15-14
in address comparisons 5-11 arithmetic 15-15
operand types for 5-18 built-in 15-1
precedence of 5-4 character-test 15-14
unsigned maximum 15-15
in address comparisons 5-11 minimum 15-15
operand types for 5-19 miscellaneous built-in 15-16/15-17
precedence of 5-4 procedure-parameter 15-16
with INT(32) operands 5-10 pTAL privileged 15-11/15-12
with extended addresses 5-12 type-conversion 15-12/15-13
with nonextended addresses 5-12 variable-characteristic 15-16
Relocatable data blocks RSCAN statement 12-40/12-42
See Global data, blocked Run-time environment directives 17-17
Remainder operator (’\’)
in arithmetic expression 5-5 S
operand types for 5-9 SAVEGLOBALS directive 17-8/17-13,
precedence of 5-3 17-56/17-57
result types for 5-9 SCALE routine 15-82/15-83
with INT(32) and FIXED operands 5-11 Scaling FIXED values
Reserved keywords 2-3 by specifying fpoint 5-7
RESETTOG directive 17-54/17-55 in assignment statements 12-7
RESIDENT procedure attribute 14-5, 14-6 with $SCALE routine 15-82
RETURN statement 12-34/12-40 SCAN statement 12-40/12-42
RETURNSCC procedure attribute SCF user interface
for procedures 14-5, 14-8 attributes of 4-3
for subprocedures 14-19, 14-20 misalignment handling and 4-3
Right-to-left move (=:) 12-28 misalignment tracing facility and 4-1
RISC Scope of declared items 2-10/2-11
See TNS/R architecture Search subvolume (SSV)
ROUND directive 17-55/17-56 command B-9/B-10
ROUND (default) misalignment handling SECTION directive
method 4-3 description of 17-57/17-58
Rounding global data blocks and 16-16
expressions unaffected by 15-13 SOURCE directive and 17-61
ROUND directive and 17-55/17-56 Section names 17-57

HP pTAL Reference Manual—523746-006


Index -19
Index S

Segment Page Table (SPT) SGXWADDR address type (continued)


address of 15-62 pointers of 10-9
copying an entry from 15-80 Shared code
Selector See Position-independent code (PIC)
in labeled CASE statement 12-13 SHARED2 parameter
in unlabeled CASE statement 12-15 description of 9-6, 9-20/9-22
Semicolon (;) FIELDALIGN clause and 9-5/9-6
as delimiter 2-4 SHARED8 parameter
in statements 12-2 description of 9-6, 9-22/9-27
Services FIELDALIGN clause and 9-5/9-6
CRE 1-7 Shifting bits
pTAL 1-7 description of 5-33/5-35
system 1-6 precedence of operators for 5-3
setjmp() instruction 9-1 Short-circuit expression evaluation 5-17
SETTOG directive 17-58/17-59 SIGILL signal (signal #4) 4-3
SGBADDR address type Signed operators
description of 10-6 arithmetic 5-6/5-7
converting 3-9 bit shift 5-3
parameters of 14-11 relational 5-18
pointers of 10-9 Simple pointers
SGBADDR_TO_EXTADDR routine 15-83 description of 10-1
SGBADDR_TO_SGWADDR addresses in 10-17
routine 15-83/15-84 as parameters 14-14
SGWADDR address type declaring
description of 10-6 equivalenced 11-10/11-15
converting 3-9 not equivalenced 10-12/10-14
parameters of 14-11 equivalenced 11-10/11-15
pointers of 10-9 initializing 10-14/10-16
SGWADDR_TO_EXTADDR redefining 9-61/9-62
routine 15-84/15-85
using 9-49/9-50
SGWADDR_TO_SGBADDR routine 15-85
VOLATILE 10-4
SGXBADDR address type
description of 10-6 within structures 9-48/9-49
converting 3-9 Simple variables
as parameters 14-13, 14-14
parameters of 14-11
data type of 15-88
pointers of 10-9
SGXWADDR address type declaring
description of 10-6 equivalenced 11-8/11-10
converting 3-9 not equivalenced 7-1/7-3
parameters of 14-11 equivalenced 11-23/11-24

HP pTAL Reference Manual—523746-006


Index -20
Index S

Simple variables (continued) Statements (continued)


length of compound
in bits 15-28 See Compound statements
in bytes 15-59 null 12-2
redefining 9-54/9-55 role in program 2-12
within structures 9-40 Static T flag 13-1
Single quotation mark (’) 2-5 Stepping pointers 3-10
sINT 15-1 Storage units 3-1
Slash (⁄ ) STRING data type
See Division operator functions that return values of 14-12
Smear operation 12-33, 15-42 numeric constants of 3-14
Source code listing 17-44 parameters of
SOURCE directive actual
description of 17-60/17-64 passed conditionally 15-74
global data blocks and 16-16 passed unconditionally 12-11
NOLIST directive and 17-63 formal
system procedure declarations for procedure pointers 14-27
and 17-63 for procedures 14-3, 14-11,
Source files 14-12
checking syntax of 17-67 for subprocedures 14-11,
compiling 16-2/16-3 14-12, 14-20
listing 17-44 STRUCT data type 14-11, 14-16
Spacing rules in syntax diagrams -xxxix STRUCT keyword
Special expressions 5-20 in structures
SPECIAL routine 15-85/15-86 definition 9-33
SPT 15-62 referral 9-38
SPT (Segment Page Table) template 9-35
address of 15-62 in substructures
copying an entry from 15-80 definition
SQL/MP or SQL/MX in pTAL 1-3 not redefined 9-42
Square brackets ([ ]) 2-4 redefined 9-56
SRL directive 17-65 referral
Stacks, directive not redefined 9-45
See Directive stacks
redefined 9-59
STACK_ALLOCATE routine 15-86/15-87
STRUCTALIGN clause 9-37
Standard functions
STRUCTALIGN (MAXALIGN)
See Built-in routines attribute 9-32, 9-36
Statements Structure items
categories of 12-1 arrays 9-40
filler bits or bytes 9-46/9-47

HP pTAL Reference Manual—523746-006


Index -21
Index S

Structure items (continued) Structures


offsets of declaring (continued)
in bits 15-29 template 9-35/9-38
in bytes 15-71 items within
pointers See Structure items
simple 9-48/9-49 layout of 9-3/9-5
structure 9-51/9-53 length of
procedure pointers as 14-26 in bits 15-28
simple variables 9-40 in bytes 15-59
substructures maximum nesting levels in 9-3
definition 9-42/9-44 number of occurrences of 15-69
referral 9-45/9-46 redefining 9-53
Structure pointers Sublocal declarations 14-21
description of 10-1 Sublocal scope 2-10
addresses in 10-17 SUBPROC keyword 14-19
as parameters 14-14 Subprocedure entry points 10-10
declaring 10-16/10-17 Subprocedures
initializing 10-17/10-19 See also Functions
redefining 9-63/9-64 address types of 10-10
reference alignment with 9-27/9-32 bodies of 14-21/14-22
VOLATILE 10-5 declaring 14-19/14-21
within structures 9-51/9-53 description of 14-1
Structures formal parameter specification
description of 9-1 in 14-10/14-15
FORWARD declaration of 14-21
alignment of
description of 1-4
description of 9-4/9-5
arrays in 9-13/9-15 sublocal declarations in 14-21
that return condition codes 14-20
base 9-9
variable 14-20
fields of 9-5/9-13
with RETURN statements 12-34
in depth 9-15
Substructures
as parameters 14-13, 14-14, 14-16
alignment of 9-16/9-19
data type of 15-88
data type of 15-88
declaring
declaring
definition
definition 9-42/9-44
equivalenced 11-24/11-25
referral 9-45/9-46
not equivalenced 9-33/9-35
length of
referral
in bits 15-28
equivalenced 11-25/11-26
in bytes 15-59
not equivalenced 9-38/9-39
number of elements of 15-69
HP pTAL Reference Manual—523746-006
Index -22
Index T

Substructures (continued)
redefining
T
TACL commands
definition 9-56/9-59
See HP TACL commands
referral 9-59/9-60
TACL DEFINE tool 18-7
Subsystem Control Facility
TAL
See SCF user interface
compatibility with pTAL 1-1
Subtraction operator
procedures that return two values D-1
signed (-)
TARGET directive 17-68/17-69
in arithmetic expression 5-5
Target file option 16-6
operand types for 5-6
Template structures, declaring 9-35/9-38
precedence of 5-3
Temporary files B-7
unsigned (’-’) Temporary variables
in arithmetic expression 5-5 creating 12-45
operand types for 5-8 dropping 12-20
precedence of 5-3 THEN keyword 12-26
result types for 5-9 TNS architecture RVUs 1-2
with INT(32) operands 5-11 TNSMISALIGN attribute (SCF) 4-3
Subvolume names B-3 TNS/E architecture RVUs 1-2
SUPPRESS directive 17-65/17-66 TNS/R architecture RVUs 1-2
Swap volume B-7 TNS/R native mode 4-3
SWAPVOL command B-7 TO keyword 12-20
SYMBOLS directive 17-66/17-67 Toggles
Symbols, base address 2-7 description of 17-5
Syntax turning off 17-54
checking 17-67/17-68 turning on 17-58
conventions for -xxxvii/-xl Tracing facility 4-1/4-2
summary of A-1/A-119 Transfer Tool 18-7
SYNTAX directive 17-67/17-68 Traps, managing
System clock setting 15-80 generally 13-1/13-3
System global data GOTO statement and 12-24/12-25
See also Global data TRIGGER routine 15-88
declaring TYPE routine 15-88/15-89
equivalenced 11-22/11-29 Typed procedures
pointers 10-20 See Functions
pointers to 10-9 Type-conversion routines 15-12/15-13
System names B-2
System procedures U
description of 1-7
UDBL routine 15-89/15-90
SOURCE directive and 17-63
UDIVREM16 routine 15-90/15-91
System services 1-6 UDIVREM32 routine 15-91/15-92
HP pTAL Reference Manual—523746-006
Index -23
Index V

uINT 15-1 Variables (continued)


Unlabeled CASE statement 12-15/12-17 types of 2-10
UNLOCKPAGE routine 15-93 Variable-characteristic routines 15-16
UNSIGNED data type VARIABLE-to-EXTENSIBLE procedure
functions that return values of 14-12 conversions 14-7
parameters of 14-11 Visual Studio .NET 18-2
Unsigned operators VOLATILE pointers
arithmetic 5-8/5-11 simple 10-4
bit shift 5-3 structure 10-5
relational 5-19 VOLATILE procedure attribute 9-33
UNSPECIFIED procedure attribute 14-5 Volume names B-3
UNTIL keyword
in DO statement 12-17 W
in RSCAN statement 12-40 WADDR address type
in SCAN statement 12-40 description of 10-6
USE statement 12-45 converting 3-9
USEGLOBALS directive parameters of 14-11
description of 17-69/17-70 pointers of 10-9
SAVEGLOBALS and WADDR_TO_BADDR routine 15-93/15-94
BEGINCOMPILATION and 17-8/17-13 WADDR_TO_EXTADDR routine 15-94
SOURCE directive and 17-63 WARN directive 17-71/17-72
User library 17-65 Warning messages 17-71/17-72
WHILE keyword
V in RSCAN statement 12-40
VARIABLE procedure attribute in SCAN statement 12-40
for procedures 14-5, 14-7 in WHILE statement 12-45
for subprocedures 14-19, 14-20 WHILE statement
Variables description of 12-45/12-46
description of 2-10 hardware indicators in 13-8
equivalenced Words 3-1
See Equivalenced variables WRITEPTE routine 15-95
FIXED 5-8
procedure pointers as 14-26 X
scope of 2-10/2-11 XADR routine 15-96
simple XOR operator
See Simple variables in arithmetic expression 5-5
storing data addresses in 3-7 operand types for 5-10
temporary precedence of 5-3
creating 12-45 with INT(32) operands 5-10
dropping 12-20
HP pTAL Reference Manual—523746-006
Index -24
Index Z

Z $EFLT routine 15-37


$EFLTR routine 15-38, 15-38/15-39
ZZBInnnn target file 16-6 $EXCHANGE routine 15-39
$EXECUTEIO routine 15-40/15-41
Special Characters $EXTADDR_TO_BADDR routine 15-41
! (exclamation mark) 2-4 $EXTADDR_TO_WADDR routine 15-42
" (quotation mark) 2-5 $FILL16 procedure 15-42/15-43
# (hash mark or pound sign) 2-5 $FILL32 procedure 15-42/15-43
$ (dollar sign) 2-5 $FILL8 procedure 15-42/15-43
$ABS routine 15-22/15-23 $FIX routine 15-44
$ALPHA routine 15-23/15-24 $FIXD routine 15-44/15-45
$ASCIITOFIXED routine 15-24/15-25 $FIXEDTOASCII routine 15-45/15-46
$ATOMIC_ routines 4-1, 4-3 $FIXEDTOASCIIRESIDUE
routine 15-46/15-47
$ATOMIC_ADD routine 15-5
$FIXI routine 15-47/15-48
$ATOMIC_AND routine 15-6
$FIXL routine 15-48
$ATOMIC_DEP routine 15-7/15-8
$FIXR routine 15-48/15-49
$ATOMIC_GET routine 15-8
$FLT routine 15-49/15-50
$ATOMIC_OR routine 15-9
$FLTR routine 15-50
$ATOMIC_PUT routine 15-10
$FREEZE routine 15-51
$AXADR routine 15-26
$HALT routine 15-51
$BADDR_TO_EXTADDR
routine 15-26/15-27 $HIGH routine 15-52
$BADDR_TO_WADDR routine 15-27 $IFIX routine 15-52/15-53
$BITLENGTH routine 15-28 $INT routine 15-53/15-54
$BITOFFSET routine 15-29 $INTERROGATEHIO routine 15-55/15-56
$CARRY routine $INTERROGATEIO routine 15-57/15-58
description of 15-30 $INTR routine 15-58/15-59
after assignments 13-4 $INT_OV routine 15-54/15-55
atomic operation that can set 15-4 $LEN routine 15-59/15-60
$LFIX routine 15-60/15-61
in nested IF statements 13-12/13-13
$LMAX routine 15-61
nonatomic operations that can
set 15-20/15-22 $LMIN routine 15-61/15-62
$LOCATESPTHDR routine 15-62/15-63
returning its value to calling
procedure 13-16 $LOCKPAGE routine 15-63/15-64
$CHECKSUM routine 15-31/15-32 $MAX routine 15-64
$COMP routine 15-32 $MIN routine 15-64/15-65
$COUNTDUPS routine 15-33/15-34 $MOVEANDCXSUMBYTES
routine 15-65/15-66
$DBL routine 15-34/15-35
$MOVENONDUP routine 15-67/15-68
$DBLL routine 15-35
$NUMERIC routine 15-68
$DBLR routine 15-36
$OCCURS routine 15-69/15-71
$DFIX routine 15-36/15-37

HP pTAL Reference Manual—523746-006


Index -25
Index Special Characters

$OFFSET routine & (concatenation operator) 12-30


description of 15-71/15-73 *
structure pointers and 10-18 See Asterisk (*)
$OPTIONAL routine 15-73/15-76 +
$OVERFLOW routine See Plus sign (+)
description of 15-76/15-77 -
after assignments 13-3/13-4 See Hyphen (-)
atomic operation that can set 15-4 See Minus sign (-)
built-in routines and 15-4 ->
in nested IF statements 13-12/13-13 in labeled CASE statement 12-13
nonatomic operations that can in move statement 12-28
set 15-17/15-22 in RSCAN statement 12-40
returning its value to calling in SCAN statement 12-40
procedure 13-16 .
$PARAM routine 15-77 See Period (.)
$POINT routine 15-78 .EXT
$PROCADDR routine 15-78/15-79 in equivalenced variables 11-24
$READBASELIMIT routine 15-79 in formal parameters 14-10, 14-13
$READCLOCK routine 15-80 in pointers
$READSPT routine 15-80/15-81
procedure 14-28
$READTIME routine 15-81
simple 10-12
$SCALE routine 15-82/15-83
structure 10-16
$SGBADDR_TO_EXTADDR routine 15-83
in referral structures 9-38
$SGBADDR_TO_SGWADDR
routine 15-83/15-84 .SG
$SGWADDR_TO_EXTADDR in formal parameters 14-13
routine 15-84/15-85 in procedure pointers 14-28
$SGWADDR_TO_SGBADDR in system global pointers 10-20
routine 15-85
.SGX
$SPECIAL routine 15-85/15-86
in formal parameters 14-13
$STACK_ALLOCATE routine 15-86/15-87
in procedure pointers 14-28
$TRIGGER routine 15-88
.tal file extension 18-1
$TYPE routine 15-88/15-89
... (ellipsis) 12-13
$UDBL routine 15-89/15-90
: (colon) 14-23
$UDIVREM16 routine 15-90/15-91
:=
$UDIVREM32 routine 15-91/15-92
assignment operator 5-4
$UNLOCKPAGE routine 15-93
See also Assignments
$WADDR_TO_BADDR
routine 15-93/15-94 left-to-right move 12-28
$WADDR_TO_EXTADDR routine 15-94 ; (semicolon)
$WRITEPTE routine 15-95 as delimiter 2-4
$XADR routine 15-96 in statements 12-2

HP pTAL Reference Manual—523746-006


Index -26
Index Special Characters

< ’-’
See Less than operator, signed (<) See Subtraction operator, unsigned (’-’)
< > (angle brackets) 2-4 ’<<’ (unsigned left bit shift) 5-3
<...> (bit extraction) 5-3 ’<=’
<...> := (bit deposit operator) 5-4 See Less than or equal operator,
<< (signed left bit shift) 5-3 unsigned (’<=’)
<= ’<>’
See Less than or equal operator, signed See Not equal operator, unsigned (’<>’)
(<=) ’<’
<> See Less than operator, unsigned (’<’)
See Not equal operator, signed (<>) ’=’
= See Equal sign, as equal operator,
See Equal sign unsigned
=: (right-to-left move) 12-28 ’>=’
> See Greater than or equal operator,
See Greater than operator, signed (>) unsigned (’>=’)
>= ’>>’ (unsigned right bit shift) 5-3
See Greater than or equal operator, ’>’
signed (>=) See Greater than operator, unsigned
>> (signed right bit shift) 5-3 (’>’)
? (question mark) 2-5 ’\’
@ operator See Remainder operator (’\’)
in entry-point identifiers ’⁄ ’
for procedures 14-23 See Division operator, unsigned (’⁄ ’)
for subprocedures 14-24 ⁄
in pointers 10-14 See Division operator, signed (⁄ )
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 (’+’)

HP pTAL Reference Manual—523746-006


Index -27
Index Special Characters

HP pTAL Reference Manual—523746-006


Index -28

You might also like