原创 C51混和编程

2007-7-10 13:41 4730 9 6 分类: MCU/ 嵌入式
 

pdf

When writing single-file projects using in-line assembly, the linker produces
the following warning:

*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:    ?C_STARTUP
    MODULE:    main.obj    (MAIN)


For example, the following program:

#include

void main()  {
  unsigned char i;
  unsigned char cur[20];

  for( i = 0; i < 20; i++)  {
    #pragma asm
      mov  A, x;
      movc  A, @A+PC;
    #pragma endasm
  }
}


When compiled, assembled, and linker in uVision2, generates the warning above.
To translate this file, you must enable the following 2 checkboxes in Project -
Options for file - Properties:

Generate Assembler SRC File
Assembler SRC File

CAUSE

When you compile all your C modules with the SRC directive and the assembler,
the linker does not detect the required C run-time libraries (because the files
were assembled). In this case, you must add the libraries to your project
manually.

RESOLUTION

For a project in the SMALL memory model that uses no floating point arithmetic,
C51S.LIB is required.

For a project in the LARGE memory model that uses floating-point, C51FPL.LIB
and C51L.LIB are required.

If a project uses floating arithmetic, it is important that C51FPx.LIB is
included before the standard library file C51x.LIB. Otherwise printf and scanf
will not work with floating-point numbers.

//----------------------------------------------------------------------------------------------------

 


一、混合编程

 1、模块内接口:
使用如下标志符:
#pragma asm
  汇编语句
#pragma endasm

注意:如果在c51程序中使用了汇编语言,注意在Keil编译器中需要激活Properties中的“Generate Assembler SRC File” 和“Assembler SRC File ”两个选项

来个实例吧:
#i nclude
void main(void)
{
P2=1;
#pragma asm
    MOV R7,#10
DEL:MOV R6,#20
    DJNZ R6,$
    DJNZ R7,DEL
#pragma endasm
P2=0;
}

另:

1、把"xx.c"加入工程中,右击"xx.c"选择“options for file"xx.c" 选择“Generate Assembler SRC File”和“Assemble SRC File”打上黑勾有效;

2、根据选择的编译模式,把相应的库文件象加"xx.c"一

样加入工程中并放在"xx.c"下面,如smail模式下选"keil\c51\lib\c51s.lib"加入工程中,如果要进行浮点运算把"keil\c51\lib\c51fpl.lib"也加入工程中。

在 Keil 安装目录下的 \C51\LIB\ 目录的LIB 文件如下:

C51S.LIB - 没有浮点运算的 Small model
C51C.LIB - 没有浮点运算的 Compact model
C51L.LIB - 没有浮点运算的 Large model
C51FPS.LIB - 带浮点运算的 Small model
C51FPC.LIB - 带浮点运算的 Compact model
C51FPL.LIB - 带浮点运算的 Large model

3、在"xx.c"头文件中加入优化:比如#pragma OT(4,speed)

4、在"xx.c"中加入汇编代码 

                             #pragma ASM

                             ;Assembler Code Here

                             #pragma ENDASM

5、编译生成xx.hex

注意:

      没有做第一步会有如下警告:'asm/endasm' requires src-control to be active

      没有做第二步会有如下警告:UNRESOLVED EXTERNAL SYMBOL;

                                REFERENCE MADE TO UNRESOLVED EXTERNAL等

      没有做第三步会有如下警告:UNDEFINED SYMBOL (PASS-2)
PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
9
关闭 站长推荐上一条 /3 下一条