See comments on your code below:- > > test EQU 01AH > > ORG 0 ; Reset vector at 0 > LIST That "LIST" shouldn't be in there. > __CONFIG _CONFIG1H, _OSCS_OFF_1H & _HS_OSC_1H > __CONFIG _CONFIG2L, _BOR_ON_2L & _PWRT_ON_2L & _BORV_45_2L > __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H > __CONFIG _CONFIG3H, _CCP2MX_ON_3H > __CONFIG _CONFIG4L, _STVR_OFF_4L & _LVP_OFF_4L & _DEBUG_OFF_4L > __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L > & _CP3_OFF_5L > __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H > __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & > _WRT2_OFF_6L & _WRT3_OFF_6L > __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H > __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & > _EBTR2_OFF_7L & _EBTR3_OFF_7L > __CONFIG _CONFIG7H, _EBTRB_OFF_7H > > I'd recommend you put the config stuff in another ASM file in your project. makes things neater. > ; > ; Pseudo-code: (there is a LED connected to bit 1 of PORTC) > ; The LED should never light, as bit0 is always zero. > ; > ; Set PORTC to output > ; Clear PORTC > ; Clear TEST > ;Loop:if bit0 of TEST is 1 then > ; toggle bit1 of portc 'toggle the LED > ; endif > ; goto loop > > > clrf TRISC ; Set portc to output > clrf portc ; Set portc pins low (LED is OFF) > > CLRF test ; Clear the variable Above you specified "org 0x00". So, these first three instructions go to program memory addresses 0x0000, 0x0002 and 0x0004. > ; > ; Problem seems to occur when the target of the goto is an > ; address that is NOT a multiple of 4. > ; In the code below, L1 is at 14H. By changing the ORG > statement ; or removing the NOP in the loop, or by adding > another NOP - doing anything ; such that L1 ends up at an > address that is a multiple of 4, the code works. ; That is, > the LED does not flash. ; ; Also, by adding code (NOPs will > do) AFTER the statement at L1, the code works > > > ORG 000aH oops, you just gave another ORG. so, the program memory from 0x0006 up to 0x0009 is uninitialised. But you didn't branch over it. Who knows what it contains? > LOOP BTFSS test,0 ; IF bit0 is 1, skip to toggle LED > GOTO L1 ; Bit0 is 0, don't toggle > > ; NOTE: we should never get here, since "test" was cleared > initially ; but we do! ; The LED flashes at an irregular > rate, as if sometime ; "test" is zero and sometimes not. ; > Other tests have shown that "test" IS ALWAYS ZERO > > BTG PORTC,1 ; Toggle the LED > ; If this NOP is removed (or if another one is added), the > code works as it should > nop > L1 BRA LOOP > I prefer to put labels on separate lines:- L1: BRA LOOP Anyway, the fact that you're trying to execute un-programmed program memory might be the cause of the problem here. I guess it depends on what your programmer does with this memory. Just lose the second ORG (the ORG 000aH). Jon -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.