pTAL Conversion Guide

Hardware Indicators
pTAL Conversion Guide527302-002
20-13
Overflow Traps Considerations
Your program might trap at slightly different locations for TNS processes than for
native processes, even if the program’s trapping state—enabled or disabled—is
the same for both processes.
For a native process, overflow is detected in a pTAL program only when the
expression on the right side of an assignment statement is assigned to the
destination on the left side. A 16-bit overflow that occurs in the middle of
expression evaluation in a TNS process might not be detected in a native process
until the assignment is made. If the expression includes a call, for example, to a
routine that updates a disk file, the result of the two programs could be very
different if overflow is detected before the routine call in a TNS process but after
the routine call in a native process.
For a native process, a 32-bit overflow always causes a trap at the instruction
which causes the overflow.
If overflow traps are disabled when a trap occurs, the result of the operation on
which the overflow occurred might be different for TNS processes than for native
processes.
Overflow can also be detected when an actual parameter is assigned to its
corresponding formal parameter during a procedure call. In this case, your
program always traps to the current trap handler, if traps are enabled; the result is
undefined if traps are disabled. Your program cannot detect this overflow condition
and the results of all subsequent operations are undefined.
An overflow that a TNS process detects during expression evaluation might not be
detected at all by a native process because:
°
For a native process, pTAL performs 16-bit arithmetic in 32-bit registers.
°
The code generated by the native compiler does not generally check for 16-bit
overflow until the value on the right side of an assignment statement is
assigned to the destination on the left side.
In the Example 20-5 on page 20-13, overflow traps are disabled and the operands are
all 16-bit integers. For a TNS process, adding 1 to a in the assignment statement
causes overflow and the program traps immediately.
If you compile Example 20-5 on page 20-13 by using a native compiler and run the
example as a native process, overflow is not detected because the result of adding a
and 1 is 32768, which is maintained in a 32-bit register. The result of subtracting b
(1000) from 32768 is 31768, which is stored into a with no overflow detected.
Example 20-5. Overflow Traps (TAL Only)
PROC p;
BEGIN
INT a := 32767;
INT b := 1000;
a := a + 1 - b; ! Overflow is detected by a TNS process,
END; ! but not by a native process