main() {
asm mov ah,2
asm mov bh,0
asm mov dl, 20
asm mov dh,10
asm int 10h/*调用BIOS中断设置光标位置*/
}
asm是C语言的关键字,用于在C语言中嵌入汇编指令,例如:\x0d\x0amain() { \x0d\x0aasm mov ah,2\x0d\x0aasm mov bh,0\x0d\x0aasm mov dl, 20\x0d\x0aasm mov dh,10\x0d\x0aasm int 10h/*调用BIOS中断设置光标位置*/ \x0d\x0a}asm文件是宏汇编文件,在c中调用方法如下:1、编写汇编程序:
#include <xc.inc>
GLOBAL _add声明全局可用的函数add
SIGNAT _add,4217 告诉编译器调用方式
PSECT mytext,local,class=CODE,delta=2
our routine to add to ints and return the result
_add:
W is loaded by the calling function
BANKSEL (PORTB) select the bank of this object
ADDWF BANKMASK(PORTB),w add parameter to port
the result is already in the required location (W)so we can just return immediately
RETURN
2、编写c语言程序
//声明调用外部的汇编程序
extern unsigned char add(unsigned char a)
void main(void) {
volatile unsigned char result
result = add(5) // 开始调用上面声明的汇编函数
}