Assembler PIC programming, is this correct?

Thread Starter

visaxx

Joined Aug 14, 2013
9
Thank you for answering.

I'm only using cpf-instructions because I'm in the chapter in my book where they use cpf-instructions, therefore I'm practising it.

And I had another question:

In this subroutin they are using

decf n,f
bnz again
movlw .14
movwf n

again:

decf n,f
bnz again
nop
rlncf n,w
movwf PORTC
RETURN
But instead of

decf n,f
bnz again
can I use

Rich (BB code):
decfsz n,f
goto again
?

Is there any advantage of using bnz instead of decfsz?
 

JohnInTX

Joined Jun 26, 2012
4,787
Both of the loop constructs will do the same thing. Decfsz is the more common one and I think makes the loop code stand out a bit more for readability but its a style thing mainly.
You should use bra instead of goto to save a code word AND becsuse it takes 2Tcyc to skip over a goto and only 1 to skip a bra (at the end of the loop. Its 2Tcyc for either when it takes the loop)

Finally, bz can't jump as far as bra and goto. That's not usually a problem for small loops but if the loop gets too big that bz can't reach tbe top of the loop you're back at decfsz anyway... so I use it from the get go.


Have fun.
 

joeyd999

Joined Jun 6, 2011
5,287
...Is there any advantage of using bnz instead of decfsz?
There is a huge advantage to using decfsz/bra vs. decf/bnz. Decfsz doesn't muck with the status register. This is extremely useful if you need to test the status of an operation that occurred prior to the conditional.
 
Top