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.
Dear Sir:
I am new to the CCS6 IDE. I am using CCS5, MSP430F5529 Launchphad , and I am trying to call an assembly language function from the C integrated development environment.
I am using as a guide I am using a Texas Instruments publication, The MSP430 Optimizing C/C++ Compiler User's Guide, SLAU132j. I have posted a link to the publication for your convenience below:
http://www.ti.com/lit/ug/slau132j/slau132j.pdf
Please go to page 127.
I have copied and pasted the code below as a guide as a reference for out discussion:
The C program that calls the assembly language function:
extern "C" {
extern int asmfunc(int a); /* declare external asm function */
int gvar = 0; /* define global variable */
}
void main()
{
int var = 5;
var = asmfunc(var); /* call function normally */
The called assembly language function:
.global asmfunc
.global gvar
asmfunc:
MOV &gvar,R11
ADD R11,R12
RET
I believe this discussion would be fruitful if someone could, first, get this program working and reply with working code that I can directly cut and paste directly into CCS6 because there are a lot of problems if one copies and pastes the code directly from the TI publication.
For example, the compiler does not like the extern C {} method of coding (this can be remedied by not writing the code in shorthand) and the assembly language program does not appear to accept instructions such as ADD without a bit length appended to it (for example ADD.w) . I could go on and on with all the small problems I have encountered and if we went over every little problem this discussion would take an unreasonably long time.
Therefore, first, sending me the working code would be efficient. It is possible that, maybe, my compiler settings are not correct, in addition to, the incompatible format of code that I have been trying to work with. I would like to look into this first because I have encountered some linking errors when I managed to get parts of the code to compile.
Can someone please help me get this program working so that I can step through the program? Thank you for your consideration.
Try these two files. Most important difference is the use of RETA (instead of RET) instruction. Note that C function calls use the CALLA instruction.
Also note that the extern "C" is necessary only if you are mixing C++ with C code.
Dear Quark;
Thank you for offering your code. You wrote a great program. Your efforts were greatly appreciated.
I got your code working on CCS6.
However, there were some modifications that needed to be made and I will outline them below:
CCS6 will either lose track of the program (can't step through the program), or the compiler will otherwise output an error message when this line of code is inserted :
PM5CTL0 &= ~LOCKLPM5; // Remedy: Comment out or delete this line of code
An interesting thing also happened when I tried to cut and paste your assembler program into the .asm template that is offered by CCS6. I got this error message:
"./lnk.cmd", line 48: error #10099-D: program will not fit into available memory. placement with alignment fails for section ".reset" size 0x4 . This should not have happened because this assembly program uses such a small amount of memory.
However, the program runs fine if you open and copy the .asm program that you wrote into the project folder.
I have cut and pasted the CCS6 template program below and, hopefully, a TI engineer will offer us some feedback as to the source of the error message and how to remedy the error. (Note: No matter where I placed the .global declarations in the program I still received the same error message). The template and program:
;-------------------------------------------------------------------------------
; MSP430 Assembler Code Template for use with TI Code Composer Studio
;
;-------------------------------------------------------------------------------
.cdecls C,LIST,
"msp430.h" ; Include device header file
;-------------------------------------------------------------------------------
.text ; Assemble into program memory
.retain ; Overide ELF conditional linking
; and retain current section
.retainrefs ; Additionally retain any sections
; that have references to current section
; .global asmfunc
; .global gvar
;-------------------------------------------------------------------------------
RESET
mov.w #__STACK_END,SP ; Initialize stackpointer
StopWDT
mov.w #WDTPW|WDTHOLD,&WDTCTL ; Stop watchdog timer
;-------------------------------------------------------------------------------
; Main loop here
;-------------------------------------------------------------------------------
.global asmfunc
.global gvar
asmfunc:
MOV &gvar,R11
ADD R11,R12
RETA
;-------------------------------------------------------------------------------
; Stack Pointer definition
;-------------------------------------------------------------------------------
.global __STACK_END
.sect .stack
;-------------------------------------------------------------------------------
; Interrupt Vectors
;-------------------------------------------------------------------------------
.sect ".reset" ; MSP430 RESET Vector
.short RESET
**Attention** This is a public forum