> 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. Actually, MPASM will work just fine with conditional (variable size) macros, as long as the code expands to the same number of instructions on both assembly passes for any given invocation of hte macro. The problem with most schemes to generate optimized long calls is that, on the first pass, all the target addresses are seen as being zero if they haven't beend defined yet. One way around this is to define symbols at the front of your code identifying the page that each routine is going to be in: P_Routine1 = 0 P_Routine2 = 1 etc. Then your LCALL macro takes two arguments: LCALL Routine1,P_Routine1 It can use the second argument to determine what has to be done to PCLATH. Finally, you use a macro to define the entry point of the subroutine: ENTPT Routine1,P_Routine1 which defines the entry point, and also verifies that it is indeed in the page that the P_Xxxxx symbol indicated it would be in. Note that none of this magic is likely to work when using the linker. Bob Ammerman RAm Systems -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu