Question: The ARMv7-M instruction set has a feature called conditional execution for instructions The ARM manual defines it as follows: Conditionally executed means that the instruction


The ARMv7-M instruction set has a feature called "conditional execution" for instructions The ARM manual defines it as follows: Conditionally executed means that the instruction only has its normal effect on the programmers' model operation, memory and coprocessors if the N, Z, C and V flags in the APSR [Application Program Status Register satisfy a condition specified in the instruction. If the flags do not satisfy this condition, the instruction acts as a NOP, that is, execution advances to the next instruction as normal, including any relevant checks for exceptions being taken, but has no other effect. Let me paraphrase. When an ARM implementation runs the instruction CMP, that sets a set of flags. Those flags together encode particular results of the comparison, such as equality or less- than. For the purposes of this question, those flags remain set until another CMP instruction is executed. Future instructions can be "conditionally executed" based on the flags set by CMP: the programmer can designate a conditionally-executed instruction by appending a condition (such as EQ for equality or LT for less-than) to the opcode for that instruction. The conditionally executed instruction only runs if the flags satisfy the designated condition. (Of course, if no condition is specified, the instruction runs unconditionally.) In ARM, branch instructions also use the result of CMP instructions (as opposed to MIPS, where BEQ both executes the comparison and branches based on it) As an example, consider the following code sequence that checks if r3 is zero and if not, performs an add operation. CMP r3, #0 BEQ skip // compare r3 to zero // if the previous CMP indicated equality, // jump to "skip'" ADD r0, rl, r2 // r0 - rl + r2 skip: . . . A clever ARM programmer can rewrite this using conditional execution // compare r3 to zero CMP r3 , #0 ADDNE r0, r1, r2 // only if the previous comparison was // not-equal, compute r0-r1 r2 Note that ADDNE is an ADD instruction with the condition NE (not equal), where the condition was set on the previous CMP (comparison) operation. Other conditions that you may find useful EQ (equal), GT (greater-than), and LE (less-than-or-equal) The ARMv7-M instruction set has a feature called "conditional execution" for instructions The ARM manual defines it as follows: Conditionally executed means that the instruction only has its normal effect on the programmers' model operation, memory and coprocessors if the N, Z, C and V flags in the APSR [Application Program Status Register satisfy a condition specified in the instruction. If the flags do not satisfy this condition, the instruction acts as a NOP, that is, execution advances to the next instruction as normal, including any relevant checks for exceptions being taken, but has no other effect. Let me paraphrase. When an ARM implementation runs the instruction CMP, that sets a set of flags. Those flags together encode particular results of the comparison, such as equality or less- than. For the purposes of this question, those flags remain set until another CMP instruction is executed. Future instructions can be "conditionally executed" based on the flags set by CMP: the programmer can designate a conditionally-executed instruction by appending a condition (such as EQ for equality or LT for less-than) to the opcode for that instruction. The conditionally executed instruction only runs if the flags satisfy the designated condition. (Of course, if no condition is specified, the instruction runs unconditionally.) In ARM, branch instructions also use the result of CMP instructions (as opposed to MIPS, where BEQ both executes the comparison and branches based on it) As an example, consider the following code sequence that checks if r3 is zero and if not, performs an add operation. CMP r3, #0 BEQ skip // compare r3 to zero // if the previous CMP indicated equality, // jump to "skip'" ADD r0, rl, r2 // r0 - rl + r2 skip: . . . A clever ARM programmer can rewrite this using conditional execution // compare r3 to zero CMP r3 , #0 ADDNE r0, r1, r2 // only if the previous comparison was // not-equal, compute r0-r1 r2 Note that ADDNE is an ADD instruction with the condition NE (not equal), where the condition was set on the previous CMP (comparison) operation. Other conditions that you may find useful EQ (equal), GT (greater-than), and LE (less-than-or-equal)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
