PIC18 cheatsheet

BNZ

Detailed reference for the BNZ instruction in PIC18 ISA.

Description

Branch If Not Zero (BNZ)

Branch to the specified label if the Zero flag (Z bit of the STATUS register) is clear (0), which indicates that the result of the most recent arithmetic or logical operation was non‑zero.

  • If Z = 0 → the program counter is updated to point to the given label.
  • If Z = 1 → execution continues with the following instruction.

Examples

"; BNZ branch taken: Z flag cleared by INCFSZ\nINCFSZ counter,0\nBNZ skipLabel   ; jumps to skipLabel because Z=0"
"; BNZ branch not taken: Z flag set by CLRF\nCLRF counter,0\nBNZ skipLabel   ; does not jump (Z=1)"
"; BNZ used to jump to a label defined a few lines later\nINCFSZ counter,0\nBNZ targetLabel   ; jumps to targetLabel\nNOP\nNOP\ntargetLabel:\nNOP"