[Index] [Previous] [Next]

1.13 IF Keyword Handler


Evaluates a condition. A condition has three mandatory parts : a left-hand side expression, a comparison operator, and a right-hand side expression. Examples are 'A=2', 'B<=4' and so on.

The comparison operator is one or more of the three operators '>', '=', and '<'. Since these three operators can appear more than once, and in any order, the code does something rather clever to convert them to a single 'comparison operator value'. This value has bit 0 set if '>' is present, bit 1 for '=', and bit 2 for '<'. Thus the comparison operators '<=' and '=<' are both 6, likewise '>=' and '=>' are both 3, and '<>' is 5

You can therefore get away with stupid operators such as '>>>>>' (value 1, the same as a single '>') and '>=<' (value 7), the latter being particularly dense as it causes the condition to always evaluate to true.

Get left-hand side expression onto stack. Also get first byte of comparison operator into A.
0516 CD8A06 If CALL EvalExpression
0519 7E MOV A,M
051A CD020A CALL FPush
Get value for comparison operator. Fixme: This needs proper working out as I suspect it's brilliant!
051D 1600 MVI D,00
051F D69C GetCompareOpLoop SUI KWID_>
0521 DA3205 JC GotCompareOp
0524 FE03 CPI 03
0526 D23205 JNC GotCompareOp
0529 FE01 CPI 01
052B 17 RAL
052C B2 ORA D
052D 57 MOV D,A
052E D7 RST NextChar
052F C31F05 JMP GetCompareOpLoop
If no comparison operator value, then syntax error out.
0532 7A GotCompareOp MOV A,D
0533 B7 ORA A
0534 CAD001 JZ SyntaxError
Preserve comparison operator value on stack and evaluate the right hand side of the condition.
0537 F5 PUSH PSW
0538 CD8A06 CALL EvalExpression
Syntax check for the THEN keyword.
053B CF RST SyntaxCheck
053D 2B DCX H
053F C1 POP B
0540 D1 POP D
0541 E5 PUSH H
0542 F5 PUSH PSW
0543 CD4C0A CALL FCompare
0546 3C INR A
0547 17 RAL
0548 C1 POP B
0549 A0 ANA B
054A E1 POP H
054B CAF704 JZ 04F7
Condition evaluated to True. Here we get the first character of the THEN statement, and if it's a digit then we jump to GOTO's handler as it's an implicit GOTO. Otherwise we jump to near the top of Exec to run the THEN statement.
054E D7 RST NextChar
054F DACF04 JC Goto
0552 C34304 JMP Exec+5


[Index] [Previous] [Next]