goto $

Thread Starter

beowulf1231

Joined Aug 21, 2008
11
hi all,

i'm a newbie on assembly programming and trying to understand what does "goto $", "goto $+2", or "goto $-5" mean. tried to google it but no clear explanation found.

pls. help, thanks.
 

t06afre

Joined May 11, 2009
5,934
The $ is an Arithmetic Operator. It means current program counter. So goto $+2 will take you to current program counter+2. Goto $ will be an endless loop. You will often see the goto $-1 used combined with Bit Test f, Skip if Set (or skip if clear) in Microchip assembler like this
Rich (BB code):
btfsc ADCON0,GO ; bit will change to zero when conversion is complete
goto $-1
Same as
Rich (BB code):
Check_ADC: btfsc ADCON0,GO
           goto Check_ADC
 
Last edited:

Thread Starter

beowulf1231

Joined Aug 21, 2008
11
Thanks for the reply.

How will the "goto $+1" affected by putting a "return" after it.

Like this 1second delay from the code generator.

Rich (BB code):
            ;998996 cycles
    movlw    79h
    movwf    Delay1
    movlw    2Eh
    movwf    Delay2
    movlw    03h
    movwf    Delay3
Loop:
    decfsz    Delay1,f
    goto    $+2
    decfsz    Delay2,f
    goto    $+2
    decfsz    Delay3,f
    goto    Loop

            ;4 cycles
    goto    $+1
    goto    $+1

    return
 

AlexR

Joined Jan 16, 2008
732
The "goto $+1" has the same functionality an a "nop" but takes twice as long to execute (nop takes 1 instruction cycke, goto $+1 takes 2 cycles) which is why it is often used in delay loops.
 
Top