You are here

Using inline assembly in a C program | 赛普拉斯半导体

Using inline assembly in a C program

最近更新:

2010 年 12 月 5 日

Assembly instructions can be used in a C program by using inline assembly using the "asm" keyword. 

Below is a sample code that uses inline assembly to print two strings on an LCD.  The code shows two different methods to use the inline assembly.

#include  "m8c.h"       // part specific constants and macros
#include "PSoCAPI.h"    // PSoC API definitions for all User Modules

char string1[]="PSoC3";
char string2[]="PSoC5";

void main()

{  
     LCD_Start();   
     LCD_Position(0,0);

     // Option-1 Using separate "asm" instructions
     asm("mov A,>_string1");
     asm("mov X,<_string1");
     asm("call LCD_PrString");

     // Option-2 Using a single "asm" instruction and \n character
     LCD_Position(1,0);
     asm("mov A,>_string2\n"     
         "mov X,<_string2\n"   
         "call LCD_PrString");
}