This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Compiling error for calling assembly function from C

Dear C8051 Gurus and Experts.

New to the C8051 so just bought the C8051F120DK (Development Board) to learn. My question is can the C51 compiler V7.05 which comes with the development kit, handles well when you mixed C with assembly code? Here, mixing C with assembly code means that my Main function is written in C and it called a subroutine (in a seperate file) which is written in assembly.

Here is how I tried to do it (2-step process).

step 1: Wrote a skeleton code for the subroutine in C and compiled it with the main function using directive #pragma src to obtain the assembly code.
in the main program:

#pragma src
.
.
<include FIR.h>
.
.
external short FIR(short *databuf_ptr,short *hbuf_ptr,int Taps);
.
.
main(void)
.
FIRout = FIR(&databuf[0],&hbuf[0],Taps1]);
.
end

in the subroutine (FIR.h file)

short FIR(short*databuf_ptr,short *hbuf_ptr, int Taps)
{
short firout;

return firout;
}

I compiled the main function with the subroutine to generate the assembly code.

Step 2. Went into the assembly code generated in step 1 and cutout the assembly code section for the FIR subroutine and pasted on a blank sheet in the notepad. Saved the the sheet with the assembly code (for the FIR subroutine only.) as FIR.asm

Then went back to the Main routine and replaced the #include <FIR.h> with include <FIR.asm> and removed the #pragma src. Ran the compiler again and got an error from the compiler. The compiler points to the first line of the assembly code in the subroutine FIR.asm and said that 'missing ";" before "?"'. Have followed advices on this thread and in the knowledge base but it has not help. Your help and advice is much appreciated.

Thanks,

  • Then went back to the Main routine and replaced the #include <FIR.h> with include <FIR.asm>

    There's your error. You shouldn't usually #include one source file into another (except if it's a header file), and you absolutely never include an entire assembly source file into a C source file. You translate each of them separately, instead, then pass both to the linker to be combined into a single program.

    Please learn how to work with programs consisting of multiple C source files before you venture into the land of linking C and asm source files together.

  • "The compiler points to the first line of the assembly code..." (my emphasis)

    Of course it does!

    A 'C' compiler understands only 'C' source code - it does not understand assembly source code!

    You need to use the Assembler to translate assembly source code!

    (In uVision this is easy - you just add the assembly source file to the project, and it automatically knows to use the assembler to translate it).

    As Hans-Bernhard says, you need to go back to basics and review how the toolchain works.
    You have read the uVision Getting Started guide, haven't you...?

  • Will read the tool chain document now. Thank you gentlemmen for pointing me in the right direction.

    Regards,