----- Original Message ----- From: "WH Tan" To: Sent: Tuesday, January 06, 2004 10:59 PM Subject: Re: [PIC]: ADDWF PCL,F > Hi every one, > > May I take the opportunity here to ask some question about PCL. > > 1) Is PCL post increased by PIC after execution of instruction, or is it > increased before execution of instruction? [ NOTE: My response here assumes a PIC12 or PIC16. Things are different on a PIC18 ] PCL is effectively incremented at the beginning of the instruction. Thus, given the code: MOVLW 0x00 ADDWF PCL,F NOP NOP all four instructions will execute. With this code: MOVLW 1 ADDWF PCL,F NOP NOP The first NOP will be skipped. > 2) Is the following set of codes have the same effect on program flow? > > A1 MOVLW 0x00 > ADDWF PCL,f > > A2 GOTO A2 Because W is zero, the ADDWF PCL,F is effectively a NOP, so this will execute the MOVLW, the ADDWF and then repeat the GOTO indefiniitely. > > B1 MOVLW 0xFF > .... > ADDWF PCL,f > B2 GOTO $-1 Because W is 0xFF, adding it to PCL will keep resetting PCL to point to the ADDWF instruction. So, in this case the MOVLW will execute, and then the ADDWF will be repeated indefinitely. The GOTO will never be reached. [ NOTE: these explanations assume that the code involved does not span a 256 byte page boundary, and that PCLATH is properly set to point to the code page.] Bob Ammerman RAm Systems -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu