INCFSZ Arithmetic

Increment a register and skip the next instruction when it wraps to 0.

SyntaxINCFSZ f, d
Operandsf: register address 0-127 (bank bits come from STATUS); d: 0 or w puts the result in W, 1 or f puts it back in f
Operation(f) + 1 → destination; skip if the result is 0
Status bitsNone
Words / cycles1 word, 1 (2 if it skips) cycles
Encoding00 1111 dfff ffff

How it works

INCFSZ adds 1 to register f. If the result is 0 (the register wrapped from 0xFF), the next instruction is skipped: it is fetched but executed as a NOP, so the skip takes 2 cycles.

It changes no STATUS bits, which makes it handy in loops that must keep the flags from earlier code.

Example

; INCFSZ example from picsimulator.com/instructions/incfsz.html
    list p=16f84a
    include <p16f84a.inc>

    org 0
    movlw 0xFE
    movwf 0x20        ; 0xFE: two increments to wrap
    clrf 0x21
loop:
    incf 0x21, f      ; count the passes
    incfsz 0x20, f    ; 0xFE -> 0xFF -> 0x00, skip on 0
    goto loop
    nop               ; 0x21 = 2

The loop runs twice before 0x20 wraps to 0 and the GOTO is skipped.

Open this example in the simulator

Watch out for

  • Z is not affected, even when the register becomes 0.

Related instructions