Jerry Meng wrote: > Here I am confused when I wrote code for table looking up. The PIC I > will use is 16C73. The code as following: > > (A) > org 0 > START: bsf pclath,3 > movlw 0 > movwf INDEX > call GET_TAB_ITEM > ... > > org 0xE00 > TAB_LOOKUP: movwf pcl /*********************/ > > GET_TAB_ITEM: movlw 0x0F > movwf pclath > movf INDEX,w > call TAB_LOOKUP > return > > org 0xF00 > dt 0,1,2,3,........ > (B) > org 0 > START: bsf pclath,3 > movlw 0 > movwf INDEX > call GET_TAB_ITEM > ... > > org 0xE00 > TAB_LOOKUP: addwf pcl,f /*********************/ > > GET_TAB_ITEM: movlw 0x0F > movwf pclath > movf INDEX,w > call TAB_LOOKUP > return > > org 0xF00 > dt 0,1,2,3,........ > > You can see the code (A) and (B), the only difference betweeb them > is the line marked with /***/, personally I think in code and > [addwf pcl,f] will get the same result to [movwf pcl], but when > I use the MPLAB to simulate the result, it is different, returns > 0, but returns 1. Why? Jerry: The PIC increments the program counter BEFORE it executes the current instruction. In your example "B", PCL contains 1 when the "ADDWF PCL" is executed. -Andy === Andrew Warren - fastfwd@ix.netcom.com === === Fast Forward Engineering - Vista, California === === === === Did the information in this post help you? Consider === === contributing to the PICLIST Fund. Details are at: === === http://www.geocities.com/SiliconValley/2499/fund.html ===