On the page 87 of the Game Boy CPU Manual it is claimed that the CP n
instruction sets the carry flag when there was no borrow and that it means that A < n
. This seems to conflict itself, because the carry flag is set when A > n
.
An example: If A=0
and B=1
, CP B
sets the flags like SUB A, B
, which is 0 - 1. This becomes 0 + 255 = 255 and the carry flag is not set, even though A < B
.
I came across this same issue in other Z80 documents as well, so I don't believe this is a typo.
Am I misunderstanding how borrow and SUB
work or is there something else going on? Is SUB
not equal to ADD
with two's complement in terms of flags?