home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Falcon 030 Power 2
/
F030_POWER2.iso
/
ST_STE
/
MAGS
/
ICTARI10.ARJ
/
ictari.10
/
ASSEMBLY
/
FLOAT_PT
/
FP_STOS.DOC
< prev
next >
Wrap
Text File
|
1994-05-29
|
15KB
|
311 lines
Using STOS Floating Point Routines in Machine Code Programs
===========================================================
By Peter Hibbs
It is sometimes useful to have floating point arithmetic routines in
machine code, unfortunately these are very difficult to write and there
is very little information available on how to write them. The STOS
Basic language has an extension library called FLOAT.BIN which contains
all the main floating point arithmetic routines as a binary file which
can be linked into STOS Basic when required. This document shows how to
use these routines in your own machine code programs. (Note that the
FLOAT102.BIN file which is on the ST User cover disk of Sept 1993 does
not work as it is a different version).
The routines available are as follows :-
1 Add two floating point numbers.
2 Subtract one floating point number from another.
3 Multiply two floating point numbers together.
4 Divide one floating point number into another.
5 Return the sine of a floating point number.
6 Return the cosine of a floating point number.
7 Return the tangent of a floating point number.
8 Return the exponential of a floating point number.
9 Return the naperien log of a floating point number.
10 Return the base 10 log of a floating point number.
11 Return the square root of a floating point number.
12 Convert an ASCII string into a floating point number.
13 Convert a floating point number into an ASCII string.
14 Convert a floating point number into an integer.
15 Convert an integer value into a floating point number.
16 Tests if two floating point numbers are equal.
17 Tests if two floating point numbers are not equal.
18 Tests if a floating point number is greater than another one.
19 Tests if a fp number is equal to or greater than another one.
20 Tests if a floating point number is less than another one.
21 Tests if a fp number is less than or equal to another one.
22 Return the arc sin of a floating point number.
23 Return the arc cos of a floating point number.
24 Return the arc tan of a floating point number.
25 Return the hyperbolic sin of a floating point number.
26 Return the hyperbolic cos of a floating point number.
27 Return the hyperbolic tan of a floating point number.
28 Return the integer part of a floating point number.
29 Return the value of a number raised to the power of another one.
The floating point operations use numbers in the IEEE 64 bit format
with a numerical range of 10E-307 to 10E+308. For more information on
the mathematical use of these routines please consult your STOS User
Guide.
To use the binary file in your own program first copy the file
FP_STOS.S into your source code and the file FLOAT.BIN from the STOS
language disk into your library folder on your hard disk/working disk.
The STOS library file is 'included' in the source file as a binary file
using the 'incbin' pseudo-op and is labelled as fp_data. You may also
need to set up the pathname of the 'incbin' pseudo-op as appropriate.
Note that the ninth instruction in the 'float_point' sub-routine
locates the function look-up table by adding $398C to the start address
of the data file. I don't know if there is more than one version of
this file in existence but if there is, this value may need to be
changed. The FLOAT.BIN file I am using has a size of 15976 bytes.
The FP_STOS.S file contains two sub-routines, 'init_float' initialises
the binary file by changing the longword addresses in conjunction with
the re-location table at the end of the data. This routine should be
called near the start of the program once to set up these addresses.
The 'float_point' sub-routine is called each time a floating point
operation is required. In most cases registers d0 and d1 hold one
number, registers d2 and d3 hold the second number (where applicable)
and register d4 holds the function number (0-28). The values returned
are always held in registers d0 and d1, no other registers are changed.
Note that the original STOS routines pass the numbers to the routines
in registers d1/d2 (or d3/d4) but return the results in registers d0
and d1 which makes it very messy to program. The start of the
'float_point' routines swaps the registers around so that they are
always in d0/d1 or d2/d3.
The standard IEEE format for the double precision floating point
numbers is as follows: registers d0.l and d1.l together form a complete
64 bit floating point number (registers d2 and d3 are formed the same
way). Register d0.l holds the bottom half (bits 0-31) and registers
d1.l holds the top half (bits 32-63). Bits 0-51 form the mantissa part,
bits 52-62 form the exponent part and bit 63 holds the sign. The exact
format of the numbers is not really important for the programmer (and I
don't know what it is anyway) since there are routines to convert from
ASCII or integer formats available. Just remember when moving data
about that the top and bottom halves of the numbers are copied to the
correct registers as longwords.
A typical program to multiply two floating point numbers in ASCII
format and display the results in ASCII format might look like this :-
main initialisation
.
bsr init_float initialise fp code
.
first convert ASCII numbers to fp format (if not already done)
.
lea first_no,a0 convert 1st No to fp
move #11,d4 ASCII to fp function
bsr float_point d0/d1=fp No
move.l d0,d2 and save in d2/d3
move.l d1,d3
lea second_no,a0 convert 2nd No to fp
bsr float_point d4=11 still, d0/d1=fp No
.
now multiply fp numbers together, result in d0/d1
.
move #2,d4 multiply function
bsr float_point result in d0/d1
.
now convert fp numbers back to ASCII for display
.
lea fp_buffer,a0 convert fp to ASCII
move #'3',d2 3 digits after decimal pt
move #12,d4 fp to ASCII function
bsr float_point result in fp_buffer
.
now display ASCII numbers, if required
.
move.l a0,-(sp) display results with
move #9,-(sp) c_conws BIOS call at
trap #1 current cursor posn
addq #6,sp
.
.
first_no dc.b '123.456',0 1st No=123.456
second_no dc.b '987.654',0 2nd No=987.654
.
fp_buffer ds.b 50 output buffer
.
The format for each function with the input and output parameters is
shown below :-
1 Add two floating point numbers.
ENTRY d0.l and d1.l hold first fp number
d2.l and d3.l hold second fp number
d4=0
EXIT d0.l and d1.l hold result of d0/d1 plus d2/d3
2 Subtract one floating point number from another.
ENTRY d0.l and d1.l hold first fp number
d2.l and d3.l hold second fp number
d4=1
EXIT d0.l and d1.l hold result of d0/d1 minus d2/d3
3 Multiply two floating point numbers together.
ENTRY d0.l and d1.l hold first fp number
d2.l and d3.l hold second fp number
d4=2
EXIT d0.l and d1.l hold result of d0/d1 times d2/d3
4 Divide one floating point number into another.
ENTRY d0.l and d1.l hold first fp number
d2.l and d3.l hold second fp number
d4=3
EXIT d0.l and d1.l hold result of d0/d1 divided by d2/d3
5 Return the sine of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=4
EXIT d0.l and d1.l hold sine value
6 Return the cosine of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=5
EXIT d0.l and d1.l hold cosine value
7 Return the tangent of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=6
EXIT d0.l and d1.l hold tangent value
8 Returns the exponential of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=7
EXIT d0.l and d1.l hold exponential value
9 Returns the naperien log of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=8
EXIT d0.l and d1.l hold naperien log value
10 Returns the base10 log of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=9
EXIT d0.l and d1.l hold base10 log value
11 Returns the square root of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=10
EXIT d0.l and d1.l hold square root value
12 Converts an ASCII string into a floating point number.
ENTRY a0=start address of buffer which holds value in ASCII
d4=11
EXIT d0.l and d1.l hold floating point number
13 Converts a floating point number into an ASCII string.
ENTRY d0.l and d1.l hold floating point number
d2 holds number of digits required after decimal point
as an ASCII character
d4=12
a0=start address of buffer (ensure buffer is big enough)
EXIT d0=number of characters (excluding the NUL chr) in string
a0=start address of output buffer
14 Converts a floating point number into an integer.
ENTRY d0.l and d1.l hold floating point number
d4=13
EXIT d0.l holds integer value
15 Converts an integer value into a floating point number.
ENTRY d0.l holds integer number
d4=14
EXIT d0.l and d1.l hold floating point value
16 Tests if two floating point numbers are equal.
ENTRY d0.l and d1.l hold first floating point number
d2.l and d3.l hold second floating point number
d4=15
EXIT d0=1 if numbers are equal or 0 if not
17 Tests if two floating point numbers are not equal.
ENTRY d0.l and d1.l hold first floating point number
d2.l and d3.l hold second floating point number
d4=16
EXIT d0=1 if numbers are not equal or 0 if they are
18 Tests if a floating point number is greater than another one.
ENTRY d0.l and d1.l hold first floating point number
d2.l and d3.l hold second floating point number
d4=17
EXIT d0=1 if 1st number is greater than 2nd number or 0 if not
19 Tests if a fp number is equal to or greater than another one.
ENTRY d0.l and d1.l hold first floating point number
d2.l and d3.l hold second floating point number
d4=18
EXIT d0=1 if 1st number is equal to or greater than 2nd number or
0 if not
20 Tests if a floating point number is less than another one.
ENTRY d0.l and d1.l hold first floating point number
d2.l and d3.l hold second floating point number
d4=19
EXIT d0=1 if 1st number is less than 2nd number or 0 if not
21 Tests if a fp number is less than or equal to another one.
ENTRY d0.l and d1.l hold first floating point number
d2.l and d3.l hold second floating point number
d4=20
EXIT d0=1 if 1st number is less than or equal to 2nd number or
0 if not
22 Returns the arc sin of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=21
EXIT d0.l and d1.l hold arc sin value
23 Returns the arc cos of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=22
EXIT d0.l and d1.l hold arc cos value
24 Returns the arc tan of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=23
EXIT d0.l and d1.l hold arc tan value
25 Returns the hyperbolic sin of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=24
EXIT d0.l and d1.l hold hyperbolic sin value
26 Returns the hyperbolic cos of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=25
EXIT d0.l and d1.l hold hyperbolic cos value
27 Returns the hyperbolic tan of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=26
EXIT d0.l and d1.l hold hyperbolic tan value
28 Returns the integer part of a floating point number.
ENTRY d0.l and d1.l hold floating point number
d4=27
EXIT d0.l and d1.l hold integer part value
29 Returns the value of a number raised to the power of another one.
ENTRY d0.l and d1.l hold first floating point number
d2.l and d3.l hold second floating point number
d4=28
EXIT d0.l and d1.l hold value of 1st number raised to the power of
the 2nd number
See also FP_MACRO.DOC file for macro definitions. Programmers should
note that although it would be OK to use the FLOAT.BIN file in their
own programs it could be a breach of copyright to use it in any
published programs. ICTARI accepts no responsibility for programs or
programmers who may be in breach of copyright in respect of these
routines.