This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

c语言调用汇编的问题



最近在学着用dsp2000编写C程序,想在C语言中调用汇编语句段,例如_FUNCTION__U16

在fun.asm文件中:

.include "fun.inc"

.def _FUNCTION_U16

_FUNCTION_U16:
             MOVU ACC,@AA             
             RPT #15                      
           ||SUBCU ACC,@BB
             MOV @CC,ACC                      
             LRETR

........

想在fun.inc文件中定义:

AA.   set         AR7
BB.  set         AR6
CC.  set         AR5

.....

想在C语言中引用后缀名inc文件

#include "fun.inc"

long bb;

long cc;

void functiontest()

{

AA = 2;

BB = 3;

FUNCTION_U16( );

cc = CC;

}

......

编译的时候,提示fun.inc文件有“error: this declaration has no storage class or type specifier。error: unrecognized token”

请问怎么解决编译错误?

多谢多谢!

  • 这样包含应该是有误的 

    #include "fun.inc"

     

  • 1. fun.inc 命名有问题,应该是fun.h

    2. 如果里面是C语言写的头文件,那就应该用.cdecls指令来进行引用。

  • 在fun.asm文件中:

    .cdecls "fun.h"

    .def _FUNCTION_U16

    _FUNCTION_U16:
                 MOVU ACC,@AA             
                 RPT #15                      
               ||SUBCU ACC,@BB
                 MOV @CC,ACC                      
                 LRETR

    在fun.h中定义

    #define AA        AR7
    #define BB        AR6
    #define CC        AR5

    在test.C文件中

    #include "fun.h"

    long bb;

    long cc;

    extern Uint16 AA;

    extern Uint16 BB;

    extern Uint16 CC;

    void functiontest()

    {

    AA = 2;

    BB = 3;

    FUNCTION_U16( );

    cc = CC;

    }

    ......

    编译出错提示:

    <Linking>

     undefined first referenced                           
      symbol       in file                                
     --------- ----------------                           
     _AR5      ./source/test.obj
     _AR6      ./source/test.obj
     _AR7      ./source/test.obj

    error: unresolved symbols remain

    error: errors encountered during linking; "test.out" not built

    请问怎么解决编译错误?

    多谢多谢!

  • 请高手帮我解决一下!

  • 表示压力山大,不太懂汇编。。。

    请问有相关汇编的资料么?我最近也在学,可否共享下?谢谢

  • 不要把define 跟全局变量定义等同一起。

    define 只是纯粹的在编译的时候把AA替换为ARx。

    另外,你为什么会觉得你的text.c能够识别AR5啊?AR5是什么啊,编译器不知道。

    Eric

  • 我的本意是想用AA代替AR7(dsp辅助寄存器),在C文件中通过给AA赋值来给AR7寄存器赋值,作为汇编函数的输入;把汇编函数中计算的结果CC,传给C文件中使用。请问如何定义汇编函数输入(AR6,AR7),把汇编函数计算的结果AR5返回给C文件中使用?