Searching \ for '[PIC]: Pseudo loops in assembly directives' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=directive
Search entire site for: 'Pseudo loops in assembly directives'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Pseudo loops in assembly directives'
2005\08\01@095534 by Hector Martin

flavicon
face
Hi all,

I've been wondering if there is an easier way to code assembler loops
(i.e. the repetition of a section of the program, which would get
unrolled at compile time). I know I can code the loop for the PIC to
execute, but I'd rather not waste time messing around with INDF/FSR
and a loop variable, since that wastes time and I've got plenty of
space in program memory.

Previously I've been doing this:

       VARIABLE i=0
       WHILE i<7
               ; code here
               VARIABLE i=i+1
       ENDW

Which is fine (although I'd appreciate it if there is an easier way of
doing it.) The problem comes when using labels inside the loop, since
the assembler doesn't like the repeated labels, and the LOCAL stuff
can only be used inside a macro (yes, I could code everything into a
macro and then put the macro into the loop, but that would be even
more confusing). So I end up doing things like $+5, which is evil and
hard to maintain.

Is there a better way of doing this? Like mangling label names with
the i variable or something?

--
Hector Martin (spam_OUThectorTakeThisOuTspammarcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

2005\08\01@103755 by olin piclist

face picon face
Hector Martin wrote:
> Previously I've been doing this:
>
>        VARIABLE i=0
>        WHILE i<7
> ; code here
>                VARIABLE i=i+1
>        ENDW
>
> Which is fine (although I'd appreciate it if there is an easier way of
> doing it.)

There is no FOR construct that I know of.  All my counted loops work pretty
much the same as your example.

> The problem comes when using labels inside the loop, since
> the assembler doesn't like the repeated labels, and the LOCAL stuff
> can only be used inside a macro (yes, I could code everything into a
> macro and then put the macro into the loop, but that would be even
> more confusing). So I end up doing things like $+5, which is evil and
> hard to maintain.
>
> Is there a better way of doing this? Like mangling label names with
> the i variable or something?

You can reserve some names to always be temporary assembler variables for
purposes of code like that.  I use II and JJ, for example, although that's a
bit unclean if you don't know that convention is being used.  Another way is
to make a unique name for that loop, then use the #V() syntax to append a
the loop variable value to make a unique name for that iteration.  That's
cleaner, but also messier to look at.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

2005\08\01@111559 by Hector Martin

flavicon
face
Olin Lathrop wrote:
> Another way is
> to make a unique name for that loop, then use the #V() syntax to append a
> the loop variable value to make a unique name for that iteration.  That's
> cleaner, but also messier to look at.

OK, so that was what I was looking for. Shame on me for not reading
the whole manual!

--
Hector Martin (.....hectorKILLspamspam@spam@marcansoft.com)
Public Key: http://www.marcansoft.com/hector.asc

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...