8-Bit Software

The BBC and Master Computer Public Domain Library

Back to 8BS Or Back to Disassembly


Page Last Altered:

B6D9 GOSUB

Submitted by Steve Fewell

Description:

Call routine &B82A to get the Line Number after the GOTO keyword, Issue 'No such line' error if the Line doesn't exist
and set &3D-&3E to the start address of the specified Program Line.
Call routine &9BA6 to check that the statement terminates correctly with a ':', '<cr>' or 'ELSE-token'
character, issuing 'Syntax error' if it doesn't.

If the GOSUB Level (at location &25) is more than or equal to &1A (26) then issue 'Too many GOSUBs' error, as
the maximum nested GOSUB level is 26.

Store the current Text Pointer A location on the GOSUB return address stack, so that the correct position in the program
can be returned to when the RETURN statement corresponding to this GOSUB is reached.
The LSB Byte of the current program position is placed on the GOSUB return address stack at position &05CC + Y
(where Y is the current GOSUB level, i.e. the value of &25 before it is incremented (in the range 0-24)).
The MSB Byte of the current program position is placed on the GOSUB return address stack at position &05E6 + Y
(where Y is the current GOSUB level, i.e. the value of &25 before it is incremented (in the range 0-24)).

Increment the GOSUB level [&25] (to increase the current number of active GOSUBs and the GOSUB Stack level value).

Jump to &B723 to position BASIC Text Pointer A at the start of the specified Line
and begin execution of the GOSUB routine, as follows:
* If the TRACE flag (location &20) is not zero, then call routine &9C4B to display the Line Number
    (located in the IWA) on the screen [if TRACE is currently active].
* Set BASIC Text Pointer A to the start of the specified program line (&3D-&3E, offset by 4 bytes).
* Jump to &900B to start executing the code at the GOTO Line (the new BASIC Text Pointer A location).


Disassembly for the GOSUB routine

B6D9 * 032 042 184 20 2A B8 JSR &B82A Get Line Number & find Program Address of the Line Number
B6DC   032 166 155 20 A6 9B JSR &9BA6 Check end of Statement
B6DF % 164 037 A4 25 LDY &25
B6E1   192 026 C0 1A CPY#&1A
B6E3   176 014 B0 0E BCS 14 --> &B6F3 Too many GOSUBs error
B6E5   165 011 A5 0B LDA &0B
B6E7   153 204 005 99 CC 05 STA &05CC,Y
B6EA   165 012 A5 0C LDA &0C
B6EC   153 230 005 99 E6 05 STA &05E6,Y
B6EF % 230 037 E6 25 INC &25
B6F1 0 128 048 80 30 BRA 48 --> &B723 Jump to program line specified

 


 Back to 8BS
Or