CONDITION ANALYSIS: INTEL BRICKS

Back to:
index E97
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 (compare with the second operand)

Step 3 (jump, if condition is FALSE)

Examples of full condition


Condition analysis: step 1 (extract first operand to R1)

(see step 1 for assign operator)



Back to:
index top E97

Condition analysis: step 2 (compare with the second operand)

Compare simple variable (e.g. a) or variable with concrete index (e.g. b[2]) with AX (assume, that variable address is 490):
8B 0E 90 04 mov cx,[490]
39 C8 cmp ax,cx

Compare index variable (e.g. b[i]) with AX (assume, that i address is 490 and b[0] address is 4D0):
8B 1E 90 04 mov bx,[490]
D1 E3 shl bx (*2)
8B 8F D0 04 mov cx,[bx+4D0]
39 C8 cmp ax,cx

Compare constant with AX (assume, that constant is 40):
B9 40 00 mov cx,40
39 C8 cmp ax,cx
All constants are handled this way.



Back to:
index top E97

Condition analysis: step 3 (jump, if condition is FALSE)

Jump instructions for different conditions:
if result < 0 then ... 7D ?? jge ... if result >= 0 then ... 7C ?? jl ...
if result = 0 then ... 75 ?? jnz ... if result <> 0 then ... 74 ?? jz ...
if result > 0 then ... 7E ?? jle ... if result <= 0 then ... 7F ?? jg ...
By ?? concrete displacement is marked.



Back to:
index top E97

Examples of full conditions

1. i < k (4FE - address of variable i, 4FC - k)
A1 FE 04 mov ax,[04FE] Extract i
8B 0E FC 04
39 C8
mov cx,[04FC]
cmp ax,cx
Compare i and k
7D ?? jge ... Jump, if FALSE
Instead of ?? "COMPAS" will substitute concrete displacement.

2. 2 = a[i] (4FE - address of variable i, 4F0 - a[0])
B8 02 00 mov ax,2 Left part to AX
8B 1E FE 04
D1 E3
8B 8F F0 04
mov bx,[04FE]
shl bx,1 (*2)
mov cx,[bx+4F0]
Right part to CX
39 C8 cmp ax,cx
Compare
75 ?? jnz ... Jump, if FALSE



Back to:
index top E97