pTAL Conversion Guide

Expressions
pTAL Conversion Guide527302-002
13-3
Guaranteeing 16-Bit Results
Guaranteeing 16-Bit Results
The native compiler generates extra instructions that ensure that 16-bit operators
generate 16-bit results, except in these cases:
The result of the +, -, *, /, and << operators is undefined if the result has more than
16 bits.
The result of the +, -, *, and /operators is undefined in native processes if the same
operator with the same operands produces overflow in TNS processes.
The result of the << operator in native processes is undefined if the result of
shifting the same operands in TNS processes is undefined (that is, those operands
that cause the result to lose significant bits).
The result of the shift operator in the following example is undefined because the result
of the shift is 0, and a significant bit is lost:
INT i;
i := %H4000;
i := i << 1;
The result of executing the preceding sequence depends on the compiler you use and
the environment in which you run your program:
TAL programs that use the result of 16-bit operators after an overflow occurs are not
compatible with pTAL.
In Example 13-4 on page 13-4, which assumes that overflow traps are disabled:
Example 13-3. Overflow
INT i := 32767;
INT j;
j := i + 1;
IF j < 0 THEN ...
Compiler Result
TAL %H8000 = -32768
Accelerator %H8000 = -32768
pTAL %H8000 = +32768
TNS Native
i=%H8000 TRUE
(Overflow is ignored and
32767+1=%H8000, which is the
value of the constant.)
FALSE
[pTAL sign-extends the constant
value %H8000 to produce a 32-bit
operand. i+32768 is not equal to the
sign-extended constant
%HFFFF8000 (-32768).]