User`s guide
Inline Assembly Language and Intrinsics
Inline Assembly Language
139Targeting MC56F83xx/DSP5685x Controllers
add x0,y0
// int result returned in y0
rts
}
Listing 7.7 shows the C calling statement for this inline-assembly-language function.
Listing 7.7 Sample Code - Calling an Inline Assembly Language Function
int x = 4, y = 2;
y = add_int( &x, &y ); /* Returns 6 */
Calling Pure Assembly Language Functions
If you want C code to call assembly language files, you must specify a SECTION
mapping for your code, for appropriate linking. You must also specify a memory
space location. Usually, this means that the ORG directive specifies code to program
memory (P) space.
In the definition of an assembly language function, the GLOBAL directive must specify
the current-section symbols that need to be accessible by other sections.
Listing 7.8
is an example of a complete assembly language function. This function
writes two 16-bit integers to program memory. A separate function is required for
writing to P: memory, because C pointer variables allow access only to X: data
memory.
The first parameter is a short value and the second parameter is the 16-bit address.
Listing 7.8 Sample Code - Creating an Assembly Language Function
;”my_asm.asm”
SECTION user ;map to user defined section in CODE
ORG P: ;put the following program in P
;memory
GLOBAL Fpmemwrite ;This symbol is defined within the
;current section and should be
;accessible by all sections
Fpmemwrite:
MOVE Y1,R0 ;Set up pointer to address
NOP ;Pipeline delay for R0
MOVE Y0,P:(R0)+ ;Write 16-bit value to address