您的位置:首页 > 编程语言

C51程序中使用汇编代码

2006-04-19 22:59 363 查看
KEIL公司的uVision2 V2.40 自带的C51.pdf如是说:





ASM / ENDASM
Abbreviation: None.
Arguments: None.
Default: None.
μVision2 Control: This directive may not be specified on the command line.
Description: The ASM directive signals the beginning of a block of
source text to merge into the .SRC file generated using the
SRC directive.
This source text can be thought of as in-line assembly.
However, it is output to the source file generated only when
using the SRC directive. The source text is not assembled
and output to the object file.
In μVision2 you may set a file specific option for C source
files that contain ASM/ENDASM sections as follows:
 Right click on the file in the Project Window – Files tab
 Choose Options for… to open Options – Properties
page
 Enable Generate Assembler SRC file
 Enable Assemble SRC file.
With this setting, μVision2 generates an assembler source
file (.SRC) and translates this file with the Assembler to an
Object file (.OBJ).
The ENDASM directive signals the end of the source text
block.
NOTE
The ASM and ENDASM directives can occur only in the
source file, as part of a #pragma directive.

其实这样做不行,编译器将报告 C51代码中的库函数调用找不到目标模块:
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
SYMBOL: _PUTCHAR
MODULE: downmsg.obj (DOWNMSG)
除非关闭代码管理属性中的生成SRC文件的选项,而这时,代码中directive(宏指令?)#pragma asm ...#pragma endasm 又将被报告为需要打开SRC选项。

根据C51/assembly 混合编程的网络信息,在C51中调用汇编模块时,需要将KEIL/C51/LIB/C51S.LIB文件加入工程项目中一起编译,结果发现在C51代码中宏指令方式嵌入汇编代码时,也需要显式的将使用到的库函数obj(C51S.lib)加入编译项目中!——难道SRC选项跟库函数路径冲突??失效了??
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: