ARM Condition Flag Cheatsheet
There are four condition flags in ARM assembly: N, Z, C, and V.
N — Negative
The N flag is set to 1 when the result of an operation, interpreted as a signed two's-complement integer, is negative; otherwise the flag is set to 0.
Equivalently, the N flag is equal to the most significant bit of the result.
Z — Zero
The Z flag is set to 1 when the result of an operation is zero; otherwise the flag is set to 0.
C — Carry
To determine if an operation sets the carry flag, interpret both arguments as unsigned integers.
The carry flag is set when an addition results in a carry or when a subtraction results in no borrow.
The addition case is simple, the subtraction case is... confusing.
- Addition (including CMN)
The C flag is set to 1 if the addition produces a carry (i.e. results in unsigned overflow); otherwise the flag is set to 0.
Let the addition be x + y
with x
and y
interpreted as unsigned integers. If x + y
is too large to be represented as a 32-bit integer, C is set to 1; if x + y
can be represented as a 32-bit integer, C is set to 0.
- Subtraction (including CMP)
The C flag is set to 0 if the subtraction produces a borrow (i.e. results in unsigned underflow); otherwise the flag is set to 1.
Let the subtraction be x - y
with x
and y
interpreted as unsigned integers. If x < y
, i.e. the result would be negative, C is set to 0; if x ≥ y
, C is set to 1.
x < y ⟶ C = 0 x ≥ y ⟶ C = 1
V — Overflow
To determine if an operation sets the overflow flag, interpret both arguments as signed two's-complement integers.
The V flag is set to 1 if the result of an operation is outside the range of a signed 32-bit integer, i.e. if the result is greater than or equal to 2^{31} or less than