Searching \ for '$-1 ??' 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/index.htm?key=
Search entire site for: '$-1 ??'.

Truncated match.
PICList Thread
'$-1 ??'
1999\04\08@095346 by Glen

flavicon
face
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

1999\04\08@101427 by Stefan Sczekalla-Waldschmidt

flavicon
face
Hi,

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.

Kind regards,

       Stefan

1999\04\08@101850 by Harold Hallikainen

picon face
$ 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...


       btfsc   portb,0
       goto    $-1

will loop until RB0 is pulled low.

Harold


On Thu, 8 Apr 1999 23:49:09 +1000 Glen <spam_OUTelectmeTakeThisOuTspamTIG.COM.AU> writes:
{Quote hidden}

___________________________________________________________________
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]

1999\04\08@104318 by Dmitry Kiryashov

flavicon
face
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.

1999\04\08@115339 by engelec

picon face
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  program counter

           normal  example

           movlw    0xFF
           movwf    temp
loop     decfsz     temp,f
           goto        loop


           $  example

           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.

Andre Abelian

Andre




> thanks
> glen

1999\04\08@133912 by Dwayne Reid

flavicon
face
>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).

Hope this helps.

dwayne


Dwayne Reid   <.....dwaynerKILLspamspam@spam@planet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(403) 489-3199 voice          (403) 487-6397 fax

Celebrating 15 years of Engineering Innovation (1984 - 1999)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
My posting messages to Usenet neither grants consent to receive
unsolicited commercial email nor is intended to solicit commercial
email.

1999\04\08@134957 by Dwayne Reid

flavicon
face
Moments ago, I sent an explanation of how $-1 works to the list.  It is wrong.

I said:  The sequence '$-1' is the same as:

>Loop
>    goto    Loop
>
>In other words, loop forever.

This is WRONG.  My appologies for the confusion.  Not enough coffee yet this
morning, I guess.

dwayne


Dwayne Reid   <dwaynerspamKILLspamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(403) 489-3199 voice          (403) 487-6397 fax

Celebrating 15 years of Engineering Innovation (1984 - 1999)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
My posting messages to Usenet neither grants consent to receive
unsolicited commercial email nor is intended to solicit commercial
email.

1999\04\08@162153 by WF AUTOMACAO

flavicon
face
Dmitry Kiryashov wrote:
{Quote hidden}

PC=Program Counter

1999\04\08@170616 by Ralph Stickley

flavicon
face
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.

1999\04\08@172943 by Adam Bryant

picon face
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.

My 2 cents worth.

Adam Bryant (age 0x23)
.....abryantKILLspamspam.....peaktech.com (work)
EraseMEadamdbspam_OUTspamTakeThisOuTjuno.com (home)
Parker, CO, USA
Robotics, RC Airplanes, anything using a PIC

On Thu, 8 Apr 1999 17:00:39 -0400 Ralph Stickley <rstickleyspamspam_OUTDATALUX.COM>
writes:
{Quote hidden}

___________________________________________________________________
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]

1999\04\08@184423 by Dmitry Kiryashov
flavicon
face
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

WBR Dmitry.

1999\04\08@202915 by Scott Dattalo

face
flavicon
face
On Thu, 8 Apr 1999, Dmitry Kiryashov wrote:

> 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

1999\04\09@094048 by Ralph Stickley

flavicon
face
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.

Ralph

1999\04\09@094244 by Ralph Stickley

flavicon
face
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>

1999\04\09@102321 by Dmitry Kiryashov

flavicon
face
Hi Ralph.

> Question:  What do the following do ?
> ----
>     goto   $+1
>
>     goto   loop

2 clocks delay if tricks with pclath isn't used,
usually cause jump to next address ;-)


> loop:
> ----
>     goto   $-1
>
> loop:
>     goto   loop

usually used for waiting while some condition
will occur, for instance testing of some bit.

       btfss(c)        some_bit_somewhere
       goto    $-1

As only condition will postive next program
will start executing. If PCLATH is set to another
page will cause switching to another program page.


>     goto   $

Either to lock code while expecting some interrupting
event or jump to another program page (PCLATH is set
properly)


WBR Dmitry.

1999\04\09@181220 by Gerhard Fiedler

picon face
At 09:30 04/09/99 -0400, Ralph Stickley wrote:
>Question:  What do the following do ?
>----
>    goto   $+1
>
>    goto   loop
>loop:

this on eis correct, the others not (as far as i understand it, but i don't
use the $ very often... :)

>----
>    goto   $-1
>
>loop:
>    goto   loop

these are not the same. the $ points to the current instruction, so

 loop:
   goto loop

would be equal to your last example

>----
>    goto   $

whereas

   goto $-1

would be

 loop:
   <some instruction>
   goto loop

ge

1999\04\09@183105 by Adam Bryant

picon face
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.

Adam Bryant (age 0x23)
@spam@abryantKILLspamspampeaktech.com (work)
KILLspamadamdbKILLspamspamjuno.com (home)
Parker, CO, USA
Robotics, RC Airplanes, anything using a PIC

On Fri, 9 Apr 1999 09:37:56 -0400 Ralph Stickley <RemoveMErstickleyTakeThisOuTspamDATALUX.COM>
writes:
{Quote hidden}

___________________________________________________________________
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]

1999\04\09@185426 by wagnerl

picon face
Adam Bryant wrote:
...[snip]...
> ...But as with anything, there are cases
> where the use of $ has its advantages.

You are 100% right. I believe that the use of $ or mostly $$$, only has
advantages... mainly in "US$ cash" format... :)
Wagner

1999\04\09@191124 by paulb

flavicon
face
Dmitry Kiryashov wrote:

>> loop:
>> ----
>>     goto   $-1

>> loop:
>>     goto   loop

> usually used for waiting while some condition
> will occur, for instance testing of some bit.

 Actually, the latter example is *equivalent* to the following and has
the same implication:

>>     goto   $
--
 Cheers,
       Paul B.

1999\04\10@145046 by Dwayne Reid

flavicon
face
Gerhard Fiedler wrote:

>>    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.

dwayne


Dwayne Reid   <spamBeGonedwaynerspamBeGonespamplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 15 years of Engineering Innovation (1984 - 1999)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
My posting messages to Usenet neither grants consent to receive
unsolicited commercial email nor is intended to solicit commercial
email.

1999\04\10@185950 by Gerhard Fiedler

picon face
At 12:49 04/10/99 -0600, Dwayne Reid wrote:
>Gerhard Fiedler wrote:
>>>    goto   $-1

>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... :)

ge

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