menu_top_normal
NeoLoch Home Page
Home Inquisitor Tester Learning Lab Consulting Shipping Policy Contact us Support ----------------------
News
Coming soon! 9060 Blade.
DECF Command:
Syntax:
Status Flags Effected:
DECF
DECF f,d
Z

The DECF command decrements (counts down) the register specified by f. If d is equal to 0 then the result is stored in the working register, if d is equal to 1, then the result is stored in the register specified by f.

Code Example 1: Assume we have a register labeled COUNT. The following command will decrement the value currently stored in COUNT and then store the new value in the same register.
DECF         COUNT,1
Decrement COUNT and store the new value in COUNT.

Code Example 2: The following command is identical, but now the resulting value is stored in the working (w) register.
DECF        COUNT,0 Decrement COUNT and store the new value in the working register.

This command effects the z (zero) flag in the status register. If resulting value is zero, then the Z flag will be set, and if it's not zero then the Z flag will be clear.

DECFSZ Command:
Syntax:
Status Flags Effected:
DECFSZ
DECFSZ f,d
NONE

The DECFSZ operates almost identical to the DECF command, but if the resulting value from the decrement is zero, then the next command will be skipped. DECFZ is very useful for control loops that need to execute a certain number of times.

Code Example 3: The following example illustrates using the DECFSZ command to send eight high and low pulses out of the PORTA, BIT 0 pin.
MOVLW     0X08
MOVWF     COUNT
BSF              PORTA,0
NOP
BCF             PORTA,0
DECFSZ      COUNT,1
GOTO          $-4
RETURN
Load the working register with the hex value of 8.
Load the register COUNT with the value 8.
Turn bit 0 of PORT A on.
Leave the bit on for a little while.
Turn off bit 0 of PORTA.
Decrement F and store the new value in F. Does COUNT = 0?
No - Jump back 4 commands and do them again.
Yes - Exit routine and move on.










All contents of this website are copyrighted 2010-2018 NeoLoch