home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!munnari.oz.au!uniwa!peterb
- From: peterb@gu.uwa.edu.au (Peter Broadribb)
- Newsgroups: comp.sys.cbm
- Subject: Re: Floating point math in ML
- Date: 20 Dec 1992 06:11:18 GMT
- Organization: The University of Western Australia
- Lines: 54
- Message-ID: <1h12q6INNlgd@uniwa.uwa.edu.au>
- References: <Byun1x.H1y@cs.dal.ca>
- NNTP-Posting-Host: mackerel.gu.uwa.edu.au
-
- digdon@ug.cs.dal.ca (Mike Digdon) writes:
-
- MD> I am looking to do floating point math in machine language.
- MD> However, I don't really know where to begin.. Can anyone give me a
- MD> run-down on how this stuff works
-
- Are you using a C64 (or Vic-20?) If so, read on...
-
- Floating point numbers are stored in 5 or 6 bytes (6 bytes when being
- manipulated, 5 when stored in Ram). The number is represented by four
- bytes which make up the mantissa, plus a byte that holds the sign of the
- number (when it is being manipulated) plus a byte that holds the
- exponent. The exponent decides the position of the decimal point. When
- stored in Ram, the sign of the number is held by bit 7 of the most
- significant byte.
-
- When being manipulated, a flating point number is given by:
-
- 2(exponent-129)*(1+((m1 and 127)+(m2+(m3+m4/256)/256)/128) where m1=byte
- 1, m2 = byte 2 etc.
-
- When stored in Ram, multiply the above by (-1)^(m1 and 128).
-
- Floating point routines use the floating point accumulators (Fac 1 and
- Fac 2) which are at $61-$66 ($61 is the exponent and $66 the sign) and
- $69 to $6E ($69 is the exponent and $6E the sign).
-
- Here are some Basic Rom subroutines that you can SYS to:
-
- $B1AA takes a floating point number in the range -32767 to 32767 in FAC
- 1 and converts it to an integer in A and Y.
-
- $B7F7 takes a floating point number from 0-65535 in FAC 1 and converts
- it to an integer in $14 and $15.
-
- $BCCC converts the no. in FAC 1 to an integer and puts it back in FAC 1.
-
- $B391 converts an integer in A and Y in the range 0-32767 and turns it
- into a floating point number in FAC 1.
-
- $BDDD converts the no in FAC 1 to a string terminated by 0 (address in A
- and Y).
-
- $B7B5 converts a string (address in $22 and $23, length in A) to a
- number in FAC 1 (in other words, does a VAL).
-
- There are other more useful Basic Rom subroutines that you can use but I
- don't have the list with me at the moment.
-
- Cheryl Broadribb
- (via Peter Broadribb)
- --
- Peter Broadribb <peterb@gu.uwa.edu.au> Home Phone: +61 (9) 470 3261
- Box 856, Victoria Park WA 6100, Australia Work fax: +61 (9) 324 2030
-