pTAL Conversion Guide

Bit Operations
pTAL Conversion Guide527302-002
14-3
pTAL
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 behavior is undefined.
pTAL does not support signed left shifts. You can specify the same shift operations as
in TAL, but pTAL compiles a signed left shift (for example, I << 8) as an unsigned left
shift ('<<') because native instructions do not include a signed left-shift operation.
Most programs do not need to perform signed left shifts. If your program does need to
do so, use the routines in Example 14-2 on page 14-3 to perform signed left-shift
operations in both TNS and native processes.
Example 14-2. Signed Left-Shift Routines for TNS and Native Programs
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;