# Flags

Difficulty:
novice · intermediate · advanced · expert

We briefly touched on the F register yesterday. Today we’ll take a more in-depth look.

## Flags

As you learned on Day 3, The individual bits of the F register are called flags. Each flag signifies whether or not the last instruction triggered a particular event.

These are the flags, from bit 7 of the F register to bit 0:

7 6 5 4 3 2 1 0
S Z - H - P/V N C

The lowdown:

### S - Sign

If the accumulator evaluated to a negative number, this flag is set (i.e. the bit equals 1). If the accumulator evaluated to a positive number, this flag is reset (i.e. the bit equals 0). The S flag assumes that the accumulator is signed. In other words, it just stores bit 7.

### Z - Zero

If the last instruction caused a register to equal zero, this flag is set. Otherwise, the flag is reset.

### - - Not Used

These two bits aren’t used as flags.

### H - Half-Carry

Functions exactly like the carry flag (below) except that the carry is detected in the least-significant nibble (hence the name). Half-Carry is used exclusively with the DAA instruction, which is used for binary coded decimal numbers. Not something we need to be concerned about, and from now on we’ll pretend it dosen’t exist for the sake of simplicity.

### P / V - Parity/Overflow

This flag serves double duty by detecting overflows and partity. An overflow is where a register winds up having a value that exceeeds signed 8-bit range. You could also consider an overflow to be when a register’s sign bit changes through an operation. Either way you look at it, the flag is set. The parity is whether the number of 1s in the accumulator is even (set) or odd (reset).

Whether this flag reflects parity or an overflow is based on which instruction was used.

`SCF`
`CCF`