What happens when we write delay instruction twice continuously in an MSP430

msp430

What happens when we write a delay instruction twice continuously in MSP430 code as follows:

void delay();
{
    __delay_cycles(1000); 
    __delay_cycles(1000);
}

For 1 cycle delay time is 1ms if we add another what happens?

Best Answer

__delay_cycles(const int) is an intrinsic function. That means the compiler substitutes predesigned assembly for the function, and it is not optimized in any way by the optimizer in the compiler. Inserting it twice means that the delay is doubled, and code wise, two sets of the same code run back to back. It is not optimized to be a longer delay. A subtle but key difference.

Keep in mind, this is the same reason __delay_cycles only takes a constant, and not a variable. It is analyzed at compile time and cannot function as a run time function.