Rob Robson wrote: > My first (unsuccessful) attempt to locate some routines on Page 1 > and to call them from Page 0 has sent me scrambling .... could I > not just make every single CALL in my program an LCALL and call it > good? Would that work, or would that cause the PIC's PC to go on > some unwanted long-call sallies? Rob: LCALL will set the PCLATH bits appropriately for the destination of the CALL, but it won't reset PCLATH after the RETURN. Therefore, you'll have to change EVERY ONE of your CALLs and GOTOs to LCALL and LGOTO. Macros that adjust PCLATH on both sides of the CALL have been posted numerous times to the list; I'm sure Olin will post a link to his macros. Be careful when using long-call (and long-goto) macros; if you replace a fragment like: BTFSS PORT,BIT CALL BIT_IS_LO with: BTFSS PORT,BIT XCALL BIT_IS_LO your code will break, since that second fragment REALLY says something like: BTFSS PORT,BIT BSF PCLATH,3 BCF PCLATH,4 CALL BIT_IS_LO BCF PCLATH,3 BCF PCLATH,4 For cases like that, what you really want is: BTFSC PORT,BIT GOTO $+6 BSF PCLATH,3 BCF PCLATH,4 CALL BIT_IS_LO BCF PCLATH,3 BCF PCLATH,4 ... and the easiest, least-error-prone way to do THAT is to never use BTFSS/CALL at all; instead, write "LCALLIF" and "LCALLIFNOT" macros that do the whole thing for you, from the initial BTFSC/BTFSS to the final PCLATH adjustment. For a long-call macro to be correct in all cases, it must adjust all the relevant PCLATH bits, even when only one bit actually NEEDS to be adjusted. Just about everyone tries to avoid this by writing a macro that conditionally includes the second bit-adjustment only if it's necessary. Unfortunately, MPASM can't deal with macros that aren't fixed-length, so the conditional macros don't work. If you want maximal efficiency, then, you need a whole bunch of macros, one for each combination of source and destination page. To ensure that you never use the wrong one, each macro should include IF/ERROR lines that check for source and destination pages that match the ones for which the macro was written, then display an error message if there's an inconsistency. Personally, I wouldn't bother maximizing the efficiency for most projects. If you're only using two pages, it's pretty easy to arrange things so very few cross-page calls are necessary; if you're using more, it usually isn't necessary to squeeze every last byte and instruction cycle out of your code. -Andy === Andrew Warren -- aiw@cypress.com === Principal Design Engineer === Cypress Semiconductor Corporation === === Opinions expressed above do not === necessarily represent those of === Cypress Semiconductor Corporation -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu