Why would DCFSNZ take 1,2 or 3 instruction cycles?

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
DCFSNZ decrements a file register and skips the next instruction if it is zero. So I can under stand how it could just take 1 instruction cycle if it just decrements.

And I can understand if it decrements and the result is zero, it skips, the decrement would take 1 and the skip would take 2. But how could the instruction take 2 cycles?


Is the register tested when first executed? So it is zero, it skips with no decrement? Then that would only take 2 cycles?
 

John P

Joined Oct 14, 2008
2,025
This is a PIC instruction, if anyone was wondering!

"Why would DCFSNZ take 1,2 or 3 instruction cycles?"

It doesn't. It's 1 cycle if the jump isn't made, and 2 if it is.
 

t06afre

Joined May 11, 2009
5,934
From the pic 16fxxx datasheet
The contents of register ‘f’ are decremented. If ‘d’ is ‘0’, the result is placed in the W register. If ‘d’ is ‘1’, the result is placed back in register ‘f’. If the result is ‘1’, the next instruction is executed. If the result is ‘0’, then a NOP is executed instead, making it a two-cycle instruction.
 
Last edited:

AlexR

Joined Jan 16, 2008
732
As t06afre said for pic16 series its a 1 or 2 cycle instruction. 1 cycle to decrement and test and a further cycle to skip over the next instruction by replacing it with a NOP if the test proves to be true.

For pic18 processors its a 1,2,or 3 cycle instruction. Again 1 cycle to decrement and test and then a further 1 or 2 cycles to skip over the following instruction. This is because the pic18 instruction set contains some 2 word instructions and if the instruction following the DCFSNZ is a 2 word instruction then the processor has to replace it with 2 NOPs making a total of 3 machine cycles.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Thanks!


I did not realize the instructions where replaced on the PIC. I figured the PC would just be changed. So I guess that makes sense why it would use a different number of instruction cycles depending on what followed the decrement.
 
Top