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.
While debugging an if statement, why is the statement within the "if" always executed?
Lori HeustessC2000 Software Engineering
If you are debugging C2000 code that has "if" statements, it may seem like the "If" statements are always executed, no matter what the condition evaluates to. For example, consider this code:
void foo(int *p)
if(x == *p)
do stuff ...
In this case, it may seem like "do stuff" is always executing no matter what the "if" condition evaluates to. To understand what is happening here, look closely at the assembly instructions either in the CCS debugger or the assembly file generated by the compiler. If there is a MOVB instruction, then this is a conditional instruction, so the move will only happen if the condition is true - and thus the instruction itself does the check for the "if" statement. For example, consider the instruction MOVB *-SP, #0x10, EQ The 3rd operand in the MOVB instruction is the condition (EQ, NEQ, GT etc). This instruction will move the value 0x10 to stack only if the conditional equal is true. So the instruction itself will always execute (which is why things may look confusing when stepping through code in the debugger), but the outcome of the instruction is dependent on the condition. If the condition is true, then the move occurs, otherwise it does not. This instruction is single cycle, and much more efficient than using a branch.
We are glad that we were able to resolve this issue, and will now proceed to close this thread.
If you have further questions related to this thread, you may click "Ask a related question" below. The newly created question will be automatically linked to this question.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.