×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library

9883 Allocate space for new variable

Submitted by Steve Fewell

Routine:allocspace
Name: Allocate space for new variabler
Starting Address: &9983
Entry criteria: Y contains the length of the variable name (which has
just been copied to the VARTOP location) + 1.
X contains the number of bytes required for the variable parameter block.
Exit: The Variable parameter block is complete, and VARTOP has been updated
to point to the next free location.

Description:

Place a zero at the end of the variable name (to mark the end of the name).

Zero X number of bytes following the variable name location (starting at VARTOP + Y + 1).
This will clear the new variable parameter block.

Next, we need to find out if there is enough space for the variable name length (Y) plus allocation bytes (X) on the
BASIC variable stack (pointed to by VARTOP). This is done as follows.

[&988B] Calculate new VARTOP (&02-&03) location (which will point to the next free variable location (i.e. the
location after the variable name and parameter block info which has been stored for the current
variable)). But, don't update VARTOP with the new address yet.

If the new VARTOP location would be >= the BASIC Stack pointer, then we have run into the stack,
so store 0 for the Next variable MSB address field of the previous variable's parameter block (&3A,1),
to set that variable as being the last variable in the list, and generate a 'No Room' error.

Otherwise Store the updated VARTOP position back in &02-&03 and exit.


Disassembly for the Allocate space for new variable routine

9883   169 000 A9 00 LDA#&00
9885   145 002 91 02 STA (&02),Y
9887   200 C8 INY
9888   202 CA DEX
9889   208 250 D0 FA BNE -6 --> &9885
988B   024 18 CLC
988C   152 98 TYA
988D e 101 002 65 02 ADC &02
988F   144 002 90 02 BCC 2 --> &9893
9891   230 003 E6 03 INC &03
9893   164 003 A4 03 LDY &03
9895   196 005 C4 05 CPY &05
9897   144 015 90 0F BCC 15 --> &98A8
9899   208 004 D0 04 BNE 4 --> &989F
989B   197 004 C5 04 CMP &04
989D   144 009 90 09 BCC 9 --> &98A8
989F   169 000 A9 00 LDA#&00
98A1   160 001 A0 01 LDY#&01
98A3 : 145 058 91 3A STA (&3A),Y
98A5 L 076 161 144 4C A1 90 JMP &90A1 No Room error
98A8   133 002 85 02 STA &02
98AA ` 096 60 RTS

 


 Back to 8BS
Or