6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Tue Jul 02, 2024 6:58 pm

All times are UTC




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sat Jul 10, 2004 4:49 pm 
Offline

Joined: Tue Jul 06, 2004 5:16 am
Posts: 11
I can't understand FLOATING POINT REPRESENTATION of APPLE II in"Apple II Reference Manual (Red Book), January 1978, pages 94-95."

The Red Book said:
HIGH-ORDER MANTISSA BYTE
01.XXXXXX Positive mantissa.
10.XXXXXX Negative mantissa.
00.XXXXXX Unnormalized mantissa.
11.XXXXXX Exponent = -128.
But,I can't understand when the high-order mantissa byte is 00 or 11. :(

I found the FLOATING POINT REPRESENTATION of APPLE II is different with IEEE. And I can't find reference of it.

Can anybody help me?
Thanks.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Jul 10, 2004 9:44 pm 
Offline

Joined: Sun Aug 24, 2003 7:17 pm
Posts: 111
For IEEE representation:

Code:
 
         13.  $41500000
         26.  $41D00000
         52.  $42500000
        104. $42D00000
[/code

Bit 31 - sign bit - 0
bit 30-23 - exponent - $82,$83,$84,$85
bit 22-0 - mantissa - $500000 (13 = %1101, first bit implicit i.e %101 or $5)

If you have APPLE BASIC to print out 13.,26.,52.,104. in hex I can tell you the (slightly deviating?) "APPLE representation".

Good luck!


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 11, 2004 1:17 am 
Offline

Joined: Tue Jul 06, 2004 5:16 am
Posts: 11
1. Mantissa

The floating point mantissa is stored in two's complement representation
with the sign at the most significant bit (MSB) position of the high-order
mantissa byte. The mantissa provides 24 bits of precision, including sign,
and can represent 24-bit integers precisely. Extending precision is simply
a matter of adding bytes at the low order end of the mantissa.

Except for magnitudes less than 2^-128 (which lose precision) mantissa are
normalized by the floating point routines to retain maximum precision.
That is, the numbers are adjusted so that the upper two high-order mantissa
bits are unequal.


HIGH-ORDER MANTISSA BYTE
01.XXXXXX Positive mantissa.
10.XXXXXX Negative mantissa.
00.XXXXXX Unnormalized mantissa.
11.XXXXXX Exponent = -128.

2. Exponent.

The exponent is a binary scaling factor (power of two) which is applied to
the mantissa. Ranging from -128 to +127, the exponent is stored in
standard two's complement representation except for the sign bit which is
complemented. This representation allows direct comparison of exponents,
since they are stored in increasing numerical sequence. The most negative
exponent, corresponding to the smallest magnItude, -128, is stored as $00
($ means hexidecimal) and the most positive, +127, is stored as $FF (all
ones).


EXPONENT STORED AS

+127 11111111 ($FF)

+3 10000011 ($83)
+2 10000010 ($82)
+1 10000001 ($81)
0 10000000 ($80)
-1 01111111 ($7F)
-2 01111110 ($7E)
-3 01111101 ($7D)

-128 00000000 ($00)


The smallest magnitude which can be represented is 2^-150.

_____ _____ _____ _____
| | | | | | | |
| 0 | | 0 | | 0 | | 1 |
|_____| |_____| |_____| |_____|

HIGH LOW
EXP MANTISSA


The largest positive magnitude which can be represented is +2^128-1.

_____ _____ _____ _____
| | | | | | | |
| $7F | | $7F | | $FF | | $FF |
|_____| |_____| |_____| |_____|

EXP MANTISSA



FLOATING POINT REPRESENTATION EXAMPLES

DECIMAL HEX HEX
NUMBER EXPONENT MANTISSA

+ 3 81 60 00 00
+ 4 82 40 00 00
+ 5 82 50 00 00
+ 7 82 70 00 00
+12 83 60 00 00
+15 83 78 00 00
+17 84 44 00 00
+20 84 50 00 00
+60 85 78 00 00

- 3 81 A0 00 00
- 4 81 80 00 00
- 5 82 B0 00 00
- 7 82 90 00 00
-12 83 A0 00 00
-15 83 88 00 00
-17 84 BC 00 00
-20 84 B0 00 00
-60 85 88 00 00

I can understand the Representation when the high-order mantissa byte is 01.xxxxxx(positive) and 10.xxxxxx(negative), but I can't understand when the high-order mantissa byte is 00.xxxxxx(Unnormalized), especially 11.xxxxxx(Exponent = -128).

e.g. What does this mean:
$00 $c1 $00 $00
and
$85 $c1 $00 $00
.


Top
 Profile  
Reply with quote  
 Post subject: Some information
PostPosted: Sun Jul 11, 2004 4:21 am 
Offline

Joined: Tue Jul 06, 2004 5:16 am
Posts: 11
I found some information of APPLE II's floating-point number representation at http://aplawrence.com/cgi-bin/wiki?FloatingPoint

["Tandy stored floating point nubers in what they called "XS128 notation" (Excess 128 is what they really meant) and MBASIC used packed BCD."
Tandy used excess 128 because Microsoft used it in their 8 bit BASIC interpreters. Excess 128 worked well with 8 bit CPU's (like the Z80 in Tandy's TRS-80 boxes and the 6510 in the Commodore 64) because the conversion between ASCII and floating binary format could be carried out with simple binary adds, shifts and rotates -- operations that were relatively quick on these processors. The alternative, IEEE floating point format, was best implemented on 16 bit processors, where integer multiply and divide operations were common. ]


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 11, 2004 8:06 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
tedaz wrote:
I can understand the Representation when the high-order mantissa byte is 01.xxxxxx(positive) and 10.xxxxxx(negative), but I can't understand when the high-order mantissa byte is 00.xxxxxx(Unnormalized), especially 11.xxxxxx(Exponent = -128).


After a floating point operation floating point numbers are usually normalised (by shifting all the bits left and subtracting one from exponent until the most significant bit of the value is at the start of the mantissa) so that as much precision as possible is kept.

The Apple II uses a signed mantissa so a positive number will always start 0xxxxxxx and a negative one 1xxxxxxx. When we normalise a positive number we shift out leading zeros until a 1 bit reaches bit 6 (e.g. 01xxxxxx). Similarly for a negative we shift out leading ones until a zero reaches bit 6 (e.g. 10xxxxxx).

If the exponent is already -128 then a normalization step would cause it to underflow (-128 - 1 = 127) so in these cases we may be left with 00 (for a positive value) or 11 (for a negative value) as the top two bits of mantissa. Both patterns represent unnormal values.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 11, 2004 11:37 am 
Offline

Joined: Sun Aug 24, 2003 7:17 pm
Posts: 111
Example, the floating point representation of -0.09, IEEE version:

The sign bit is 1

0.09= 0.09 * 2**27 / 2**27 = 12079595.52/2**27 = (about)12079596/2**27 = $B851EC/2**27

Comment: 2**27 selected to have the mantissa between $800000 and $FFFFFF

The most significant bit of the mantissa is "implicit" as it is known to be set, i.e. the mantissa is $3851EC with only 23 bits used leaving the most significant bit of the 3 bytes free for one bit of the exponent.

The exponent is 150 - 27 = 123 = %01111011. The least significant bit is put in the "free" bit in byte 2. Together with the mantissa the 3 least significant bytes are therefore $B851EC. The 7 remaining bits together with the sign bit put in front are therefore %10111101 = $BD

All together: $BDB851EC

Multiplying 0 with any value 2**n the result is zero, i.e. it cannot be "scaled" to be between $800000 and $FFFFFF. As a special rule 0 is represented as $00000000 which normally (according to the rule above) should have meant $800000 / 2**150. The smallest positive non-zero number that can be represented is therefore the number with floating point representation $00000001 meaning

$800001 /2**150, about 5.88E-39. The largest number is $7FFFFFFF meaning $FFFFFF/2**(150-$FF)=

$FFFFFF*2**($FF-150) =16777215 * 2**105 , about 6.81E38.

Other (older) floating point representations deviate only little from this. Looking at the hex representation of a few numbers, positive/negative zero, multiplied by 2 etc it can easily be identified.


Fom what "Bitwise" wrote:

-0.09= -0.09 * 2**27 / 2**27 = -12079595.52/2**27 = (about) -12079596/2**27 = $FF47AE14/2**27 in modulo 2**32 representation. Shifting left 7 bits one gets $A3D70A with $A=%1010. This is then the "Apple mantissa" of -0.09. But what is the exponent? This is not defined! If "Bitwise" gives the full "Apple floating point" representation of -0.09 including the most significant byte containing the exponent everything should be clear!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Jul 11, 2004 1:51 pm 
Offline

Joined: Sun Aug 24, 2003 7:17 pm
Posts: 111
Sorry, my interpretation of "BitWise" was not correct. I think that it is necessary to work out at least one example for a totally complete and unambigious definition. If somebody has an APPLE please have it print out for example 0 0.9 -0.9 1.8 3.6 in hex format. Then everything should be crystal clear! That's what I did with my PC using IEEE representation.

"tedaz" has a very thorough discussion. What is missing is the meaning in the form XX.XXXX of the bit sequences he specifies!


Top
 Profile  
Reply with quote  
 Post subject: My last post today!
PostPosted: Sun Jul 11, 2004 3:51 pm 
Offline

Joined: Sun Aug 24, 2003 7:17 pm
Posts: 111
From "tedaz" table

+ 3 81 60 00 00
+ 4 82 40 00 00
+ 5 82 50 00 00
+ 7 82 70 00 00
+12 83 60 00 00
+15 83 78 00 00
+17 84 44 00 00
+20 84 50 00 00
+60 85 78 00 00

- 3 81 A0 00 00
- 4 81 80 00 00
- 5 82 B0 00 00
- 7 82 90 00 00
-12 83 A0 00 00
-15 83 88 00 00
-17 84 BC 00 00
-20 84 B0 00 00
-60 85 88 00 00

I conclude that for Apple BASIC

3 = 3 * 2**21 / 2**21 = $600000/2**21 , the most significant bits %01

The exponent is 152 - 21 = 131 = $83

4 = 4 * 2**20 / 2**20 = $400000/2**20 , the most significant bits %01.

The exponent is 152 - 20 = 130 = $82

Using this rule:

0.09= 0.09 * 2**26 / 2**26 = 6039797.76/2**26 = (about) 6039798/2**26 = $5C28F6/2**26


The mantissa is therefore $5C28F6

-0.09= -0.09 * 2**26 / 2**26 = -6039797.76/2**26 = (about) -6039798/2**27 = $A3D70A/2**27 in

modulo 2**24 representation.

The exponent is 152 - 26 = 126 = $7E in both cases, i.e.

0.09 $7E5C28F6
-0.09 $7EA3D70A

But assuming this to be correct (it must be) it is not correct to say that the "The exponent is in standard two's complement representation except for the sign bit which is complemented"


Top
 Profile  
Reply with quote  
 Post subject: An APPLE Emulator
PostPosted: Sun Jul 11, 2004 4:33 pm 
Offline

Joined: Tue Jul 06, 2004 5:16 am
Posts: 11
I found an APPLE emulator at http://www.tomcharlesworth.pwp.blueyonder.co.uk/
Maybe it can help "Mats" print floating-point numbers.
Can "Mats" tell me how to print floating-point numbers with APPLE's BASIC?


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 11, 2004 6:09 pm 
Offline

Joined: Tue Sep 30, 2003 5:46 pm
Posts: 30
Location: Central Wisconsin
tedaz wrote:
I found the FLOATING POINT REPRESENTATION of APPLE II is different with IEEE. And I can't find reference of it.

Use the source, Luke! (I couldn't resist the Star Wars-ish reference... :D )

Review the "Floating Point Math" section.


Top
 Profile  
Reply with quote  
 Post subject: Now it finally all fits
PostPosted: Sun Jul 11, 2004 6:52 pm 
Offline

Joined: Sun Aug 24, 2003 7:17 pm
Posts: 111
From "tedaz" table

+ 3 81 60 00 00
+ 4 82 40 00 00
+ 5 82 50 00 00
+ 7 82 70 00 00
+12 83 60 00 00
+15 83 78 00 00
+17 84 44 00 00
+20 84 50 00 00
+60 85 78 00 00

- 3 81 A0 00 00
- 4 81 80 00 00
- 5 82 B0 00 00
- 7 82 90 00 00
-12 83 A0 00 00
-15 83 88 00 00
-17 84 BC 00 00
-20 84 B0 00 00
-60 85 88 00 00

I conclude that for Apple BASIC

a)

3 = 3 * 2**21 / 2**21 = $600000/2**21 , the most significant bits %01

The exponent: 22 - 21 = $01 => $81 (most significant bit inverted)

b)

4 = 4 * 2**20 / 2**20 = $400000/2**20 , the most significant bits %01.

The exponent is 22 - 20 = $02 => $82

c)

Using this rule:

1 = 2**22 / 2**22 = $400000/2**22 , the most significant bits %01.

The exponent is 22 - 22 = $00 => $80

d)

0.09 = 0.09 * 2**26 / 2**26 = 6039797.76/2**26 = (about) 6039798/2**26 = $5C28F6/2**26

The mantissa is therefore $5C28F6

The exponent is 22 - 26 = -4 = $FC => $7C

i.e. 0.09 $7C5C28F6

e)

-0.09 = -0.09 * 2**26 / 2**26 = -6039797.76/2**26 = (about) -6039798/2**26 = $A3D70A/2**26 in modulo 2**24 representation.

The exponent as above, i.e.

-0.09 $7CA3D70A


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 12, 2004 1:12 am 
Offline

Joined: Tue Jul 06, 2004 5:16 am
Posts: 11
Yes, I have already read this
http://www.6502.org/source/floats/wozfp1.txt
http://www.6502.org/source/floats/wozfp2.txt
http://www.6502.org/source/floats/wozfp3.txt
Therefor I have the question about "APPLE's floationg-point number representation".
In "http://www.6502.org/source/floats/wozfp1.txt",only these message was given:
Code:
They presume a four-byte floating point operand consisting of
a one-byte exponent ranging from -128 to +127 and a
24-bit two's complement mantissa between 1.0 and 2.0.

Code:
    In the Exponent:
    00 Represents -128
          ...
    7F Represents -1
    80 Represents 0
    81 Represents +1
          ...
    FF Represents +127


  Exponent    Two's Complement Mantissa
  SEEEEEEE  SM.MMMMMM  MMMMMMMM  MMMMMMMM
     n         n+1       n+2       n+3

And "http://www.6502.org/source/floats/wozfp2.txt" is the errata for wozfp1.txt

"http://www.6502.org/source/floats/wozfp3.txt" is "Apple II Reference Manual (Red Book), January 1978, pages 94-95."
In it, the floating-point representation is describe as this
Code:
        FLOATING POINT REPRESENTATION


      _____    _____    _____    _____
     |     |  |     |  |     |  |     |
     |     |  | HI  |  |     |  | LOW |
     |_____|  |_____|  |_____|  |_____|

    Exponent       Signed Mantissa

1.  Mantissa

The floating point mantissa is stored in two's complement representation
with the sign at the most significant bit (MSB) position of the high-order
mantissa byte.  The mantissa provides 24 bits of precision, including sign,
and can represent 24-bit integers precisely.  Extending precision is simply
a matter of adding bytes at the low order end of the mantissa.

Except for magnitudes less than 2^-128 (which lose precision) mantissa are
normalized by the floating point routines to retain maximum precision. 
That is, the numbers are adjusted so that the upper two high-order mantissa
bits are unequal.


      HIGH-ORDER MANTISSA BYTE
     01.XXXXXX  Positive mantissa.
     10.XXXXXX  Negative mantissa.
     00.XXXXXX  Unnormalized mantissa.
     11.XXXXXX  Exponent = -128.

2.  Exponent.

The exponent is a binary scaling factor (power of two) which is applied to
the mantissa.  Ranging from -128 to +127, the exponent is stored in
standard two's complement representation except for the sign bit which is
complemented.  This representation allows direct comparison of exponents,
since they are stored in increasing numerical sequence.  The most negative
exponent, corresponding to the smallest magnItude, -128, is stored as $00
($ means hexidecimal) and the most positive, +127, is stored as $FF (all
ones).


     EXPONENT      STORED AS

      +127      11111111  ($FF)

        +3      10000011  ($83)
        +2      10000010  ($82)
        +1      10000001  ($81)
         0      10000000  ($80)
        -1      01111111  ($7F)
        -2      01111110  ($7E)
        -3      01111101  ($7D)

      -128      00000000  ($00)


The smallest magnitude which can be represented is 2^-150.

      _____    _____    _____    _____
     |     |  |     |  |     |  |     |
     |  0  |  |  0  |  |  0  |  |  1  |
     |_____|  |_____|  |_____|  |_____|

               HIGH               LOW
       EXP            MANTISSA


The largest positive magnitude which can be represented is +2^128-1.

      _____    _____    _____    _____
     |     |  |     |  |     |  |     |
     | $7F |  | $7F |  | $FF |  | $FF |
     |_____|  |_____|  |_____|  |_____|

       EXP            MANTISSA



 FLOATING POINT REPRESENTATION EXAMPLES

    DECIMAL    HEX        HEX
    NUMBER   EXPONENT   MANTISSA

     + 3        81      60 00 00
     + 4        82      40 00 00
     + 5        82      50 00 00
     + 7        82      70 00 00
     +12        83      60 00 00
     +15        83      78 00 00
     +17        84      44 00 00
     +20        84      50 00 00
     +60        85      78 00 00

     - 3        81      A0 00 00
     - 4        81      80 00 00
     - 5        82      B0 00 00
     - 7        82      90 00 00
     -12        83      A0 00 00
     -15        83      88 00 00
     -17        84      BC 00 00
     -20        84      B0 00 00
     -60        85      88 00 00


My question is
Code:
      HIGH-ORDER MANTISSA BYTE
     01.XXXXXX  Positive mantissa.
     10.XXXXXX  Negative mantissa.
     00.XXXXXX  Unnormalized mantissa.
     11.XXXXXX  Exponent = -128.

I can't understand 00.XXXXXX Unnormalized mantissa;
Especially I CAN'T UNDERSTAND 11.XXXXXX Exponent = -128.
What does them mean?
"http://www.6502.org/source/floats/wozfp1.txt" said
Code:
    In the Exponent:
    00 Represents -128

So, when both exponent=$00 and exponent=11.xxxxxx means Exponent;
But if exponent<>$00,exponent=11.xxxxxx, what is the Exponent?128?or?
And if exponent-$00,exponent<>11.xxxxxx,etc.

All of the three documents didn't given the details about 00.xxxxxx and 11.xxxxxx[/b]


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jul 12, 2004 9:28 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
Boy, I sure opened a can of worms by suggesting the Wozniak & Rankin routines, didn't I? Okay, here we go...

X1 is the exponent of FP1
M1 is the mantissa of FP1
M1+0 is the high byte of the mantissa
M1+1 is the middle byte of the mantissa
M1+2 is the low byte of the mantissa

Likewise for X2 and M2.

The high byte of the mantissa (M1+0):

00.XXXXXX represents an unnormalized positive mantissa
01.XXXXXX represents a normalized positive mantissa
10.XXXXXX represents a normalized negative mantissa
11.XXXXXX represents an unnormalized negative mantissa

(I'll get to the Exponent = -128 part later.)

So, what does unnormalized mean? All floating point representations are similar to scientific notation, including this representation. In scientific notation, a number is in the following form:

mantissa * 10 ^ exponent

The exponent is an integer. The mantissa starts with a non-zero digit, then the decimal point, then the rest of the digits. For example, 120 is:

1.20 * 10 ^ 2

If we could ignore the non-zero starting digit rule, 120 can be written as:

0.12 * 10 ^ 3

but that is not in scientific notation. 1.20 * 10 ^ 2 is normalized, 0.12 * 10 ^ 3 is unnormalized. Normalization is the process of converting an unnormalized to a normalized number, by shifting the decimal point and adjusting the exponent.

There is an exception to the non-zero starting digit rule: when the number is zero, the mantissa must be zero, so the starting digit must be zero.

For an N-digit mantissa (N=3 in the two examples above), we can express the mantisssa using an integer, M, as shown. The number is:

Code:
    M
---------- * 10 ^ exponent
10 ^ (N-1)


where 0 <= M < 10 ^ N. Note that the mantissa is unnormalized when 1 <= M < 10 ^ (N-1).

The FP representation is similar, but uses base 2 rather than base 10. If we treat X1 as an unsigned integer that ranges from 0 to 255 ($00 to $FF) and M1 as a 24-bit twos complement integer that ranges from -8388608 to 8388607, where -8388608 to -1 are $800000 to $FFFFFF and 0 to 8388607 are $000000 to $7FFFFF, then the number represented by FP1 is:

Code:
  M1
------ * 2 ^ (X1 - 128)
2 ^ 22


which is the same as:

M1 * 2 ^ (X1 - 150)

Example #1: X1 = $81 and M1 = $600000

$81 = 129 and $600000 = 6291456, so FP1 is 6291456 * 2 ^ (129 - 150) = 3

Example #2: X1 = $81 and M1 = $A00000

$81 = 129 and $A00000 = -6291456, so FP1 is -6291456 * 2 ^ (129 - 150) = -3

The mantissa is normalized when the upper two bits (bits 7 and 6) of the high byte (M1+0) are the same. When the high bit (i.e. bit 7) of the high byte is 0, the mantissa is positive, and when the high bit is 1, the mantissa is negative. One way to see normalization in action is to use the FLOAT routine.

To float 10000 ($2710):

store $27 at M1+0
store $10 at M1+1
store $00 at M1+2 (required by the FLOAT routine)

After a JSR FLOAT:

X1 is $8D (141) and M1 is $4E2000 (5120000)

and sure enough:

5120000 * 2 ^ (141 - 150) = 10000

To float -10000 ($D8F0):

store $D8 at M1+0
store $F0 at M1+1
store $00 at M1+2

After a JSR FLOAT:

X1 is $8D (141) and M1 is $B1E000 (-5120000)

and sure enough:

-5120000 * 2 ^ (141 - 150) = -10000

Note that when zero ($0000) is floated, after a JSR FLOAT, X1 is $00 and M1 is $000000. It doesn't really matter what the exponent is when the mantissa is zero, but the normalization loop at NORM1 shifts until the upper two bits of the high byte of the mantissa are unequal or X1 is zero. Since the former will never occur when the mantissa is zero, it exits once the latter case is true. Like scientific notation, the mantissa zero is an exceptional case.

The largest (i.e. most negative) normalized negative mantissa is $800000 (-2^23).
The smallest (i.e. closest to zero) normalized negative mantissa is $BFFFFF (-2^22 - 1)
The smallest (i.e. closest to zero) normalized positive mantissa is $400000 (2^22).
The largest (i.e. most positive) normalized positive mantissa is $7FFFFF (2^23 - 1).

The minimum exponent is $00 (0)
The maximum exponent is $FF (255)

So, a normalized negative number may range from:

-2^23 * 2 ^ (255 - 150) = -2^128

to:

(-2^22 - 1) * 2 ^ (0 - 150) = -2^-128 - 2^-150

A normalized positive number may range from:

2^22 * 2 ^ (0 - 150) = 2^-128

to:

(2^23 - 1) * 2 ^ (255 - 150) = 2^128 - 2^105

The largest negative mantissa is the largest normalized negative mantissa, and the largest positive mantissa is the largest normalized positive mantissa, so larger numbers are not representable. However, smaller numbers are representable, using unnormalized mantissa, specifically:

The smallest negative mantissa is $FFFFFF (-1)
The smallest positive mantissa is $000001 (1)

So, the smallest negative number is:

-1 * 2 ^ (0-150) = -2^-150

The smallest positive number is:

1 * 2 ^ (0-150) = 2^-150

So, a negative number may range from -2^128 to -2^-150.
A positive number may range from 2^-150 to 2^128 - 2^105.

The routines that return a floating point number (FADD, FCOMPL, FDIV, FMUL, FLOAT, FSUB, and NORM) will return an unnormalized number if the number is too close to zero to be represented as a normalized number. Note that when an unnormalized number is returned the exponent (i.e. X1) will be -128 ($00). (Bet you thought I forgot about the Exponent = -128!)

Here are three examples where the high byte of the mantissa returned is either 00.XXXXXX or 11.XXXXXX. Note that in all three cases, the inputs are normalized mantissa. I should also point out that I have carefully chosen these examples so that there is no swapping or shifting either before the mantissa are added, and after the manitissa are added, M1 (the mantissa of the result) is unchanged, so you can more easily follow along in the code.

Example #1: -3 + 3 = 0

Upon entry:

X1 = $81, M1 = $A00000
X2 = $81, M2 = $600000

JSR FADD returns with:

X1 = $00, M1 = $000000

Example #2: -2^-127 + 2^-128 = -2^128

Upon entry:

X1 = $00, M1 = $800000
X2 = $00, M2 = $400000

JSR FADD returns with:

X1 = $00, M1 = $C00000

Example #3: -1.25 * 2^-128 + 1.5 * 2^-128 = 2^-130

Upon entry:

X1 = $00, M1 = $B00000
X2 = $00, M2 = $600000

JSR FADD returns with:

X1 = $00, M1 = $100000

All clear now?

One other thing. The subtraction performed by FSUB is actually FP1 = FP2 - FP1. The documentation in the wozfp3.txt file is incorrect (there are a lot of errors in the documentation, in fact).

By the way, the Apple II had two BASICs. The first was known as Integer BASIC (it's "official" name was Apple BASIC) and was written by Steve Wozniak himself. The second, and more common, BASIC was known as Applesoft and was written by Microsoft (Apple contributed some Apple II-specific code, like graphics commands).

Applesoft was supplied (in ROM) starting with the II+ (the second machine in the Apple II line). Applesoft used floating point math (there were integer variables, but it converted them to FP to do math on them). EhBASIC is another example of a BASIC based on what might be called the "Microsoft model". EhBASIC uses 3-byte mantissa and Applesoft used 4-byte manitissa, but their FP representation is the same otherwise. In fact, many of EhBASIC's routines are similar if not identical to Applesoft's.

Integer BASIC, as you might guess from its name, used only integer math. It never used the floating point routines (known as the FP package) described in the wozfp3.txt file. You could access these via BASIC using POKE and CALL commands, but this was inconvenient to say the least. It was possible to write special routines to interface between BASIC and the FP package, and this was in fact done. (Until the II+, Integer BASIC was the only BASIC there was for the Apple II.) So there isn't an easy, built-in way to enter a FP number such as 0.125 directly (but you could easily use the FLOAT routine to float an integer) or print FP numbers from BASIC.

Incidentally, Integer BASIC was located at $E000-$F424 in ROM. There was a mini-assembler at $F500-$F63C. If you're paying careful attention, you'll notice that the FP package was located at $F425-$F4FB and $F63D-$F65D, and SWEET16 (also described in the Repository) was located at $F689-$F7FC, which is partly why they start at such strange addresses. (The $F800-$FFFF space contained I/O routines, the monitor program, and some other routines.) Integer BASIC, the FP package, the mini-assembler, and SWEET16 were all basically independent of one another, since none of them called routines in any of the others (all except the FP package used $F800-$FFFF routines, though).

Applesoft took up the entire $E000-$F7FF ROM space (and $D000-$DFFF also), so the mini-assembler, the FP-package, and SWEET16 had to be removed, unfortunately.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 12, 2004 4:41 pm 
Offline

Joined: Tue Jul 06, 2004 5:16 am
Posts: 11
Thanks for dclxvi's explanation.
I just found
Quote:
The subtraction performed by FSUB is actually FP1 = FP2 - FP1.
this evening.
And as you said, there are a lot of errors in the documentation, in fact.

As I had said at the beginning, I want to write a program in 6502 assembler language. This program must use floating-point mathematics.(Fadd, Fsub, Fmul, Fdiv,Fsqrt, etc.)

Can dclxvi gives me another example or some reference?
Thanks.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jul 13, 2004 3:56 am 
Offline

Joined: Thu Jul 24, 2003 8:01 pm
Posts: 24
For another version of the Woz FP routines with another explanation of the format, please see:

http://members.buckeye-express.com/mark ... FLOAT4.TXT

--
Paul
Monroe, Michigan USA


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: