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.

Calling Assembly from C - Need help to debug example from manual.

Calling Assembly from C is well documented in the C6000 Compiler User's Guide.  But it is not work with me. 

Code from page 166.
file main.c 
        extern "C" {
extern int asmfunc(int a); /* declare external as function */
int gvar = 4; /* define global variable */
}

void main()
{
int I = 5;
I = asmfunc(I); /* call function normally */

   ......

Compilation result 
"main.c", line 96: error: expected an identifier
"main.c", line 96: error: expected a ";"
"main.c", line 101: warning: parsing restarts here after previous syntax error
2 errors detected in the compilation of "main.c".

line 96      is    ----         extern "C" {

file test.asm

.global _asmfunc
.global _gvar
_asmfunc:
LDW *+b14(_gvar),A3
NOP 4
ADD a3,a4,a3
STW a3,*b14(_gvar)
MV a3,a4
B b3
NOP 5
Compilation result 
" test.a", line 1: error: expected a declaration
At end of source: warning: parsing restarts here after previous syntax error
1 error detected in the compilation of " test.a".

Additional Info

Code Compser Studio   version  3.3.81.6 

Code Genaration Tolls  version 6.08.

Are there anybody able to resolve this problem?

Thanks in advance!

Andrew

  • Andrew,

    I see a couple of potential issues here.

    First, what target is this?  Are you using ELF or COFF symbols?  If you are using ELF, don't use the "_" underscore to define the names in your assembly code. See: http://processors.wiki.ti.com/index.php/C6000_EABI_Migration 

    Additionally, and I can't tell for sure from your paste, but it looks like you are using the very first column in the assembly file for instructions.  (I could be wrong, but that's what it looks like from here.).  The first column is reserved for the start of labels.  You want to start your instructions in column 2 or farther right.  

    Finally, are you compiling for C or C++?  If for C, I think you need to leave out the extern "C" { } and just keep the stuff embedded in it.

    Regards,

    Dan