Electronic Components Datasheet Search
  English  ▼

X  

AN669 Datasheet(PDF) 1 Page - Microchip Technology

Part # AN669
Description  Embedding Assembly Routines into C Language Using a Floating Point Routine as an Example
PDF  7 Pages
Scroll/Zoom Zoom In 100%  Zoom Out
Manufacturer  MICROCHIP [Microchip Technology]
Direct Link  http://www.microchip.com
Logo MICROCHIP - Microchip Technology

AN669 Datasheet(HTML) 1 Page - Microchip Technology

  AN669 Datasheet HTML 1Page - Microchip Technology AN669 Datasheet HTML 2Page - Microchip Technology AN669 Datasheet HTML 3Page - Microchip Technology AN669 Datasheet HTML 4Page - Microchip Technology AN669 Datasheet HTML 5Page - Microchip Technology AN669 Datasheet HTML 6Page - Microchip Technology AN669 Datasheet HTML 7Page - Microchip Technology  
Zoom Inzoom in Zoom Outzoom out
 1 / 7 page
background image
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

ManufacturerPart #DatasheetDescription
logo
Silicon Laboratories
AN669 SILABS-AN669 Datasheet
521Kb / 14P
INTEGRATING SILICON LABS SiM3XXXX DEVICES INTO THE KEIL 關VISION짰 IDE
More results

Similar Description - AN669

ManufacturerPart #DatasheetDescription
logo
Motorola, Inc
MC68881 MOTOROLA-MC68881 Datasheet
1Mb / 48P
HCMOS Floating-Point Coprocessor
logo
Digital Core Design
DFPAU DCD-DFPAU Datasheet
137Kb / 5P
Floating Point Arithmetic Coprocessor
DFPCOMP DCD-DFPCOMP Datasheet
120Kb / 3P
Floating Point Comparator Unit
DFPMU DCD-DFPMU Datasheet
138Kb / 5P
Floating Point Coprocessor
logo
Texas Instruments
TMS320C6748 TI-TMS320C6748_1 Datasheet
2Mb / 254P
Fixed/Floating-Point DSP
logo
Freescale Semiconductor...
M68SMASM FREESCALE-M68SMASM Datasheet
240Kb / 4P
Assembly Language Toolset for Microcontrollers
logo
Fairchild Semiconductor
AN-5048 FAIRCHILD-AN-5048 Datasheet
65Kb / 3P
System Clock Distribution Example Using LVDS
logo
Texas Instruments
SNOA565 TI1-SNOA565 Datasheet
1Mb / 13P
AN-2177 Using the LMH6554 as a ADC Driver
logo
ATMEL Corporation
SAM9N12 ATMEL-SAM9N12_14 Datasheet
1Mb / 42P
One 128-Kbyte internal ROM embedding bootstrap routine
logo
STMicroelectronics
AN3178 STMICROELECTRONICS-AN3178 Datasheet
310Kb / 11P
Using a surface-mount inductor as an M24LRxx antenna
19-Jul-2010
More results


Html Pages

1 2 3 4 5 6 7


Datasheet Download

Go To PDF Page


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


Mirror Sites
English : Alldatasheet.com  |   English : Alldatasheet.net  |   Chinese : Alldatasheetcn.com  |   German : Alldatasheetde.com  |   Japanese : Alldatasheet.jp
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