How to combine assembly code with C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to combine assembly code with C

11,854 Views
Jalen
Contributor I
I am new to code warrior and embedded design. How do i combine C code with assembly codes? Thx
Labels (1)
0 Kudos
Reply
4 Replies

1,760 Views
bigmac
Specialist III
Hello and welcome to the forum.
 
You can incorporate assembly instructions directly within a C function, using "inline assembly".  You should find further information within the manual for the compiler.  The format for some of the instructions will differ from that for "standard" assembler.
 
Alternatively, you could create a separate file, written in "standard" (relocatable) assembler, and consisting of assembly sub-routines.  However, parameter passing to these routines will need to match the requirements of C for the MCU you are using, and a prototype for each routine will need to be visible from the C module(s).  Perhaps the simplest method of handling parameters for the assembly routines is via global variables.
 
Regards,
Mac
 
0 Kudos
Reply

1,760 Views
Alban
Senior Contributor II
Hello,

The post referenced after is showing how to do INLINE assembly.
You create a asm{} and put your assembly code in the curly brackets:
/message?board.id=CFCOMM&message.id=235 http://forums.freescale.com/freescale/board/message?board.id=CFCOMM&message.id=235" target="_blank
Look for "asm {" as a keyword in the search at the bottom of forum pages.

Cheers,
Alban.
0 Kudos
Reply

1,760 Views
CrasyCat
Specialist III
Hello
 
Just to close the loop here, the HC08 or HC12 assembler manual include a section around mixing C and assembly in an application.
 
  - Depending on the CPU you are using open the file {Install}\Help\PDF\Assembler_HC08.pdf or
    {Install}\Help\PDF\Assembler_HC12.pdf.
  - For HC08 go to chapter "Using the HC(S)08 Assembler", section
     "Mixed C and Assembler application"
  - For HC12 go to chapter "Using the HC(S)12 Assembler", section
     "Mixed C and Assembler application".
 
 
CrasyCat
0 Kudos
Reply

1,760 Views
Jalen
Contributor I
Thanks loads to everyone for your help!
0 Kudos
Reply