Condition analysis is similar to assign operator.
It's also divided on two parts by several signs of relation: >, <, =, >=, <=, <>.
"COMPAS" extracts both operands from the left and right parts of condition and then compares
them. A conditional jump always follows this instruction. Note, that compiler uses jump
condition, opposite to written in Pascal text - such logic is better agree with
language constructions.
"COMPAS" always control the fact, that types of left and right parts must be identical.
There is a special situation, when BOOLEAN variable is used as a condition:
IF b THEN ...
In this case "COMPAS" compares BOOLEAN value with zero (0 - FALSE, 1 - TRUE).
Condition is analysed in three steps:
extract first operand
compare it with the second
do conditional jump, if result is FALSE.
Examples and condition structure
1 step: get first operand
2 step: compare with the second operand
3 step: conditional jump
"E97" code bricks
Intel code bricks
I called bricks the short pieces of code,
that "COMPAS" generate as a part of operator. Compiler builds result machine
code from the bricks.
Examples and condition structure
Examples of typical conditions, available in "COMPAS", are exemplified below.
- a = 10
- 1 = a
- a = b
- a <> b
- a >= b
- a <= b
- a > b
- a < b
All variables can have indexes.
BOOLEAN value can be written as a condition.
The structure of condition:
{variable or constant} {relation sign} {variable or constant}
{BOOLEAN variable or constant}
Back to:
Step 2: compare with the second operand
In "E97" and in Intel compilers this step is realized slightly different:
in last case the value of the second operand is previously extracted to CX register
and only then comparison is made. I used such algorithm for unification with assign
operator.
At this step "COMPAS" generates compare instruction with fix register
(R1 in "E97" and AX in Intel) and the second operand.
Condition analysis in "COMPAS" is just a kind of operation between two operands,
similar to right part calculation of assign operator.
Back to:
Step 3: conditional jump
The last step makes conditional jump if the result of analysis is FALSE.
The condition modification is opposite to those, which is written in the
Pascal text (e.g. >=0 instead of
<0).
"E97" compiler uses demonstrative absolute jumps (to concrete address,
directly contained in command). In Intel there is no such type of instruction,
so I had to use relative jump (the displacement from current instruction
is written in command).
Back to: