COBOL Manual for TNS and TNS/R Programs

Migrating TNS Programs to Native Programs
HP COBOL Manual for TNS and TNS/R Programs522555-006
33-12
Causes of Misalignment in HP COBOL Programs
The compiler’s PORT directive avoids misaligned address problems by inserting extra
run-time code that copies all potentially misaligned operands to aligned temporary data
items before using them.
The PORT directive also removes “implicit” filler bytes from records, aligning BINARY
or COMPUTATIONAL data items on any byte, except where the SYNCHRONIZED
clause appears. The SYNCHRONIZED clause aligns BINARY and COMPUTATIONAL
data items on 2-byte boundaries.
Because it changes the default record layout, the PORT directive must be applied to
either all or none of the modules and programs of all the compilation units of a single
program (that is, the run unit) and to all other run units with which it shares data
records.
Subprogram:
IDENTIFICATION DIVISION.
PROGRAM-ID. PROG-2.
DATA DIVISION.
LINKAGE SECTION.
* Prog-2's reference parameter is a 16-bit-word-aligned group
* containing 1-word, 2-word, and 4-word binary numeric items:
01 indirect-group.
05 v16 PIC S9(4) COMP.
05 v32 PIC s9(9) COMP.
05 v64 PIC S9(18) COMP.
PROCEDURE DIVISION USING indirect-group.
main.
* This subprogram expects its "indirect-group" parameter to begin
* at an even-byte memory location, allowing use of TNS instructions
* for loading or storing binary numbers.
MOVE 16 to v16.
MOVE 32 to v32.
MOVE 64 to v64.
* References to v16 and v64 misbehave if caller passes an
* alphanumeric string beginning at an odd-byte memory location.
* On TNS/R but not TNS, references to v32 usually behave as expected
* even when an incorrect odd address is given.
END PROGRAM PROG-2.
Note. This extra run-time code can slow down the program significantly.
Example 33-1. Misalignment (page 2 of 2)