Assignment Statement [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation
SPL to HP C/XL Migration Guide
Assignment Statement
Table 5-28. Assignment Statement
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| assignment-statement: | assignment-statement: |
| 1. variable | 1. variable |
| [:= variable][...] := expression | [= variable][...] = expression ; |
| 2. variable ( left-bit : len ) | 2. (No direct equivalent; |
| [:= variable][...] := expression | see BDEPOSIT function below.) |
| | Note: The HP C/XL assignment operator, "=",|
| | is the same as the SPL equality operator. |
| | |
---------------------------------------------------------------------------------------------
| | |
| The type of expression may be different from| The types of the variables and expression |
| the the types of the variables and they may | may all be different. They do not have to h|ve
| be different from each other, except they mu|tthe same length. HP C/XL performs automatic|
| all be the same length. Type BYTE is treate| type conversions as assignment proceeds from|
| as a 16-bit quantity. | right to left. |
| | |
---------------------------------------------------------------------------------------------
| | |
| The leftmost assigned-to variable may specif| Bit-field assignment is not allowed. |
| a bit field in itself where the value will b| This operation may be performed separately w|th
| deposited. | the user-defined function BDEPOSIT, |
| | described below. |
| | |
---------------------------------------------------------------------------------------------
| | |
| May be used as an expression. | Same as SPL. |
| Its value is the value stored into the | |
| leftmost operand. Its type is the type of | |
| the leftmost operand. | |
| | |
---------------------------------------------------------------------------------------------
For compatability with very old systems, SPL accepts the "_" (underscore)
character as an alternate to the ":=" assignment symbol. (Early
terminals and printers labeled and displayed what now is the underscore
as a "left arrow" symbol, "<--".)
SPL Examples:
Z := B * F;
arithmetic expression assignment
F1 := F2 = F3;
logical expression assignment
Z.(5:6) := P := B;
multiple assignment, bit deposit
Z := (B := B + 1) * 2;
assignment in expression
Z _ B;
underscore replacing ":="
HP C/XL Examples:
i = k * l; /*arithmetic expression assignment*/
l1 = l2 == l3; /*logical expression assignment*/
i = (k = k + 1) * 2; /*assignment in expression*/
i = (++k) * 2; /*same operation*/
The SPL bit deposit operation may be emulated in SPL and converted to HP
C/XL in two steps.
Step 1: In SPL, add the BDEPOSIT procedure in Figure 5-19 to the
compilation unit.
_________________________________________________________
| |
| PROCEDURE BDEPOSIT(dw,sb,nb,expr); |
| VALUE dw, sb, nb, expr; |
| LOGICAL dw, sb, nb, expr; |
| BEGIN |
| LOGICAL M; |
| POINTER P; |
| nb := 16-nb; |
| sb := nb-sb; |
| M := (%(16)FFFF & LSR(nb)) & LSL(sb); |
| @p := dw; |
| p := (p LAND NOT m) LOR (expr & LSL(sb) LAND m);|
| END; |
_________________________________________________________
Figure 5-19. SPL BDEPOSIT Procedure: Bit Assignment
Here dw is the address of the destination word, sb is the starting bit of
the deposit field, nb is the number of bits to be deposited, and expr is
the value to be deposited into the field.
Then separate the bit deposit from any multiple assignments and convert
it to a procedure call. For example,
I.(5:6) := J + K ;
would become
BDEPOSIT(@I,5,6,J+K);
Note that the address of the first parameter is formed with the "@"
operator, and that the parameter has been declared type LOGICAL (16 bit
word), and passed by value. Within BDEPOSIT, this value is assigned to a
pointer to allow the actual value to be accessed. This rather
unconventional approach (normal SPL practice would be to pass this
parameter by reference), is to simplify later conversion to the HP C/XL
function described below.
Step 2: In HP C/XL, replace the SPL procedure with the HP C/XL BDEPOSIT
function shown in Figure 5-20.
___________________________________________
| |
| void BDEPOSIT(dw,sb,nb,exp) |
| unsigned short *dw, sb, nb, exp; |
| { |
| unsigned short m; |
| nb = 16-nb; |
| sb = nb-sb; |
| m = (0xFFFF>>nb)<<sb; |
| *dw = (*dw & ~m) | (exp<<sb & m);|
| } |
___________________________________________
Figure 5-20. HP C/XL BDEPOSIT Function: Bit Assignment
Then replace the converted SPL call to BDEPOSIT:
BDEPOSIT(@I,5,6,J+K);
with:
BDEPOSIT(&I,5,6,J+K);
Note that the only difference in the calls is that "@" is changed to "&".
MPE/iX 5.0 Documentation