Condition Codes

What condition codes are

When performing operations, the CPU will set condition codes in the status register after the instruction is executed.

For example the tst, cmp instructions will set the condition codes that represent the result of the comparison of the operands.

The instructions that use the condition codes are: bcc dbcc scc

Condition codes flags

The condition codes X, N, Z, V, C are the individual flags that can be set in the status register.

  • X is the extend flag, it is set when the result of an operation is too large to fit in the destination register.
  • N is the negative flag, it is set when the result of an operation is negative.
  • Z is the zero flag, it is set when the result of an operation is zero.
  • V is the overflow flag, in arithmetical operations, it is set if it caused the result to overflow.
  • C is the carry flag, when an operation causes a carry, like an addition or a shift, it is set to the value of the carry.

The following are all the condition codes available:

hi

!c && !z

Unsigned higher.

Used by bhi, dbhi and shi.

ls

c || z

Unsigned lower or same.

Used by bls, dbls and sls.

cc

!c

Carry clear.

Used by bcc, dbcc and scc.

cs

c

Carry set.

Used by bcs, dbcs and scs.

ne

!z

Not equal.

Used by bne, dbne and sne.

eq

z

Equal.

Used by beq, dbeq and seq.

vc

!v

Overflow clear.

Used by bvc, dbvc and svc.

vs

v

Overflow set.

Used by bvs, dbvs and svs.

pl

!n

Plus.

Used by bpl, dbpl and spl.

mi

n

Minus.

Used by bmi, dbmi and smi.

ge

(n && v) || (!n && !v)

Greater or equal.

Used by bge, dbge and sge.

lt

(n && !v) || (!n && v)

Less than.

Used by blt, dblt and slt.

gt

(n && v && !z) || (!n && !v && !z)

Greater than.

Used by bgt, dbgt and sgt.

le

z || (n && !v) || (!n && v)

Less than or equal.

Used by ble, dble and sle.

hs

!c

Unsigned higher or same.

Used by bhs, dbhs and shs.

lo

c

Unsigned lower.

Used by blo, dblo and slo.