CHAPTER 7Conditional Execution

This chapter provides an overview of Arm condition flags, how they are set and used by instructions, and how conditional select and comparison instructions work.

Conditional Execution Overview

In the previous few chapters, we have seen many Arm instructions used to process and modify data held in registers, as well as how to load and store data to and from memory. But data processing is only part of the story of how modern programs operate. Programs can also perform complex logic, dynamically adapting their behavior in real time based on the data that they encounter.

Software developers writing code in C and C++ often use high‐level programming constructs such as if statements, while loops, and for statements to specify how their program should adapt to various data conditions. For example, a programmer might write code such as the following:

 int main(int argc, char** argv) {
   if(argc>= 2) {
     printf(“Hello %s!\n”, argv[1]);
   }
   return 0;
 }
  

In this example, the behavior of the function dynamically changes depending on the argc parameter's value. The condition used by the if statement is a Boolean (yes/no) question, in this case asking “is argc >= 2?” The answer to this question is determined at runtime, and the statements bracketed by the if statement will be conditionally executed only if the answer to this question is “yes.”

Unfortunately for us as reverse engineers, these high‐level programming constructs do not exist at the processor ...

Get Blue Fox now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.