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.

Crude assembly counter

Status
Not open for further replies.
I want to run a routine seven times. Would something like this work?:

Code:
Counter equ 20   ; variable to put the counter in

   ; Main code here.
   ;  At some point it'll call RoutineName

RoutineName
   movlw b'01111111'
   movwf Counter
RoutineLoop
   
   Goto Transmit          ;  this being the routine to be done seven times
   RRNFC Counter,1     ; roll the bits right, don't use carry, store result in counter?
   BTFSC Counter,1     ; check counter.  skip next  line if it's clear?
   Goto RoutineLoop     ; repeat loop if there are still bits in Counter
   Return  ;  if there are no bits in Counter return to where RoutineName was called

I'm not sure about my use (and understanding) of RRFNC. also am i checking the lsb using BTFSC COunter,1 ?

Any suggestions appreciated..

Mark
 
What's RRNFC?. Assuming this is PIC assembler, bits go from 0 to 7, so the least significant bit would be 0, not 1.

If you want to see how loops are done, have a look at my PIC tutorials, many of those use loops.
 
DECFSZ is best for loop counting.

Code:
Counter equ 20   ; variable to put the counter in 

   ; Main code here. 
   ;  At some point it'll call RoutineName 

RoutineName 
   movlw 7 
   movwf Counter 
RoutineLoop 
    
   CALL Transmit          ;  this being the routine to be done seven times 
   DECFSZ Counter,f
   Goto RoutineLoop     ; repeat loop if there are still bits in Counter 
;
   Return  ;  if there are no bits in Counter return to where RoutineName was called
 
Thanks for the help. I see now how complicated i was trying to make it!

Nigel Goodwin said:
What's RRNFC?. Assuming this is PIC assembler, bits go from 0 to 7, so the least significant bit would be 0, not 1.

20ff RRNCF f,d

Rotate right (no carry)

(found it in the MPLAB help files)
 
Remeber ASM is very specific, its best when asking for help that you clearly say what device you are using, the fuse settings, as well as a breif overview of what the final application will be.

Low end microcontrollers, been developed in ASM, don't deal very well with the idea of box design, where you don't care about other peoples code to be run on the same micro.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top