JB wrote: > > From what I have (mis)read, branching instructions for these cannot always > address 'distant' locations. If this is the case, then when exactly does a > Call, Goto, or Return/Retfie require special handling, and how would I know > I've not done this when I should have? > > Moreover, how do I handle these special cases? The peculiarity of branching in PICs is due to the 14 bit size of the instructions themselves. GOTO and CALL instructions use 3 bits to define the actual instruction which leaves 11 bits available for address information. This means you can jump to address locations in the range 0 - 2047 only. To enable branches to addresses outside this range, the 11 bit address needs to be expanded. These extra bits come from the PCLATH register, and are bits 3 and 4. These 2 bits make up an effective 13 bit address and are always appended when a GOTO or CALL instruction is used. PCLATH bits 4 3 2K ROM Block 0 0 0 0000 - 07FF 0 1 1 0800 - 0FFF 1 0 2 1000 - 17FF 1 1 3 1800 - 1FFF The return and retfie instructions cause the top address to be popped off the stack and get put back into the program counter. This is a 13 bit operation, and with the current range of PICs, is the entire return address. For PICs like the 16F84 with only 1K of ROM, you can ignore these PCLATH bits. For PICs like the 16C74 with 2 pages of ROM, you will need to know the state of the PCLATH bits before using GOTO and CALL. Org 0000h CALL There Org 00FFh Here retlw 5h ; if PCLATH = xxx0 0xxx W = 5 on return Org 08FFh There retlw 2h ; if PCLATH = xxx0 1xxx W = 2 on return -- Best regards Tony http://www.picnpoke.com mailto:sales@picnpoke.com