[Index] [Previous] [Next]

1.8 FOR Handler

For

Although FOR indicates the beginning of a program loop, the handler only gets called the once. Subsequent iterations of the loop return to the following statement or program line, not the FOR statement itself.

First we call LET to assign the initial value to the variable. On return, HL points to the next bit of program (the TO clause with any luck)
03D5 CD0205 For CALL Let
Stick program ptr onto stack. We lose the return address, since we don't need it as this function conveniently falls into ExecNext by itself.
03D8 E3 XTHL
03D9 CD9201 CALL GetFlowPtr
Get program ptr into DE.
03DC D1 POP D
03DD C2E203 JNZ 03E2
03E0 09 DAD B
03E1 F9 SPHL
HL=prog ptr, DE=stack. Here we check we've at least 8*4 bytes of space to use for the flow struct.
03E2 EB XCHG
03E3 0E08 MVI C,08
03E5 CDB601 CALL CheckEnoughVarSpace
Get pointer to end of statement (or end of program line) onto stack. This is the prog ptr that NEXT will return to.
03E8 E5 PUSH H
03E9 CDF504 CALL FindNextStatement
03EC E3 XTHL
Push current line number onto stack.
03ED E5 PUSH H
03EE 2A6101 LHLD CURRENT_LINE
03F1 E3 XTHL
Syntax check that TO clause is next.
03F2 CF RST SyntaxCheck
03F3 95 KWID_TO
Evaluate expression following 'TO', and push the result of that expression (a floating point number of course) on the stack
03F4 CD8A06 CALL EvalExpression
03F7 E5 PUSH H
03F8 CD1D0A CALL FCopyToBCDE
03FB E1 POP H
03FC C5 PUSH B
03FD D5 PUSH D
Initialise the STEP value in BCDE to 1.
03FE 010081 LXI B,8100
0401 51 MOV D,C
0402 5A MOV E,D
If a STEP clause has not been given, skip ahead with the direction byte (in A) as 0x01.
0403 7E MOV A,M
0404 FE97 CPI KWID_STEP
0406 3E01 MVI A,01
0408 C21404 JNZ PushStepValue
STEP clause has been given so we evaluate it and get it into BCDE. The sign of this value becomes the direction byte (0x01 for fowards, 0xFF for backwards).
040B CD8B06 CALL EvalExpression+1
040E E5 PUSH H
040F CD1D0A CALL FCopyToBCDE
0412 EF RST FTestSign
0413 E1 POP H
Push the STEP value onto the stack.
0414 C5 PushStepValue PUSH B
0415 D5 PUSH D
Push A onto stack. (A=1 if no step clause, else ???)
0416 F5 PUSH PSW
0417 33 INX SP
Push the prog ptr to the end of the FOR statement (kept on PROG_PTR_TEMP) on the stack.
0418 E5 PUSH H
0419 2A5D01 LHLD PROG_PTR_TEMP
041C E3 XTHL
Push KWID_FOR onto the stack, and fall into ExecNext
041D 0681 EndOfForHandler MVI B,KWID_FOR
041F C5 PUSH B
0420 33 INX SP

 


[Index] [Previous] [Next]