Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Quick question about piece of code

Status
Not open for further replies.

DerStrom8

Super Moderator
Hello, everyone.
I came across this tutorial that explains how to use Assembly to program a PIC16F84, but I am wondering about one of the pieces of the code.
For the delay, this is what the code says:

Delay

Loop1 decfsz Count1,1 ;
goto Loop1 ;
decfsz Count2,1 ;
goto Loop1 ;
return
END

My question is how this part works. I thought that by saying "goto Loop1" it would go back to "Loop1" and do the same thing over and over again, without ever getting to the "return" command. Could someone please explain why this is does not happen? If you need any more information, please see the link. It has the entire code, if it would help.
Many thanks!
Der Strom
 
Last edited:
Its actually 2 loops in one to make a larger delay.
when the first counter becomes zero
it will jump over the 2nd line decreasing the 2nd counter
and so on......
 
The directive 'decfsz' means 'DECrement File and Skip if Zero'. So once Count1 has reached zero the code will 'skip' the goto Loop1 line and move onto the next one.
 
Thank you both for the replies. That helps a lot. :)
 
With respect to that tutorial, although it is quite a good explanation, there are some bad flaws in the code. Tutorial 4 is particularly wrong and confusing and the interrupt code is a very bad example.

Mike.
 
With respect to that tutorial, although it is quite a good explanation, there are some bad flaws in the code. Tutorial 4 is particularly wrong and confusing and the interrupt code is a very bad example.

Mike.

I just looked at tutorial 4. I learned some from this site when I first got into PIC ASM. Looking at it now, I can't imagine why they are moving values through WREG to set or clear single pins on a PORT.
 
I just looked at tutorial 4. I learned some from this site when I first got into PIC ASM. Looking at it now, I can't imagine why they are moving values through WREG to set or clear single pins on a PORT.
That's just one of a number of different methods to avoid read-modify-write problems.
 
Status
Not open for further replies.

Latest threads

Back
Top