SUMMARY
For this discussion only the 32-bit floating point multiply
is used. However, the same principles of embedded
assembly language routines into C code can be used
with other assembly language routines. A summary list
of a step- by- step process to embed assembly code
into your C code is below:
• Convert assembly register EQU equates to C vari-
able types such as unsigned int.
• Convert constants to #define in C.
• Place the assembly code into a subroutine using
#asm and #endasm
• To avoid paging issues in parts with multiple pro-
gram memory pages, force the code to an
address where it will not cross a page boundary.
For example:
#pragma memory ROM [MAXROM-0x800] @ 0x800;
• Macros and conditional assembly will have to be
rewritten in actual in-line assembly code. The
MPLAB-C compiler does not support these higher
level assembly options to the same degree as the
assembler, MPASM.
For your convenience, all the 32-bit floating point rou-
tines in application note AN575 are provided in a zip file
along with this application note. Each routine has been
separated to work as a stand-alone routine. There is a
AN669
separate file for each floating point routine. The files
may be included individually into your C code. Table 2
shows a list of all the files and routines included with
this application note.
TABLE 2: 32-BIT FLOATING POINT C FILES/FUNCTIONS INCLUDED WITH THIS APPLICATION
NOTE
AN575 Original
Assembly Routine/file *
Equivalent C
file/function
Purpose
-
FLO2432
FLO3232
FPD32
FPM32
FPA32
FPS32
INT3224
example.c
flo2432.inc
flo3232.inc
fpd32.inc
fpm32.inc
fpsa32.inc
fps32() 32-bit subtract
fpa32() 32-bit add
int3224.inc
The example main() routine calculating
the area given the radius. (uses fpm32)
24-bit integer to 32-bit floating point conversion
32-bit integer to 32-bit floating point conversion
32-bit floating point divide
32-bit floating point multiply
32-bit floating point add
32-bit floating point subtract
32-bit floating point to 24-bit integer conversion
INT3232
int3232.inc
32-bit floating point to 32-bit integer conversion
NRM3232
nrm3232.inc
32-bit normalization of unnormalized 32-bit
floating point numbers
NRM4032
nrm4032.inc
32-bit normalization of unnormalized 40-bit
floating point numbers
math16.inc
math16c.c
variables and constants need for the floating point functions
* Check Microchip web site and bulletin board for latest code.
© 1997 Microchip Technology Inc.
DS00669A-page 5