×   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

A35D ASCNUM: Handle Exponential values and complete number conversion

Submitted by Steve Fewell

Routine:A35D> Name: ASCNUM: Handle Exponential value (decimal to binary conversion)
and complete the number conversion
Starting Address: &A35D

Description:

A35D:
Call A3BA to Extract Exponent value into A.
Add current exponent value ?&48 to the extracted exponent, and store back in &48.
Continue to A364 to complete the number conversion.

A364 ASCNUM: Complete the Number Conversion:

Store current PTRB pointer position back in &1B (PTRB Offset).
If exponent is zero and no decimal-point found then goto A399 (to copy
Integer to IWA and return with A=&40).

Gosub asign (if zero value in FWA then clear Sign, Exp, etc..., exit with A = sign)
if FWA = 0 then A395 [FWA = 0.0 so exit with C=1 and A=&FF].

Set FWA Exponent to 168 (Default value), FWA Overflow to 0 and FWA Sign to 0 (Positive value).
[Default exponent = 10101000 =&A8 = 2 to the power of 40 as offset from 128.]
gosub 81F7 to Normalise FWA#1 (correcting the exponent value).

If the ?&48 exponent is zero, then it doesn't need to be applied; otherwise:
If exponent in ?&48 is negative then A38B (keep dividing FWA by 10 and incrementing the
exponent by 1, until ?&48 is zero. [meaning that we have now applied the base 10 exponent].

If exponent in ?&48 is positive A382 (keep multiplying FWA by 10 and decrementing the
exponent by 1, until ?&48 is zero. [meaning that we have now applied the base 10 exponent].

After applying the exponent to the binary number, gosub A695 (round Mantissa to 4 bytes),
and exit with Carry=1 and A=&FF.

A399 ASCNUM: Copy Integer from FWA to IWA if it will fit:

If FWA Mantissa 1 is not 0 or FWA Mantissa byte 2's top bit is set (MSB) then the
integer value is too large to fit in the IWA; so go back to the Float routine.

Transfer Integer in FWA to IWA as follows:
    FWA Mantissa byte 2 ==> IWA Byte 4 (MSB)
    FWA Mantissa byte 3 ==> IWA Byte 3
    FWA Mantissa byte 4 ==> IWA Byte 2
    FWA Mantissa byte 5 (rounding) ==> IWA Byte 1 (LSB)

Exit with A=&40 and Carry = 1.

A3BA ASCNUM: Extract Exponent:

Get Next Character (after the 'E').
If '-' then get the Positive value (as described below) and then EOR with #&FF to
make it negative and exit with the carry set.

If '+' then get next character (skip the leading '+')

If first digit is invalid, return 0 as the exponend value (in A).
Subtract 48 to get the binary value of the digit - store in &49.

Get next character.
If second digit is invalid return with A = value in ?&49 [1 digit exponent].

Subtract 48 to get the binary value of the digit - store in &42.
Multiply the first digit by 10 (ASL, ASL, Add ?&49, ASL) and then add the second digit
to obtain the completed exponent.
Return with exponent in A, and carry set if exponent is negative; otherwise, with carry clear.


Disassembly for the ASCNUM: Handle Exponent Values & complete num conv routine

A35D   032 186 163 20 BA A3 JSR &A3BA ASCNUM: Extract Exponent
A360 eH 101 072 65 48 ADC &48
A362 H 133 072 85 48 STA &48
A364   132 027 84 1B STY &1B
A366 H 165 072 A5 48 LDA &48
A368 G 005 071 05 47 ORA &47
A36A - 240 045 F0 2D BEQ 45 --> &A399 ASCNUM: FWA Integer copied to IWA
A36C   032 242 163 20 F2 A3 JSR &A3F2 asign
A36F $ 240 036 F0 24 BEQ 36 --> &A395
A371   169 168 A9 A8 LDA#&A8
A373 0 133 048 85 30 STA &30
A375 d/ 100 047 64 2F STZ &2F
A377 d. 100 046 64 2E STZ &2E
A379   032 247 129 20 F7 81 JSR &81F7
A37C H 165 072 A5 48 LDA &48
A37E 0 048 011 30 0B BMI 11 --> &A38B
A380   240 016 F0 10 BEQ 16 --> &A392
A382 6 032 054 164 20 36 A4 JSR &A436
A385 H 198 072 C6 48 DEC &48
A387   208 249 D0 F9 BNE -7 --> &A382
A389   128 007 80 07 BRA 7 --> &A392
A38B x 032 120 164 20 78 A4 JSR &A478
A38E H 230 072 E6 48 INC &48
A390   208 249 D0 F9 BNE -7 --> &A38B
A392   032 149 166 20 95 A6 JSR &A695
A395 8 056 38 SEC
A396   169 255 A9 FF LDA#&FF
A398 ` 096 60 RTS

ASCNUM: Copy Integer from FWA to IWA if it will fit & exit:
A399 2 165 050 A5 32 LDA &32
A39B - 133 045 85 2D STA &2D
A39D ) 041 128 29 80 AND#&80
A39F 1 005 049 05 31 ORA &31
A3A1   208 206 D0 CE BNE -50 --> &A371
A3A3 5 165 053 A5 35 LDA &35
A3A5 * 133 042 85 2A STA &2A
A3A7 4 165 052 A5 34 LDA &34
A3A9 + 133 043 85 2B STA &2B
A3AB 3 165 051 A5 33 LDA &33
A3AD , 133 044 85 2C STA &2C
A3AF @ 169 064 A9 40 LDA#&40
A3B1 8 056 38 SEC
A3B2 ` 096 60 RTS

ASCNUM: Extract Exponent value:
A3B3   032 197 163 20 C5 A3 JSR &A3C5
A3B6 I 073 255 49 FF EOR#&FF
A3B8 8 056 38 SEC
A3B9 ` 096 60 RTS
A3BA   200 C8 INY
A3BB   177 025 B1 19 LDA (&19),Y
A3BD - 201 045 C9 2D CMP#&2D
A3BF   240 242 F0 F2 BEQ -14 --> &A3B3
A3C1 + 201 043 C9 2B CMP#&2B
A3C3   208 003 D0 03 BNE 3 --> &A3C8
A3C5   200 C8 INY
A3C6   177 025 B1 19 LDA (&19),Y
A3C8 : 201 058 C9 3A CMP#&3A
A3CA " 176 034 B0 22 BCS 34 --> &A3EE
A3CC / 233 047 E9 2F SBC#&2F
A3CE   144 030 90 1E BCC 30 --> &A3EE
A3D0 I 133 073 85 49 STA &49
A3D2   200 C8 INY
A3D3   177 025 B1 19 LDA (&19),Y
A3D5 : 201 058 C9 3A CMP#&3A
A3D7   176 017 B0 11 BCS 17 --> &A3EA
A3D9 / 233 047 E9 2F SBC#&2F
A3DB   144 013 90 0D BCC 13 --> &A3EA
A3DD   200 C8 INY
A3DE B 133 066 85 42 STA &42
A3E0 I 165 073 A5 49 LDA &49
A3E2   010 0A ASL A
A3E3   010 0A ASL A
A3E4 eI 101 073 65 49 ADC &49
A3E6   010 0A ASL A
A3E7 eB 101 066 65 42 ADC &42
A3E9 ` 096 60 RTS
A3EA I 165 073 A5 49 LDA &49
A3EC   024 18 CLC
A3ED ` 096 60 RTS
A3EE   169 000 A9 00 LDA#&00
A3F0   024 18 CLC
A3F1 ` 096 60 RTS

 


 Back to 8BS
Or