Hi
I am working on code composer studio as IDE. I want to change program counter or use jump command . But when add asm("JMP 0x9000"); command, .out file is not created by compiler. Which configurations needs for compile mixed asm and c ?
Thanks.
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.
Hi
I am working on code composer studio as IDE. I want to change program counter or use jump command . But when add asm("JMP 0x9000"); command, .out file is not created by compiler. Which configurations needs for compile mixed asm and c ?
Thanks.
You compile it like any other .c file.
What exactly are you doing? What happens then?
void main (void)
{
unsigned char received_packet_cnt = 0;
WDT_A_hold(WDT_A_BASE);
STOP_WDT(WDT_A_BASE);
i2c_receive_init();
asm("MOV #9000h, PC");
while (1);
}
this is my main. I want to init i2c then i want to jump 0x9000. when i compile this code i didnt take any error but .out file is not created. when i make command asm("MOV #9000h, PC"); line, .out file is created. I want to create out file.
I'm not sure why CCS isn't producing an error when it fails to output the .out file. I'd have expected to see something in the output window explaining what had gone wrong. I'll see if I can replicate that issue later today.
By the way, if you just want to run some assembly code from a C project there's another way to set things up.
Instead of jumping to a hardcoded address from a C function with inline assembly you can set up a global symbol in your assembly code which can be called from C like any other function. That way the linker can put the assembly code wherever it likes and the C source doesn't need to change to match.
I've got an example at home that I can post later, but I think it's just a case of putting ".global functionName" before the assembly code you want to jump to, and having a matching function protoype of "void functionName();" in a C header. Then you can call functionName() like any other C function. The assembly code needs to follow the rules of the C compiler's calling convention, which is given on page 130 of MSP430 Optimizing C/C++ Compiler User's Guide.
Ok, I've tried building a cut-down version of the code posted earlier and get this console window output:
warning: "../main.c", line 18: Assembly statement "MOV #9000h, PC" creates a label, which may not be what was intended. Use a colon after a label or a space before a non-label to silence the warning. warning: "../main.c", line 18: Assembly statement "MOV #9000h, PC" creates a label, which may not be what was intended. Use a colon after a label or a space before a non-label to silence the warning. [...], ERROR! at line 55: [E0002] Illegal mnemonic specified MOV #9000h, PC Errors in Source - Assembler Aborted 1 Assembly Error, No Assembly Warnings >> Compilation failure gmake: *** [main.obj] Error 1 gmake: Target `all' not remade because of errors. **** Build Finished ****
The assembly fails because "MOV #9000h, PC" is parsed as a label "MOV" and a mnemonic "#9000h", which isn't legal. To fix the errors you need to have a space or tab character at the start of the inline assembly string like so: asm(" MOV #9000h, PC");
Surprisingly CCS doesn't show these errors in the "Problems" window where compile errors normally appear. I'll see if there's anything about this on the CCS forum, as that's not right.
EDIT: The missing errors in the "Problems" view is a known issue, and is due to be fixed in CCS 6.1.3.
Also, here's an example of how to call assembly from C, for a simple function call with no parameters:
; ExampleFunction.asm .text .def ExampleFunctionName ExampleFunctionName: nop ; <-- replace this nop with the actual asm code ret ; return to c
/* TestFunction.c */
#include <msp430.h>
/* Prototype of ASM function taking no parameters and returning nothing */
void ExampleFunctionName(void);
void main(void)
{
WDTCTL = WDTPW | WDTHOLD;
ExampleFunctionName();
}
Make sure the is space char's before the asm word
try asm("br #0x9000");
Or do it in C
typedef void (*asmfuncpnt)(void); asmfuncpnt const asmpnt = (asmfuncpnt) 0x9000; asmpnt(); // uses Call so return address is stored on stack but can be ignored
**Attention** This is a public forum