goto $

Discussion in 'Programmer's Corner' started by beowulf1231, Jun 12, 2010.

  1. beowulf1231

    Thread Starter Member

    Aug 21, 2008
    11
    0
    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.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
    Code ( (Unknown Language)):
    1.  
    2. btfsc ADCON0,GO ; bit will change to zero when conversion is complete
    3. goto $-1
    4.  
    Same as
    Code ( (Unknown Language)):
    1.  
    2. Check_ADC: btfsc ADCON0,GO
    3.            goto Check_ADC
    4.  
     
    Last edited: Jun 12, 2010
  3. beowulf1231

    Thread Starter Member

    Aug 21, 2008
    11
    0
    Thanks for the reply.

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

    Like this 1second delay from the code generator.

    Code ( (Unknown Language)):
    1.             ;998996 cycles
    2.     movlw    79h
    3.     movwf    Delay1
    4.     movlw    2Eh
    5.     movwf    Delay2
    6.     movlw    03h
    7.     movwf    Delay3
    8. Loop:
    9.     decfsz    Delay1,f
    10.     goto    $+2
    11.     decfsz    Delay2,f
    12.     goto    $+2
    13.     decfsz    Delay3,f
    14.     goto    Loop
    15.  
    16.             ;4 cycles
    17.     goto    $+1
    18.     goto    $+1
    19.  
    20.     return
     
  4. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    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.
     
    beowulf1231 likes this.
  5. beowulf1231

    Thread Starter Member

    Aug 21, 2008
    11
    0
    Thanks, it's much clearer now.
     
Loading...