Section 2.7 – Making Decisions & Branches in LEGv8


1. Why Decision Instructions Exist


2. Two Basic Conditional Branches in LEGv8


3. Compiling an if–then–else Statement

C code:

if (i == j)
  f = g + h;
else
  f = g - h;

Assembly version:

SUB X9, X22, X23      // X9 = i - j
CBNZ X9, Else         // go to Else if i ≠ j (X9 ≠ 0)
ADD X19, X20, X21     // f = g + h
B Exit                // skip Else
Else: SUB X19, X20, X21 // f = g - h
Exit: