參數(shù)資料
型號(hào): AN669
廠商: Microchip Technology Inc.
英文描述: Embedding Assembly Routines into C Language Using a Floating Point Routine as an Example
中文描述: 大會(huì)例程嵌入到C語(yǔ)言使用為例,浮點(diǎn)例程
文件頁(yè)數(shù): 1/7頁(yè)
文件大?。?/td> 84K
代理商: AN669
M
1997 Microchip Technology Inc.
DS00669A-page 1
INTRODUCTION
With the advent of MPLAB-C, the Microchip C-com-
piler, many PICmicro
users need to embed existing
assembly language routines and/or Microchip applica-
tion notes into C. This application note explains how to
embed an assembly language program into MPLAB-C,
version 1.10, and the issues therein. For example,
embedding interrupt save and restore must be done
using assembly language. Also, critical timing routines
may require assembly. The 32-bit floating point multiply
routine from AN575 is used to illustrate this process.
The remaining 32-bit floating point math routines are
embedded into individual C functions and are included
in the file accompanying this application note.
PROCEDURE
For this example, we’ll use a PIC16C74A with 4K
Program Memory, and 192 bytes of RAM.
Embedding assembly routines
In order to embed an assembly language routine in C
code place the
#asm
and
#endasm
the assembly routine. Furthermore, if this is a subrou-
tine, as is the case with the floating point multiply, then
embed the assembly code within a C function declara-
tion. The
#asm
construct is illustrated in Example 1 with
an excerpt from the 32-bit floating point routine.
directives around
Authors:
Rick Evans
Richard Fischer
Microchip Technology, Inc.
EXAMPLE 1:
#ASM, #ENDASM
CONSTRUCT
void fpm32(void)
{
#asm
FPM32 MOVF AEXP,W ;test for zero
BTFSS _Z ;arguements
MOVF BEXP,W
BTFSC _Z
GOTO RES032M
M32BNE0 MOVF AARGB0,W
XORWF BARGB0,W
MOVWF SIGN ;save sign
MOVF BEXP,W ;in SIGN
ADDWF EXP, F
MOVLW EXPBIAS-1
;...etc.
#endasm
}
Locating the Routine in Program Memory,
GOTO
s and
CALL
s
There are two 2K word pages of program memory in
the PIC16C74A. Program memory 000h to 7FFh is
page 0, 800h to FFFh is page 1. By making
C function, MPLAB-C initializes the appropriate page
bit in the PCLATH register before the subroutine call is
made. (See data sheet for more on PCLATH).
A potential problem could arise, however, if the new C
function,
fpm32(),
crosses the page boundary
(7FFh,800h). MPLAB-C does not insert code into the
assembly code to initialize the page bits (remember
MPLAB-C does take care of paging for function calls).
That means it is up to the programmer to either; 1) add
assembly language to initialize PCLATH appropriately,
or 2) move the entire
#asm
page. Option 1 involves more work. The programmer
must first compile the C code, then analyze the listing
file to see if the assembly function crossed a page
boundary. Finally, add the appropriate assembly lan-
guage to initialize PCLATH then re-compile. This solu-
tion is not desirable since every time new C code is
added to or deleted from the program, the routine,
fpm32()
can potentially move across the page bound-
ary. Option 2 is the simplest solution - to locate the C
function in a single page.
fpm32()
a
function within a single
Embedding Assembly Routines into C Language Using a Floating Point
Routine as an Example
AN669
相關(guān)PDF資料
PDF描述
AN754 Understanding Microchip’s CAN Module Bit Timing
AN795 Voltage-to-Frequency/Frequency-to-Voltage Converter
AN80196CA ADVANCED 16-BIT CHMOS MICROCONTROLLER WITH INTEGRATED CAN 2.0
AN80196CB ADVANCED 16-BIT CHMOS MICROCONTROLLER WITH INTEGRATED CAN 2.0
AN87196CA ADVANCED 16-BIT CHMOS MICROCONTROLLER WITH INTEGRATED CAN 2.0
相關(guān)代理商/技術(shù)參數(shù)
參數(shù)描述
AN670 制造商:SILABS 制造商全稱:SILABS 功能描述:PRECISION32a?¢ MCU DEVELOPMENT KIT QUICK-START GUIDE
AN6701 制造商:PANASONIC 制造商全稱:Panasonic Semiconductor 功能描述:Temperature Sensor IC
AN6701S 制造商:PANASONIC 制造商全稱:Panasonic Semiconductor 功能描述:Temperature Sensor IC
AN671 制造商:STMICROELECTRONICS 制造商全稱:STMicroelectronics 功能描述:Prevention of Data Corruption in ST6 On-Chip EEPROM
AN6713 制造商:Panasonic Industrial Company 功能描述:IC