KEIL C51环境下,汇编与C语言交叉编译的问题

1. 关于如何在C语言中嵌入汇编命令:

转载自:http://www.keil.com/support/docs/2308.htm

C51: GETTING INLINE ASSEMBLY TO WORK


Information in this article applies to:

  • C51 All Versions

QUESTION

How do I implement inline assembly in C51 using the ASM and ENDASM directives. I have read some of the knowledgebase articles relating to this problem, but I still cannot get it to work.

ANSWER

The following example program, MAIN.C, demonstrates some simple inline assembly.

void main(void){
   test();

#pragma asm
      JMP   $           ; endless loop
#pragma endasm
}

The following rules apply to C51 inline assembly:

  • To use #pragma ASM/ENDASM, you must set the Generate Assembler SRC File andAssemble SRC File source file compile options in µVision by right-clicking your source file name in the Project Workspace and selectingOptions for File.
  • When using the Generate Assembler SRC File and Assemble SRC File options in µVision, if there are no other C modules in your project, you must manually include the C51 Run-Time Library (C51S.LIB, C51M.LIB, or C51L.LIB).

MORE INFORMATION

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Thursday, July 17, 2008

 

2.  关于如何将C语言源文件转化为汇编文件:

--转载自:http://blog.21ic.com/user1/6088/archives/2010/68469.html

方法:(假设当前工程中只有一个C代码文件)

       第1步:新建一个工程,添加C文件,编译通过

       第2步:右击Keil界面中Project Workspace里的C文件名,选择‘Option for…’

       第3步:点击‘Generate Assembler SRC File’‘Assemble SRC File’两个三态复选框使它们呈高亮并勾选,点击确定

       第4步:将KEIL安装目录下C51/LIB/C51S.LIB(如果是SMALL模式)文件复制到工程目录下

       第5步:添加库文件C51S.LIB文件到工程,即右击‘Source Group 1’,选择‘Add Files to Group …’,在工程目录下选择C51S.LIB,点击打开

       (因为有了第3步中的操作,如果在这里不添加库文件,则编译生成的HEX文件不能被单片机正确执行,同时编译时会出现一个警告:

WARNING L1:UNRESOLVED EXTERNAL SYMBOL

SYMBOL:  ?C_STARTUP

无法识别?C_STARTUP这个标号,这个标号是在库文件中定义

       第6步:打开工程目录,可以看到新生成一个扩展名为.SRC的文件,将其扩展名改成.A51

       第7步:添加这个.A51文件到工程(这时候工程就包含C51S.LIB库文件,不然编译会产生第5步中说明的警告,且生成的HEX文件不能被单片机正确运行)

       第8步:重新编译,生成HEX文件,加载到单片机中,可以发现与C语言运行的现象是一致的

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值