简体   繁体   中英

merging assembly and C in mplab

I want use a procedure written in assembly for PIC in my c code in MPLABX. is there a way I can do this. I have searched over the internet but can't find anything helpful on this.

If you are using a 16-bit PIC, see 8.3 MIXING ASSEMBLY LANGUAGE AND C VARIABLES AND FUNCTIONS in MPLAB® C30 User's Guide .

EXAMPLE 8-2: CALLING AN ASSEMBLY FUNCTION IN C

  /* ** file: call1.c */ extern int asmFunction(int, int); int x; void main(void) { x = asmFunction(0x100, 0x200); } 

The assembly-language function sums its two parameters and returns the result.

  ; ; file: call2.s ; .global _asmFunction _asmFunction: add w0,w1,w0 return .end 

Parameter passing in C is detailed in Section 4.12.2 “Return Value” . In the preceding example, the two integer arguments are passed in the W0 and W1 registers. The integer return result is transferred via register W0. More complicated parameter lists may require different registers and care should be taken in the hand-written assembly to follow the guidelines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM