DECF Arithmetic

Subtract 1 from a file register.

SyntaxDECF 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
Status bitsZ
Words / cycles1 word, 1 cycle
Encoding00 0011 dfff ffff

How it works

DECF subtracts 1 from register f and sets Z if the result is 0. Like INCF, it leaves C and DC alone. Decrementing 0x00 gives 0xFF.

Example

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

    org 0
    movlw 0x01
    movwf 0x20
    decf 0x20, f      ; 0x20 = 0, Z = 1

The register reaches 0, so Z is set.

Open this example in the simulator

Watch out for

  • For a counting loop, DECFSZ does the decrement and the zero test in one instruction.

Related instructions