Switch to full style
PIC Assembly Articles
Post a reply

Loops and Branching

Tue Apr 02, 2013 12:26 am

1. Conditional Branching:

Code:
  DECFSZ      fileReg, d

Decrements file register and skip next instruction if value in file registers reaches 0.
Untitled3.png
Untitled3.png (53.42 KiB) Viewed 3823 times

Code:
BNZ      Label

Branch if the value in file register is not zero, it works on zero flag in status register.
Untitled4.png
Untitled4.png (51.72 KiB) Viewed 3823 times

Code:
BZ      Label

Branch if the value in file register is zero.
Code:
BNC      Label

Branch if no carry, if C flag in status register is zero.
Untitled.png
Untitled.png (11.43 KiB) Viewed 3824 times


2. Unconditional Branching:
Code:
GOTO      Label


Nested Loops:
Due to the fact that registers in PIC can carry only 8 bits which means it can have numbers only from 0 to 255, and then if we have for loop greater than 255 what should we do? This is the nested loop:
Untitled2.png
Untitled2.png (76.47 KiB) Viewed 3823 times


Comparing Instructions:

Code:
cpfseq f,a ; compare register f with WREG, skip if equal
cpfsgt f,a ; compare register f with WREG, skip if greater than
cpfslt f,a ; compare register f withWREG, skip if less than
decfsz f,d,a ; decrement f, skip if 0
dcfsnz f,d,a ; decrement f, skip if not 0
incfsz f,d,a ; increment f, skip if 0
infsnz f,d,a ; increment f, skip if not 0




Post a reply
  Related Posts  to : Loops and Branching
 C++ For Loops     -  
 C++ for loops     -  
 Nesting Two for Loops     -  
 Break in Nested Loops     -  
 Re: Lets Learn C++----->(Lesson 4) Loops     -  
 write a while loops performing operations on number     -  
 Using Program Loops to Create Time Delays     -