ASSIGN OPERATOR: "E97" BRICKS

Back to:
index Intel
I called bricks the short pieces of code, that "COMPAS" generate as a part of operator. Compiler builds result machine code from the bricks.

Step 1 (extract first operand to R1)

Step 2 (do operation or calculate function)

Step 3 (save result from R1)

Examples of full operator


Assign operator: step 1 (extract first operand to R1)

Extract simple variable (e.g. a) or variable with concrete index (e.g. b[2]) to R1 (assume, that variable address is 90):
INTEGER type
01E1 (90) ==> R1
0090
CHAR or BOOLEAN
81E1 (90)b ==> R1
0090

Extract index variable (e.g. b[i]) to R1 (assume, that i address is 90 and b[0] address is D0):
INTEGER type,
INTEGER index
01E2 (90) ==> R2
0090 i
0EA2 shift R2 (*2)
01D1 D0 ==> R1
00D0 b[0] address
0221 R1 + R2 ==> R1
0151 (R1) ==> R1
INTEGER type,
CHAR index
81E2 (90)b ==> R2
0090 i
0EA2 shift R2 (*2)
01D1 D0 ==> R1
00D0 b[0] address
0221 R1 + R2 ==> R1
0151 (R1) ==> R1
CHAR type,
INTERGER index
01E2 (90) ==> R2
0090 i

01D1 D0 ==> R1
00D0 b[0] address
0221 R1 + R2 ==> R1
8151 (R1)b ==> R1
Red color is used to show the effect of index type, blue - array elements type.

Extract constant >15 to R1 (assume, that constant is 40):
INTEGER type
01D1 40 ==> R1
0040
CHAR or BOOLEAN
81D1 40b ==> R1
0040

Extract constant <=15 to R1 (assume, that constant is 0):
INTEGER type
2101 0 ==> R1
BOOLEAN
A101 FALSE ==> R1



Back to:
index top Intel

Assign operator: step 2 (do operation or calculate function)

Add simple variable (e.g. a) or variable with concrete index (e.g. b[2]) to R1 (assume, that variable address is 90):
02E1 R1 + (90) ==> R1
0090

Add index variable (e.g. b[i]) to R1 (assume, that i address is 90 and b[0] address is D0):
01E2 (90) ==> R2
0090 i
0EA2 shift R2 (*2)
02D2 R2 + D0 ==> R2
00D0 b[0] address
0261 R1 + (R2) ==> R1

Add constant >15 to R1 (assume, that constant is 40):
02D1 R1 + 40 ==> R1
0040

Add constant <=15 to R1 (assume, that constant is 1010=A16):
22A1 R1 +10 ==> R1

Different operations with simple variable (assume, that variable address is 90):
INTEGER operationsBOOLEAN operations
02E1 R1 + (90) ==> R1
0090
C7E1 R1 AND (90) ==> R1
0090
E711 R1 AND 1 ==> R1 (low bit extract)
03E1 R1 - (90) ==> R1
0090
C8E1 R1 OR (90) ==> R1
0090
E711 R1 AND 1 ==> R1 (low bit extract)
05E1 R1 * (90) ==> R1
0090
C9E1 R1 XOR (90) ==> R1
0090
E711 R1 AND 1 ==> R1 (low bit extract)
06E1 R1 DIV (90) ==> R1
0090
01E2 (92) ==> R2
0092
9C0D call subroutine MOD
4000 from ROM address 4000
0121 R2 ==> R1 (result to R1)

Calculation of functions:
INTEGER typeCHAR typeBOOLEAN type
0511 SQR( ): R1 * R1 2211 SUCC( ): R1 + 1 ==>R1 0E11 NOT R1
C711 extract low bit
9C0D ABS( ): call subroutine
4010 from ROM address 4010
2311 PRED( ): R1 - 1 ==>R1
Functions CHR( ) and ORD( ) need no special " E97" code: just on step 1 we read INTEGER data (2-byte word) and on step 3 save byte and vice versa.



Back to:
index top Intel

Assign operator: step 3 (save result from R1)

Save simple variable (e.g. a) or variable with concrete index (e.g. b[2]) to R1 (assume, that variable address is 90):
INTEGER type
011E R1 ==> (90)
0090
CHAR or BOOLEAN
811E R1 ==> (90)b
0090

Save index variable (e.g. b[i]) to R1 (assume, that i address is 90 and b[0] address is D0; i and b have INTEGER type):
Step 1
01E2 (90) ==> R2
0090 i
0EA2 shift R2 (*2)
01D3 D0 ==> R3
00D0 b[0] address
0223 R3 + R2 ==> R3
Here we prepare b[i] address in R3
Step 2
...
Step 3
0117 R1 ==> (R3)
And now save R1, using R3



Back to:
index top Intel

Examples of full operators

1. i := i + k (DE - address of variable i, DC - k)
01E1
00DE
(DE) ==> R1 Extract i
02E1
00DC
R1 + (DC) ==> R1 i + k
011E
00DE
R1 ==> (DE) Save i

2. k := SQR(i)
01E1
00DE
(DE) ==> R1 Extract i
0511
R1 * R1 ==> R1 SQR(i)
011E
00DC
R1 ==> (DC) Save k

3. a[i] := b[i] + a[k]
01E2 (DE) ==> R2
00DE i
0EA2 shift R2 (*2)
01D3 C6 ==> R3
00C6 a[0] address
0223 R3 + R2 => R3
Step 1:
Prepare a[i] address in R3
01D1 B2 ==> R1
00B2 b[0] address
0221 R1 + R2 ==> R1
Prepare b[i] address in R1
(using R2 above value)
0151 (R1) ==> R1
Extract b[i] to R1
01E2 (DC) ==> R2
00DC k
0EA2 shift R2 (*2)
02D2 R2 + C6 ==> R2
00C6 a[0] address
Step 2:
Prepare a[k] address in R2
0261 R1 + (R2)
b[i] + a[k]
0117 R1 ==> (R3)
Step 3: result ==> a[i]



Back to:
index top Intel