8-Bit Software

The BBC and Master Computer Public Domain Library

Back to 8BS Or Back to Disassembly


Page Last Altered:

Extract String

Submitted by Steve Fewell

Routine: ExtStr
Name: Extract String
Starting Address: &AD19
Entry criteria: Text Pointer B points to the " character [quote] of the String. Y contains the Text Pointer B Offset (&1B).
Exit: SWA contains the extracted String.

Description:
Set X to 0 (X is a pointer to the next free position in the SWA).

Increment Y to point to the character after the quote. If the current character is a carriage return (ASCII 13), then the end of line has been reached before the closing quote, so a Missing " error is generated.
Otherwise, store the character in the next free location in the SWA, and increment the next free location (X), and the Text Pointer B Offset (Y).

If the character that was just stored wasn't a quote ["] then process the next character.

Otherwise, if a quote was just processed, then check the next character. If the next character is not a quote then branch to the end of string routine (&AD11), otherwise increment Y to the next character (ignoring the second quote, as the first quote has already been stored in the SWA), before processing the next character.

End of string routine (&AD11):
When the end of string is reached (a quote which isn't followed by a second quote), the length of the string (X) is decremented by 1 (as the end quote is not part of the string). This length is stored in &36 (The SWA length byte), and the current Text Pointer B Offset position (Y) is stored back in the Text Pointer B working area (&1B), the offset now points to the character after the end quotes. Load the Accumulator with 0 (to signify that a String type has just been processed) and exit.

 

Disassembly for the Extract String routine

AD19   162 000 A2 00 LDX#&00
AD1B   200 C8 INY
AD1C   177 025 B1 19 LDA (&19),Y
AD1E   201 013 C9 0D CMP#&0D
AD20   240 017 F0 11 BEQ 17 --> &AD33
AD22   157 000 006 9D 00 06 STA &0600,X
AD25   200 C8 INY
AD26   232 E8 INX
AD27 " 201 034 C9 22 CMP#&22
AD29   208 241 D0 F1 BNE -15 --> &AD1C
AD2B   177 025 B1 19 LDA (&19),Y
AD2D " 201 034 C9 22 CMP#&22
AD2F   240 234 F0 EA BEQ -22 --> &AD1B
AD31   208 222 D0 DE BNE -34 --> &AD11
AD33 L 076 148 146 4C 94 92 JMP &9294   Missing " error

Complete the Extraction of the String

AD11   202 CA DEX
AD12 6 134 054 86 36 STX &36
AD14   132 027 84 1B STY &1B
AD16   169 000 A9 00 LDA#&00
AD18 ` 096 60 RTS

 


 Back to 8BS
Or