×   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

8085 Get Address of Variable

Submitted by Steve Fewell

Routine:varaddr
Name: Get Address of Variable
Starting Address: &8085
Entry criteria: &37 and &38 point to the variable name. Y = Variable name length.
Exit: &2A and &2B = the address of the variable block for the variable name [LSB first].
A = &00 if variable not found. &39 = Length of variable Name (Y).

Description:

Store the offset to the end of the variable name in &39 (variable name length).
Load the first character of the variable name. Multiply the ASCII value of the first
character by 2 and store in Y. Y now points to the page &4 offset for the variable pointer
table.
i.e.: If first Char = "A" [ASCII value=&41], then the variable pointer table for
"A" variables is located at &0482.
Note: The resident integer variables (@%, A%, B%, etc...) are handled separately.

Load the MSB of the address stored at the specified variable pointer table location.
If the MSB of the address is zero, then no "A" variables have been defined, so exit with A=&00.

Store the MSB of the variable pointer table address in &2B.
Store the LSB of the variable pointer table address in &2A.

&80A6: Load the 3rd byte of the variable lookup table (&2A, &2B). The 3rd byte is the
beginning of the rest of the variable name [as the variable name is stored without its first
character].

If the variable name character is zero, then we have reached the end of the variable name,
so check whether the length of the variable we are searching for (&39) is the same
as the variable we have found (Y). If not then jump to &8099 to look at the next variable
in the pointer table. If equal, then we have found our variable, so jump to &80C3.
Otherwise (end of name not reached); [&80B6:] Compare the variable name character
(from lookup table) with the next character pointed to by &37, &38.
If the characters don't match then this is not our variable, so goto 8099 to look at next variable
in the pointer table.
Increment Y, and check whether the variable length (&39) has been reached, if not
then (&80B2) load the next character of the variable name in the pointer table (and
jump to &8099 (look at next variable), if the the end of the name was reached (while we still
had more characters in the variable name we were looking for)); otherwise compare this next character [&80B6].
If the end of the variable we are looking for has been reached then check that the next
character of the variable name in the lookup table is zero (indicating the end of the name);
if it isn't, then jump to &8099 to look at the next variable in the lookup table.

Otherwise -> [&80C3:] We have found our variable.
Add length of variable to the address in &2A, &2B -> so that &2A, &2B now
points to the variable details/variable contents section of the variable block (which is located
directly after the variable name). And exit (updating the MSB if any overflow occurred).

[&8099:] Look at next variable in lookup table.
This routine checks byte 2 of the variable block, if it is zero then there is no
next variable address, so exit (with A=00) as the variable doesn't exist.
Otherwise, store the next variable address in &2A (LSB) and &2B and jump to &80A6 to
compare the variable name with the one we are looking for.


Disassembly for the Get Address of Variable routine

8085 9 132 057 84 39 STY &39
8087   160 001 A0 01 LDY#&01
8089 7 177 055 B1 37 LDA (&37),Y
808B   010 0A ASL A
808C   168 A8 TAY
808D   185 001 004 B9 01 04 LDA &0401,Y
8090 : 240 058 F0 3A BEQ 58 --> &80CC
8092 + 133 043 85 2B STA &2B
8094   185 000 004 B9 00 04 LDA &0400,Y
8097   128 011 80 0B BRA 11 --> &80A4
8099   160 001 A0 01 LDY#&01
809B * 177 042 B1 2A LDA (&2A),Y
809D - 240 045 F0 2D BEQ 45 --> &80CC
809F   168 A8 TAY
80A0 * 178 042 B2 2A LDA (&2A)
80A2 + 132 043 84 2B STY &2B
80A4 * 133 042 85 2A STA &2A
80A6   160 002 A0 02 LDY#&02
80A8 * 177 042 B1 2A LDA (&2A),Y
80AA   208 010 D0 0A BNE 10 --> &80B6
80AC 9 196 057 C4 39 CPY &39
80AE   208 233 D0 E9 BNE -23 --> &8099
80B0   128 017 80 11 BRA 17 --> &80C3
80B2 * 177 042 B1 2A LDA (&2A),Y
80B4   240 227 F0 E3 BEQ -29 --> &8099
80B6 7 209 055 D1 37 CMP (&37),Y
80B8   208 223 D0 DF BNE -33 --> &8099
80BA   200 C8 INY
80BB 9 196 057 C4 39 CPY &39
80BD   208 243 D0 F3 BNE -13 --> &80B2
80BF * 177 042 B1 2A LDA (&2A),Y
80C1   208 214 D0 D6 BNE -42 --> &8099
80C3   152 98 TYA
80C4 e* 101 042 65 2A ADC &2A
80C6 * 133 042 85 2A STA &2A
80C8   144 002 90 02 BCC 2 --> &80CC
80CA + 230 043 E6 2B INC &2B
80CC ` 096 60 RTS

 


 Back to 8BS
Or