8-Bit Software

The BBC and Master Computer Public Domain Library

Back to 8BS Or Back to Disassembly


Page Last Altered:

AB4E ASCNUM (ASCII String to Binary Number)

Submitted by Steve Fewell

Routine:ascnum
Name: Convert ASCII string to Binary numbers
Starting Address: &AB4E
Entry: &36 = Length of String in SWA. SWA = ASCII Number "String".
Exit: A and &27 contain the conversion type (&40 = Integer; &FF = Float).

Description:

The ASCII string in SWA is converted to either an Integer (IWA)
or a Float (FWA).
The routine places a binary zero at the end of the SWA, and steps &36 by 1).
Push the text pointer B position onto the Hardware stack (PHA).
Read the text at the text pointer B position (offset from &0600).
Skip any spaces at PTR B.
if a '-' is the first character (sign) in the string then:      Skip any Spaces.
     Call &A2E1 to get the number (result).
     Then complement the result (if the carry is set - non-zero)
     Set &27 to the Result type and retore PTR B position from stack the return.
Otherwise; If a '+' is the first character found, then skip spaces and get next character
(and ignore the '+'-sign).
Call &A2E1 to get the numeric result.
Store the result type in &27.
restore the PTR B position and return with A=?&27.


Disassembly for the ASCNUM routine

AB3A h 104 68 PLA
AB3B   133 027 85 1B STA &1B
AB3D h 104 68 PLA
AB3E   133 026 85 1A STA &1A
AB40 h 104 68 PLA
AB41   133 025 85 19 STA &19
AB43 ' 165 039 A5 27 LDA &27
AB45 ` 096 60 RTS
AB46 - AB4D ...[VAL routine]...
AB4E 6 166 054 A6 36 LDX &36
AB50   158 000 006 9E 00 06 STZ &0600,X
AB53   165 025 A5 19 LDA &19
AB55 H 072 48 PHA
AB56   165 026 A5 1A LDA &1A
AB58 H 072 48 PHA
AB59   165 027 A5 1B LDA &1B
AB5B H 072 48 PHA
AB5C d 100 027 64 1B STZ &1B
AB5E d 100 025 64 19 STZ &19
AB60   169 006 A9 06 LDA#&06
AB62   133 026 85 1A STA &1A
AB64   032 213 142 20 D5 8E JSR &8ED5 Skip Spaces in PTRB
AB67 - 201 045 C9 2D CMP#&2D
AB69   240 014 F0 0E BEQ 14 --> &AB79
AB6B + 201 043 C9 2B CMP#&2B
AB6D   208 003 D0 03 BNE 3 --> &AB72
AB6F   032 213 142 20 D5 8E JSR &8ED5 Skip Spaces in PTRB
AB72   198 027 C6 1B DEC &1B
AB74   032 225 162 20 E1 A2 JSR &A2E1 ASCNUM: Extract Number at PTRB
AB77   128 013 80 0D BRA 13 --> &AB86
AB79   032 213 142 20 D5 8E JSR &8ED5 Skip Spaces in PTRB
AB7C   198 027 C6 1B DEC &1B
AB7E   032 225 162 20 E1 A2 JSR &A2E1 ASCNUM: Extract Number at PTRB
AB81   144 003 90 03 BCC 3 --> &AB86
AB83   032 218 172 20 DA AC JSR &ACDA Complement Result
AB86 ' 133 039 85 27 STA &27
AB88   128 176 80 B0 BRA -80 --> &AB3A

 


 Back to 8BS
Or