I'm new to assembly language and I wrote a simple program to learn. I run into a problem of program counter (I believe) with a "goto" instruction. I use a PIC 10f202 and I use MPLAB v.6.15 in simulator mode to debug my code. Here my code:
PROCESSOR 10f202
#include <xc.inc>
; CONFIG
CONFIG WDTE = OFF ; Watchdog Timer (WDT disabled)
CONFIG CP = OFF ; Code Protect (Code protection off)
CONFIG MCLRE = OFF ; Master Clear Enable (GP3/MCLR pin fuction is digital I/O, MCLR internally tied to VDD)
PSECT resetVect, class=CODE, delta=2
resetVect:
PAGESEL main
goto main
PSECT code, delta=2
main:
clrf GPIO ; clrf GPIO, F
movlw 0b0001000 ; configure GP1 (only) as an output
tris GPIO
loop:
bcf GPIO,0
bsf GPIO,0
movlw 256
movwf 0x10
nop
goto loop
END resetVect
The program start at program memory 1F6 (line 503) with the instruction "goto main". It executes all code lines but when it reaches the instruction "goto loop", the program memory line 1FF does not show the instruction "goto loop" and then the program goes to program memory line 0c7 where there is no instruction. It does not go back to instruction "bcf GPIO,0" has expected.
At first I was using a "call" instruction to call the subroutine "loop" with a return instruction but I was getting the error message that the instruction return was an illegal instruction for this PIC 10F202. I had an old assembly code that work before with "goto" instruction but this code was compiled with the old compiler from MPLAB: MPASM. In this code (using the same PIC 10f202) I used goto and call instructions and it compiled fine. Thanks for helping! Dominique