Glen wrote:
>
> hi , hope you can help.
>
> i've seen these a few times , but don't know what they mean
> could someone please explain for me.
>
> $-1
> $+1
$ is actual program-counter
e.g.
decsfz dummy, F
goto $-1 ;goto previous instruction (decsfz) until dummy
= 0
this is often used to specifiy short jumps for avoiding using a lable.
e.g. to make the relationship to local code more clear or to get
a better readability for the source.
$ is the address of the instruction the $ is in. This is an easy way of
doing a loop to wait for something without having to do another label.
For example...
>hi , hope you can help.
>
>i've seen these a few times , but don't know what they mean
>could someone please explain for me.
>
>$-1
>$+1
>
>thanks
>glen
>
___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]
x:
---
$-3 will spend 2 clocks and jump to cmd1
$-2 ... to cmd2
$-1 ... to cmd3
$ ... to itself, endless loop , sometimes usefull ;-)
$+1 ... to cmd4
$+2 ... to cmd5
$+3 ... to cmd6
movlw 0xFF
movwf temp
decfsz temp,f
goto $ - 1 ; when counter gets here we
tell counter to - 1
it will go one line
above.
using $ you save lots of labeling BUT you have to be
careful about this it doesn't work every where.
it happened to me a few times and I couldn't find
the reason why replacing $ to label worked.
>hi , hope you can help.
>
>i've seen these a few times , but don't know what they mean
>could someone please explain for me.
>
>$-1
>$+1
Glen - the symbol '$' means 'current Program Counter address'. The value of
$ is incremented at the END of the current instruction.
The sequence '$-1' is the same as:
Loop
goto Loop
In other words, loop forever.
The sequence '$+1' is best considered to be a 2 cycle nop. It really means:
goto Label
Label
Note that you can use integers other than 1 but you should limit that
practice to jumps that are no longer than 2 or 3 locations. The following
is generally considered acceptable:
incfsz counter,F
goto $+2
goto somehwere
execute some code starting here
This little fragment emulates an 'incfsnz' instruction - increment the
counter and skip if NOT zero. You might use this if you didn't want the
increment or test to affect the status register (otherwise you would just
use the pair of instructions incf counter / skpnz).
>
> Hi Glen.
>
> $ mean current PC address.
>
> > hi , hope you can help. i've seen these a few times , but don't
> > know what they mean could someone please explain for me.
>
> > $-1
>
> loop1:
> nop ;some cmd...
> goto $-1 ;will jump to loop1
> ;usually used for loops
> > $+1
>
> goto $+1 ;will jump to loop2
> loop2: ;usually used for 2clock delay (1word)
> ;instead of nop (1clock 1 word)
> nop ;some cmd...
>
> Common case:
>
> cmd1 ;1word
> cmd2 ;1word
> cmd3 ;1word
> goto x
> cmd4 ;1word
> cmd5 ;1word
> cmd6 ;1word
>
> x:
> ---
> $-3 will spend 2 clocks and jump to cmd1
> $-2 ... to cmd2
> $-1 ... to cmd3
> $ ... to itself, endless loop , sometimes usefull ;-)
> $+1 ... to cmd4
> $+2 ... to cmd5
> $+3 ... to cmd6
>
> and so on ...
>
> WBR Dmitry.
Exactly why it should never, ever be used!!! Type the label!
Your hard disk is not full, the extra assembly time is zero. Your debug and
maintenance time is your most valuable asset, don't waste it trying to keep this
outdated scheme in your code.
Ralph
Free advice is worth every penny!:-0
Dwayne Reid wrote:
>
> Moments ago, I sent an explanation of how $-1 works to the list. It is wrong.
There are cases where you HAVE to use the $ notation. Try putting a
label in a macro. The second time you use the macro the assembler will
complain about duplicate labels. And I often use $+1 as a 2 cycle 1 word
delay instead of using two NOP's (and therefore 1 more word of precious
program space) to accomplish the same thing.
>Exactly why it should never, ever be used!!! Type the label!
>
>Your hard disk is not full, the extra assembly time is zero. Your
>debug and
>maintenance time is your most valuable asset, don't waste it trying to
>keep this
>outdated scheme in your code.
>
>Ralph
>
>Free advice is worth every penny!:-0
>
>
>Dwayne Reid wrote:
>>
>> Moments ago, I sent an explanation of how $-1 works to the list. It
>is wrong.
>
___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]
> Exactly why it should never, ever be used!!! Type the label!
>
> Your hard disk is not full, the extra assembly time is zero.
> Your debug and maintenance time is your most valuable asset,
> don't waste it trying to keep this outdated scheme in your code.
It's very depends on ability thinking absolutly and relativly ;-)
Sometimes one is better, sometimes another...
> Hi Ralph.
>
> > Exactly why it should never, ever be used!!! Type the label!
> >
> > Your hard disk is not full, the extra assembly time is zero.
> > Your debug and maintenance time is your most valuable asset,
> > don't waste it trying to keep this outdated scheme in your code.
>
> It's very depends on ability thinking absolutly and relativly ;-)
> Sometimes one is better, sometimes another...
>
> Hint: absolute and relocatable addressing
also consider something like this:
goto $+1
goto $+1
goto $+1
which is a 3-instruction 6-cycle delay. I find it much easier to read than
labelled version
goto L322
L322: goto L333
L333: goto L334
L334:
preference, style ...
BTW, Dwayne has made many useful contributions to the piclist. He's also
posted an error before - but so has every regular poster. BFD.
Scott Dattalo wrote:
>
<snip> >
> > It's very depends on ability thinking absolutly and relativly ;-)
> > Sometimes one is better, sometimes another...
> >
> > Hint: absolute and relocatable addressing
>
> also consider something like this:
>
> goto $+1
> goto $+1
> goto $+1
>
> which is a 3-instruction 6-cycle delay. I find it much easier to read than
> labelled version
>
> goto L322
> L322: goto L333
> L333: goto L334
> L334:
>
How about a macro:
delay 6 ; wait for something to happen...
Seems easier to read, and the details are hidden in the macro. If the number is
larger that 'x' the macro may even implement a loop. In either case, I know
what is meant by the code, maybe not exactly how it was implemented.
Understanding what the code does is a lot of times separate from understanding
how it is implemented.
Granted, some code must be fully visible to indicate the timing or other
implications associated with the code. Hidding such details in macros can
sometimes lead to other errors. However, I tend to make such timing critical
code highly commented to point this out.
>From the $ notation, I only know that I must try to find the documentation on $
(where is this ?), understand how the PIC increments the PC and so on. The fact
that this came up as a question indicates some sort of problem.
Question: What do the following do ?
----
goto $+1
goto loop
loop:
----
goto $-1
loop:
goto loop
----
goto $
????
-----
As with any 'concise' notation, this can be abused. Note that I also never use
a lot of the notations in 'C' which must be 'interpreted' by the reader before
the meaning of the code is understood.
> preference, style ...
>
Yes, that is a good point. Style is often left out of the code when we move
from high level language to assembler. This is obvious by many examples given
in the app notes from Micro-chip.
> BTW, Dwayne has made many useful contributions to the piclist. He's also
> posted an error before - but so has every regular poster. BFD.
>
> Scott
My apologies to Dwayne, I didn't not mean to jump on any specific error he may
have made. I was only pointing out that this notation is error prone and, as a
general guideline of (my?) style, should be avoided to prevent errors that can
easily be prevented. We all make enough mistakes anyhow, I'm only suggesting to
adopt a style that can help prevent as many as possible.
Check out the LOCAL keyword used by the pre-processor.
>From the MPASM help file:
"A local label is one that is defined with the LOCAL directive (see
Chapter 3). These labels are particular to a given instance of the
macro's instantiation. In other words, the symbols and labels that
are declared as local are purged from the symbol table when the ENDM
macro is encountered."
This seems to work fine and I have used it often....
Ralph
Adam Bryant wrote:
>
> There are cases where you HAVE to use the $ notation. Try putting a
> label in a macro. The second time you use the macro the assembler will
> complain about duplicate labels. And I often use $+1 as a 2 cycle 1 word
> delay instead of using two NOP's (and therefore 1 more word of precious
> program space) to accomplish the same thing.
>
<snip>
Good point (says he after realizing he engaged mouth before brain,
AGAIN!) I had seen the reference to the LOCAL directive, but skipped
over it and have not gotten in the habit of using it. I also have a
problem with coming up with very creative label names anyway, and
therefore use the $ references instead of my usual creative labels that
usually end up looking like Loop1:, Loop1a:, Loop1b:
Certainly when I do larger programs or any programs that will be looked
at by someone else, I try to minimize the use of $ and maximize the
descriptiveness of my labels. But as with anything, there are cases
where the use of $ has its advantages.
>Check out the LOCAL keyword used by the pre-processor.
>>From the MPASM help file:
>
>"A local label is one that is defined with the LOCAL directive (see
>Chapter 3). These labels are particular to a given instance of the
>macro's instantiation. In other words, the symbols and labels that
>are declared as local are purged from the symbol table when the ENDM
>macro is encountered."
>
>This seems to work fine and I have used it often....
>
>Ralph
>
>Adam Bryant wrote:
>>
>> There are cases where you HAVE to use the $ notation. Try putting a
>> label in a macro. The second time you use the macro the assembler
>will
>> complain about duplicate labels. And I often use $+1 as a 2 cycle 1
>word
>> delay instead of using two NOP's (and therefore 1 more word of
>precious
>> program space) to accomplish the same thing.
>>
><snip>
>
___________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com/getjuno.html
or call Juno at (800) 654-JUNO [654-5866]
>> goto $-1
>>
>>loop:
>> goto loop
>
>these are not the same. the $ points to the current instruction, so
>would be
>
> loop:
> <some instruction>
> goto loop
Hi there, Gerhard. That was my mistake, not Ralph's. I noticed the error
right after I uploaded the message and sent a retraction. Sorry about the
confusion on my part.
>Hi there, Gerhard. That was my mistake, not Ralph's.
actually, it was the $'s mistake :) one of the reasons i never liked it,
is that it's easy even for experienced programmers to make (or overlook)
mistakes. i prefer labels (for singluar occurences) or macros (for repeated
occurences of similar constructs). or C right away... :)