3.0 PHASE 2 - Code Generation
3.1.2 Integer and Scalar Operations Nomenclature
The register R is any of the available set of accumulators. The terms I, I2, S, and S2 refer to the single and double precision versions of Integer and Scalar values
respectively. It is assumed that any implicit precision or type conversions have been accomplished prior to generating the code sequences shown below.
3.1.2.1 Arithmetic Operators
Integer and scalar arithmetic operators generally employ two operands, denoted as X and Y. X is assumed to be loaded into register Rx unless otherwise noted. If Y is also in a register, it is represented by the form Ry.
Note that the shift operations used in the integer multiplications are required to correctly normalize the result in the proper registers
Certain constant multipliers are optimized to avoid using actual multiply instructions.
They are described below.
Operation Type Code Alternate Code
X + Y: I AH Rx,Y AHI Rx,Y†
† Used if Y is a literal.
I2 A Rx,Y AR Rx,Ry S AE Rx,Y AER Rx,Ry S2 AED Rx,Y AEDR Rx,Ry
X- Y: Similar to X + Y except that the subtract operator is used (For example, SH in place of AH in the above list).
(Multiply)
Operation Type Code Alternate Code
I 2n SLL RI,n,n>1
X**Y: The exponentiation is performed by subroutine. The patterns shown for I and S are identical to those which will be generated for I2 and S2, except for the obvious differences:
The DED and DEDR instructions are broken on the AP-101S machine. Thus, the compiler emits the following code sequences in place of these instructions:
Operation Type Code Alternate Code
X/Y S2 LER Ra+1,Rx+1 LER Ra+1,Rx+1 LER Ra,Rx LER Ra,Rx DE RX,Y DER RX,Ry LER Rb+1,Rx+1 LER Rb+1,Rx+1 LER Rb,Rx LER Rb,Rx MED Rb,Y MEDR Rb,Ry SEDR Rb,Ra SEDR Rb,Ra DE Rb,Y DER Rb,Ry SEDR RX,Rb SEDR RX,Rb where the result resides in the Rx,Rx+1 register pair.
In the special case where a double precision result is divided by itself, a double precision "1" is loaded directly into the result register rather than executing the DED/DEDR workaround sequence. The code sequence for this case is:
Operation Type Code
X/X S2 LFLI Rx,1 LFLI Rx+1,0
where the result resides in the Rx,Rx+1 register pair.
I**I LH 5,X ⎫
CVFL 0,5* ⎪
LH 6,Y ⎪
S**I LH 6,Y (see note) ⎬ Argument Setup
LE 0,X ⎪
S**S LE 2,Y ⎪
LE 0,X ⎭
ACALL αPWRβ } Actual Call
where α and β represent the types of operands X and Y respectively:
Return is in F0 for α of E or D; in R5 for α of H or I.
* if Y operand is a positive integer literal, the CVFL conversion is eliminated and the PWR routine invoked is αPWRH or αPWRI.
Note: Scalar expressions raised to integer literal powers from 1 to 16 are performed in line via repeated multiplication, using the binary powers algorithm. The following examples should serve to illustrate the method.
For type S2, the instruction MEDR is used in place of MER. Two LERs must be used in place of one.
3.1.2.2 Comparison Operators
The full complement of relational operators is allowed for Integer or Scalar operations between single quantities. Only equal or not equal operators are allowed for arrayed comparisons. No logical variables are created by comparisons. Instead, branching to one of two points is used for true/false relations.
Type of X α Type of Y β
Single precision integer ⎫ single precision integer H double precision integer ⎬ E double precision integer I single precision scalar ⎭ single precision scalar E double precision scalar D double precision scalar D single precision integer H*
double precision integer I*
Operation Type Code Alternate Code
X**1: No code generated.
X**2: S MER Rx,Rx X**3: S LER RT,Rx MER Rx,Rx MER RT,Rx (result in RT) X**6: S MER Rx,Rx
LER RT,Rx MER Rx,Rx MER RT,Tx (result in RT)
Operation Type Code
+X No code generated
-X I,I2 LACR Rx,Rx S LECR Rx,Rx S2 LED Rx,X
LECR Rx,Rx
Note: For comparisons to the literal 0, the condition code is used directly. If the condition code is not valid, the instruction LR or LER is used to set it.
3.1.2.3 Conversions
Where necessary, conversions are performed in intrinsic or library functions. Some conversions do not require any generation of code.
Integer Conversions
Operation Type Code Alternate Code
X <OP> Y: I CH Rx,Y
BC COND,not-true-label
I2 C Rx,Y CR Rx,Ry
BC COND,not-true-label
S CE Rx,Ry CER Rx,Ry
BC COND,not-true-label
S2 SED Rx,Y SEDR Rx,Ry BC COND,not-true-label
Operation Code
I TO S LH Rx,X
CVFL Fx,Rx I TO S2 LH Rx,X
CVFL Fx,Rx SER Fx+1,Fx+1
I2 TO S L 5,X
ACALL ITOE I2 TO S2 L 5,X
ACALL ITOD
I,I2 TO BIT No code necessary I TO CHAR LH 5,X
LA 2,temp-string-area†
† temp-string-area contains converted string.
ACALL HTOC I2 TO CHAR L 5,X
LA 2,temp-string-area† ACALL ITOC
I TO I2 SRA Rx,16 I2 TO I SLL Rx,16
Scalar Conversions
3.1.2.4 Assignments
For all assignments, type conversion may take place across the assignment operator.
For multiple assignments, the left hand side operands are grouped by data type to minimize the number of conversions performed. The order in which the groups are processed is determined by the following table:
Right Hand Operand Type
Type Ordering I I2 S S2
Character is always performed before any right hand side conversion is performed.
Operation Code Alternate Code
S TO I,I2 LE 0,X LER 0,Rx ACALL αTOβ
S2 TO I,I2 LED 0,X LEDR 0,Rx ACALL αTOβ
TYPE OF SCALAR α TYPE OF INTEGER β
Single Precision E Single Precision H
Double Precision D Double Precision I
S,S2 TO BIT Same as for scalar to integer S TO CHAR LE 0,X
LA 2,temp-string-area†
† temp-string-area contains converted string.
ACALL ETOC S2 TO CHAR LED 0,X
LA 2,temp-string-area† ACALL DTOC
S TO S2 LE Rx,X SER Rx+1,Rx+1
Left Hand
First I I2 S S2
I2 Char Char Char Char S2 S2 S
S2 S I2 I2
S I I I
Last Vector-Matrix
The following sequences assume that Rx has already had the required integer or scalar conversions performed as described in Section 3.1.2.3.
Rx is also marked as now containing the value Y. Subsequent usages of Y may use this register in lieu of the copy of Y in memory until such time as the contents of this register are destroyed or a label is generated.
3.1.3 Bit String Operations