Detailed reference for the BN instruction in PIC18 ISA.
Branch to a target label if the Negative (N) status flag is set. If N = 1, the program counter is updated to the relative address of the target, otherwise execution continues with the next instruction. BN does not alter any registers or flags.
N flag is the test condition.; Negative flag set, branch executed
BN negTarget ; jumps to negTarget if N==1; Negative flag set, branch executed
BN negTarget ; jumps to negTarget if N==1; Negative flag not set, branch skipped
BN negTarget ; no jump because N==0; Negative flag not set, branch skipped
BN negTarget ; no jump because N==0; Use in a loop to continue while result is negative
LOOP: MOVLW 0x80
SUBWF counter, 0 ; sets N
BN LOOP ; repeat if N==1; Use in a loop to continue while result is negative
LOOP: MOVLW 0x80
SUBWF counter, 0 ; sets N
BN LOOP ; repeat if N==1