home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / cbm / 5150 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  2.4 KB

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