How do I do a “greater than” jump in Z80 Assembly, rather than “greater than or equal to”?

CP performs a subtraction and sets the flags appropriately. It doesn’t store the results of the subtraction.

So to compare for the A greater than the operand, you need to look for a result of that subtraction that was a strictly positive number, i.e. it was 1 or greater.

There’s no direct route to that, you’ll have to do it as a compound — NC to eliminate all results less than 0, getting you to greater than or equal, followed by NZ to eliminate the possibility of equality. But you might want to flip those for more straightforward code. E.g.

      CP <whatever>
      JR C, testFailed   ; A was less than the operand.
      JR Z, testFailed   ; A was exactly equal to the operand.

      ; A was not less than the operand, and was not
      ; equal to the operand. Therefore it must have
      ; been greater than the operand.


CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top