Darren Mulholland

Occasional coder.

ARM Condition Flags


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.

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.

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.

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 231 or less than –231. Otherwise the flag is set to 0.