Why does my program JMP to the wrong location?

Submitted by: TechTools

a) The PICmicro® MCU architecture uses a paged code space. Similar to the file register banking scheme, it depends on you to select the proper code page before jumping or calling into a different code page. CVASM16 provides some relief for this headache: LJMP. This instruction actually generates one or two bitset/clr instructions before the JMP instruction to automate this process. To save code and processor cycles, you can selectively use LJMPs and LCALLs to code in other code pages and use standard call and jmp instructions to code within the current page.

If efficiency in code space or cycles is not an issue, you could just use the LONG versions of these all of the time and forget about which code page the target address is in. The code generated by the LJMP and LCALL instructions is no less efficient than the code you would generate yourself. It is also much easier to read, understand and maintain code written with the LONG versions.

b) See FAQ3 Part B about mis-configured device types.