We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I'd like to branch to a certain Label if X=32 -- but only if (N=6 and O=6) or if (N=0 and O=0).
How must I construct that conditional?
Len
ps: Are there any limits to this? Actually, (N=6 and O=6) and (N=0 and O=0) are only two of some 173 conditions that I must state.
You can compile a C construct that does the same, and observe what the compiler does with minimum optimizations.
You can construct basically any level of complex conditional statement up to the limits of the memory in the board, the memory in the PC running the compiler or possibly any limitations claimed by the compiler (unless you use an assembler in which case only the memory in the ARM will limit your complexity).
If using C - just make sure to use the required number of parentheses to inform in which order the subexpressions should be evaluated.
Or if the expression gets too big - check if you can split it into multiple separate statements. Keeping it as a single expression has the advantage that the compiler can perform lazy evaluation.
See your problem as a logic tree. You either have a sequence of multiple "or" statements where each term ored may be a new complex subexpression. Or you have a sequence of "and" statements where each term may possibly be a new complex subexpression.
"I'd like to branch to a certain Label"
I take it that means you're writing in Assembler, then?
If you can't think how to do it directly in Assembler, then try drawing a flowchart, or writing it in pseudo-code; eg,
if N=6 { // Here, N must be 6 if O=6 { // Here, both N and O must be six } else { // Here, N is 6 but O is not } }
"some 173 conditions that I must state."
Sounds like a job for a Table...
Or, consider the good, old-fashioned techniques for logic minimisation...
Thanks Per Westermark and Andy Neil.
Very useful comments.
I think it's worth pointing out that parentheses don't necessarily affect the order of evaluation but do affect precedence. This is usually what is desired, but not always. To guarantee order of evaluation it is necessary to ensure that sequence points appear between expressions.