Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
what is mean by goto $ and goto $+2 . ^^![]()
The $ is the program counter value.
$+2 means goto the current program counter +2.
i still not understand , coz i m newbie for PIC programming code zzzzzzzzzzz. can ericgibbs tell me more ??? tqtq![]()
The Program counter keeps track of the current program address value.
Assume your program starts at program count of 0000h, the first instruction machine code is at this address. ]
The next instruction code would reside at 0001h and so on.
The instruction at 0001 address could be for example 'goto skip', this would load the PC program counter with the address of the skip instruction, which could be for example at 0100h.
A shorthand way to write the value of the PCntr into the program, is the $ sign.
Look at this link also Nigels tutorials.
As Eric explained, $ is the current address, so $+2 is two locations higher up, in this case the 'goto Delay_0'.
Now i understand , thank eric and Nigel. Nigel P16PRO40 hardware suitable for burning program code into 16F877A PIC ??![]()
I have never used the P16PRO40, I expect it would program the 16F877A , perhaps Nigel will confirm.![]()
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto [COLOR="Red"]Delay_1[/COLOR]
decfsz countb, f
[COLOR="red"]Delay_1[/COLOR] goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
Personally, I hate the use of goto $+x. It is just lazy programming.
The above code makes total sense when it's written,
Code:Delay movlw d'250' ;delay 250 ms (4 MHz clock) movwf count1 d1 movlw 0xC7 movwf counta movlw 0x01 movwf countb Delay_0 decfsz counta, f goto [COLOR="Red"]Delay_1[/COLOR] decfsz countb, f [COLOR="red"]Delay_1[/COLOR] goto Delay_0 decfsz count1 ,f goto d1 retlw 0x00
The use of goto $+n has no use in code that wasn't written 10 years ago.
Mike.
The code above, as I'm sure you're fully aware, is generated by the PICList delay code generator, it makes obvious sense to avaoid the use of unrequired labels, so it can't clash with any existing labels when you cut and paste it. Notice they are only used for very short jumps, where it's no bother.
Personally, I hate the use of goto $+x. It is just lazy programming.
The use of goto $+n has no use in code that wasn't written 10 years ago.
-tagged text.
goto $+2 or goto $-2
Surely as the assembler is reading through the mnumonics on each line, the program counter will be counting up. So to goto the line above would need the address of the program counter with a few knocked off, rather than added on... ? Help ?
SKIP_WORD_HIG_V MACRO WORD_H,WORD_L,VAL
MOVLW HIGH VAL ;W =VAL_H - substracts value from
SUBWF WORD_H,W ;WORD_H (but not changing it)
BTFSS STATUS,C ;if C =1, WORD_H =>VAL_H
BRA $+16 ;C =0, W_H <V, go to the line!
BTFSS STATUS,Z ;if Z=1 WORD_H =VAL_H, check WORD_L
BRA $+14 ;Z =0, WORD_H>VAL_H; skip the line!
MOVLW LOW VAL ;W =VAL_L - substracts value from
SUBWF WORD_L,W ;WORD_L (but not changing it)
BTFSS STATUS,C ;if C =1, WORD_L=>VAL_L - Check Z
BRA $+4 ;C =0, W<V - go to the line!
BTFSC STATUS,Z ;if Z =0, WORD_L>VAL_L; skip line!
ENDM
Maybe I'll write a modern equivalent but then I'll be accused of plagiarism.