How to combine assembly code with C

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to combine assembly code with C

11,857件の閲覧回数
Jalen
Contributor I
I am new to code warrior and embedded design. How do i combine C code with assembly codes? Thx
ラベル(1)
0 件の賞賛
返信
4 返答(返信)

1,763件の閲覧回数
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 件の賞賛
返信

1,763件の閲覧回数
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 件の賞賛
返信

1,763件の閲覧回数
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 件の賞賛
返信

1,763件の閲覧回数
Jalen
Contributor I
Thanks loads to everyone for your help!
0 件の賞賛
返信