8-Bit Software

The BBC and Master Computer Public Domain Library

Back to 8BS Or Back to Disassembly


Page Last Altered:

BA58 REPEAT

Submitted by Steve Fewell

Description:

Set X to the current value of the REPEAT level (location &24).
If the current REPEAT level is greater than or equal to #&14 (20) then issue 'Too many REPEATs' error, as a maximum
of 20 REPEATs can be nested.

Call routine &9BBC to add the BASIC text pointer A offset (&0A) to the BASIC text pointer A base (&0B-&0C),
and reset the BASIC text pointer A offset to 1.

Store the current Program location (&0B-&0C) on the REPEAT start address stack (&0500-&0527), where the
MSB of the current program location (&0C) is stored at &0514 + X (where X is the current REPEAT level) and LSB of
the current program location (&0B) is stored at &0500 + X (where X is the current REPEAT level).

Increment &24 (the REPEAT level) to increase the number of nested REPEAT statements.
Jump to &900B to continue executing the program from the next statement after the REPEAT keyword.


Disassembly for the REPEAT routine

BA58 $ 166 036 A6 24 LDX &24
BA5A   224 020 E0 14 CPX#&14
BA5C   176 167 B0 A7 BCS -89 --> &BA05 Too many REPEATs error
BA5E   032 188 155 20 BC 9B JSR &9BBC Update BASIC Text pointer A (Add offset value & then reset offset to 1)
BA61   165 011 A5 0B LDA &0B
BA63   157 000 005 9D 00 05 STA &0500,X
BA66   165 012 A5 0C LDA &0C
BA68   157 020 005 9D 14 05 STA &0514,X
BA6B $ 230 036 E6 24 INC &24
BA6D L 076 011 144 4C 0B 90 JMP &900B Process next BASIC program statement

 


 Back to 8BS
Or