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.

CCS/MSP430G2553: Assembly/C

Part Number: MSP430G2553

Tool/software: Code Composer Studio

Hello,

Correct me if I'm wrong on the following code I was trying to translate from Assembly to C.

DelayTenths:

push.w  R4

jmp        LoopTest

Outerloop:

mov.w   #Delayloops, R4

jnz         Delayloop

dec.w     R12

Looptest:

cmp.w  #0,R12

jnz       Outerloop

pop.w   R4

ret

Here is what I came up with.  I would like some feedback.

Thank you.

#include <stdio.h>

int main ()
{
int outerloop, delayloop;
outerloop = 5;

while ( outerloop > 0)
{
for( delayloop = 1; delayloop > 0; delayloop--)
{
delayloop--;
}
outerloop--;
}
}

  • Hello Edgar,

    For posting code, please sue the advanced tab in order to format your code correctly. Once in the advanced posting menu, click on the </> symbol to post code so the web interface can format it correctly. I've modified your post above to reflect this change.

    I believe your conversion passes the "eye test", but if you just want to delay a certain amount of cycles, we do provide an intrinsic function for that. __delay_cycles( x ), where x is the number of cycles wanted to be delayed. Be careful with the delay cycle intrinsic and your loop above when it comes to optimization settings in the compiler. the compiler may see both of these as pointless loops and optimize it out. It is usually better when wanted to get a specific timing to either:

    • A) set an interrupt for a corresponding HW action
    • B) Poll a HW or SW flag for an action
    • C) setup a timer to interrupt for the appropriate timing