Delay Symbol Question

Status
Not open for further replies.
Just a quick question. What does the $ symbol mean/equate in this code mean? It is not in my pic mcu quickchart. The code needs to go into a 16f870. I found this code in a delay code generator at piclist.com

; Delay = 0.5 seconds
; Clock frequency = 4 MHz

; Actual delay = 0.5 seconds = 500000 cycles
; Error = 0 %

cblock
DELAYP5
DELAYP5_1
DELAYP5_2
endc

DelayP5
;499994 cycles
movlw 0x03
movwf DELAYP5
movlw 0x18
movwf DELAYP5_1
movlw 0x02
movwf DELAYP5_2
DelayP5_0
decfsz DELAYP5, f
goto $+2
decfsz DELAYP5_1, f
goto $+2
decfsz DELAYP5_2, f
goto DelayP5_0

;2 cycles
goto $+1

;4 cycles (including call)
return
 
$+2 means goto the next 2 instruction.
Code:
decfsz DELAYP5_1, f
goto $+2
decfsz DELAYP5_2, f
goto DelayP5_0
If DELAYP5_1 is not zero, then go to-->goto DELAYP5_0

EDIT: you can use MPLAB to see the disassembler listing (if not mistaken), see where address it goes.
 
Last edited:
$ is the symbol for Present Location

1. goto $ will loop forever given no interrupts intervene.
2. goto $ + X will skip forward X instructions.
3. goto $ - X will skip backward X instructions.

P.S. When a delay routine is this ugly, you should just make up your own and make it paramatized so that one routine can suffice for most your long delay times.
 
FYI, $+11 is not the next 11 instruction but next 17. $+0B is the next 11th instruction. I've tried without a '0', i.e. $+B and it doesn't work.
 
You must always be away of the default radix or use definitive expressions.
If you want to skip eleven you do this:
GOTO $ + .11
GOTO $ + 0X0B
GOTO $ + 0BH
GOTO $ + B'00001011'

Or do this:
RADIX DEC
GOTO $ + 11

This is true for every single line of opcode and not just goto's.
 
If not mistaken, it changes the default way that the compiler interprets numerals from a base (or radix) of sixteen (hex) to a base of ten (decimal). Otherwise, it is good common practice to pre/post-fix all numerals as donniedj shows at the top of his post above.
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…