pTAL Conversion Guide

pTAL Built-In Routines
pTAL Conversion Guide527302-002
18-50
$UDIVREM16
quotient output
sINT:variable
remainder output
sINT:variable
If the quotient is too large to fit in quotient, overflow occurs.
pTAL checks the following conditions during compilation:
If divisor evaluates to a constant value of zero, pTAL reports an error that divide
by zero is invalid:
$UDIVREM16(dividend, 2 / 2 - 1, quot, rem); ! Report error
If both dividend and divisor evaluate to constant values whose unsigned
quotient is greater than 16 bits, pTAL 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, pTAL reports a warning that overflow cannot
occur:
$UDIVREM16(32767, 256, quot, rem);
IF $OVERFLOW THEN ... ! Report warning
If pTAL 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
Figure 18-21. TAL Code Equivalent to $UDIVREM16 Routine
STACK dividend, divisor;
CODE(LDIV);
STORE quotient, remainder;
Example 18-36. Call to $UDIVREM16 Routine
INT(32) dividend;
INT divisor;
INT quotient;
INT remainder;
$UDIVREM16(dividend, divisor, quotient, remainder);