user3014816
user3014816

Reputation: 63

Compiler ignoring if statements

This is probably a simple problem so, I hope you can point me in the right direction.

I am writing a simple IO program in C. In the middle of my program, I have an if statement that is never executed. I realized this when I tried to put a break point within the if statement just to have it automatically removed and pushed down past the if statement block. Diving into the problem even further, the c compiler doesn't create any assembly code for my if statement. The following are my code snippet and assembly output.

CODE:

void sendData(unsigned int val1 ){
    P1OUT |= 1;
    if ((val1 & 0x8000 ) == 0x8000)
        wait(T1H);
    else
        wait(T1L);
    P1OUT &= ~(1);
}

*NOTE: Yes, I do have another function called wait that delays a number of cycles.

ASSEMBLY:

 13     P1OUT |= 1;
      sendData():
 c0ae:   D3D2 0021           BIS.B   #1,&Port_1_2_P1OUT
 18     P1OUT &= ~(1);
 c0b2:   C3D2 0021           BIC.B   #1,&Port_1_2_P1OUT

Thank you for your help.

Upvotes: 1

Views: 336

Answers (1)

AShelly
AShelly

Reputation: 35600

Wait is probably a busy loop that is getting optimized out. I believe there is an example of a good wait function that will survive optimization in the sample code.

See for example http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/18638.aspx

Upvotes: 6

Related Questions