| Electronic Components Datasheet Search |
|
AN669 Datasheet(PDF) 1 Page - Microchip Technology |
|
|
|||||||||||||||||||||||||||||
AN669 Datasheet(HTML) 1 Page - Microchip Technology |
|
1 / 7 page ![]() 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 directives around 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. Authors: Rick Evans Microchip Technology, Inc. Richard Fischer 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 CALLs 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 fpm32() a 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 function within a single 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. Embedding Assembly Routines into C Language Using a Floating Point Routine as an Example AN669 |
Similar Part No. - AN669 |
|
Similar Description - AN669 |
|
|
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |