8-Bit Software

The BBC and Master Computer Public Domain Library

Back to 8BS Or Back to Disassembly


Page Last Altered:

9854 Add new variable name to Variable Pointer table

Submitted by Steve Fewell

Routine:addvar
Name: Add new variable name to Variable Pointer table
Starting Address: &9854
Entry criteria: &37 and &38 point to the start of the variable name.
&39 contains the length of the variable name + 1.
Exit: The Variable name has been stored in a newly created variable parameter block.

Description:

Load the first character of the variable name.
Multiply the ASCII character of the variable name by 2 to get the page &4 address of
the pointer table start position for that character (a 2-byte address is allocated for each character
a variable can start with. This address points to the first defined variable beginning with that
character, or the MSB adress byte contains &00, if no variables have been defined beginning with that character.

[&9859] Store the variable pointer table start address (for the character we want) in &3A-&3B.
If the variable pointer table location contains a non-zero address, then there are already variable(s)
defined beginning with that character, so, store this address in &3A-&3B and check this address.
The first two bytes of each variable block is the address of the next variable (beginning with that character),
so we just need to keep checking this address, then the location pointed to by that address (etc...),
until we find an address with a zero MSB value.

[9868] When we have found zero address, we know that we are at the last variable in the list
of variables beginning with the character we want [note: the variables are stored as a linked list].
Replace the &0000 address with the value of VARTOP (the next free space for variable storage).
VARTOP will be the first location of the variable block for the variable that we will create.
Store 00 in the seond byte of this variable location (as a MSB adress of &00 represents the new end of
the variable list).

If there are no more characters in the variable name (only 1 character name) then exit, as we
do not need to store the variable name, as the first character is already known (by the pointer table
location).
Otherwise, store the rest of the variable name (excluding the first character) at the new variable block location.
Exit when the variable name has been copied.


Disassembly for the Add new variable name to Variable Pointer table routine

9854   160 001 A0 01 LDY#&01
9856 7 177 055 B1 37 LDA (&37),Y
9858   010 0A ASL A
9859   162 004 A2 04 LDX#&04
985B : 133 058 85 3A STA &3A
985D ; 134 059 86 3B STX &3B
985F : 177 058 B1 3A LDA (&3A),Y
9861   240 005 F0 05 BEQ 5 --> &9868
9863   170 AA TAX
9864 : 178 058 B2 3A LDA (&3A)
9866   128 243 80 F3 BRA -13 --> &985B
9868   165 003 A5 03 LDA &03
986A : 145 058 91 3A STA (&3A),Y
986C   165 002 A5 02 LDA &02
986E : 146 058 92 3A STA (&3A)
9870   169 000 A9 00 LDA#&00
9872   145 002 91 02 STA (&02),Y
9874   200 C8 INY
9875 9 196 057 C4 39 CPY &39
9877 1 240 049 F0 31 BEQ 49 --> &98AA   [RTS]
9879 7 177 055 B1 37 LDA (&37),Y
987B   145 002 91 02 STA (&02),Y
987D   200 C8 INY
987E 9 196 057 C4 39 CPY &39
9880   208 247 D0 F7 BNE -9 --> &9879
9882 ` 096 60 RTS

 


 Back to 8BS
Or