Hello Dave, You are on the right track with the macros. On any of the Microchip devices with multiple pages of RAM or ROM, we always use macros that state your present address ($) and the address of the routine you wish to access, then let the assembler figure out the proper page bits to set and / or clear. Unfortunately with the code space, the macro has to always set and / or clear using the the same number of instructions since it gets upset if differing number of addresses are used. For example, if one called a routine from the same page, no instructions would be needed, but the macro has to generate them. Actually, in versions of the compiler long gone, the task was easier since the assembler would make another pass through the code to see if the addresses had been modified. Here's a crude example of something that might work: ;************************************** ;Long Jump ;************************************** ; If on Different Pages, Do Page Set, LJump MACRO AddFrom,AddTo NOLIST IF (AddTo>>.9) == 0 LIST ; Page 0 BCF STATUS,PS0 BCF STATUS,PS1 NOLIST ENDIF IF (AddTo>>.9) == 1 LIST ; Page 1 BSF STATUS,PS0 BCF STATUS,PS1 NOLIST ENDIF IF (AddTo>>.9) == 2 LIST ; Page 2 BCF STATUS,PS0 BSF STATUS,PS1 NOLIST ENDIF IF (AddTo>>.9) == 3 LIST ; Page 3 BSF STATUS,PS0 BSF STATUS,PS1 NOLIST ENDIF errorlevel -306 LIST GOTO AddTo NOLIST errorlevel +306 LIST ENDM The same type of "Bankswitch From, To" works great with the RAM since it doesn't rely on your knowing or caring which bank the variables are in. This method can, in fact set and clear variable numbers of bank bits (including none) since it doesn't self modify the address space. Hope this helps. Tom -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU] On Behalf Of David Thompson Sent: Tuesday, January 09, 2001 6:44 AM To: PICLIST@MITVMA.MIT.EDU Subject: [PIC]: Anyone have a solid strategy for code that spans pages? Hi guys, The code for my project has been growing beyond the first 2k page of my 16F877 for some time now. I have moved as much code and subroutines as possible into Page 1. I have all the right macros for doing cross-page calls and gotos, but *@#% it, it is never quite that simple, is it?. There is always something that has a problem with running in a certain page or being accessed from another page. To save me from death-through-debugging, I wanted to ask the group what strategies people had for managing large code the spans pages on these chips. It is a bit more complex than saying "Put the less-used subs in Page 1" as nothing in my code is much less used than anything else. A typical problem is as follows: You have a large number of calls to a subroutine from various spots, all residing in page 0. You decide to move the subroutine to page 1, because you're desperate for space in page 0. You then have to change all calls to the subroutine to xcalls/longcalls/whatever to make it all work. You recompile and discover that while moving the subroutine gave you say, 100 bytes free space in page 0, you lost 60 bytes of those because of the 30 times you now call it with your macro!. If the subroutine is small, you can actually be worse off than you were. As my code tries to be as size efficient as possible (in a linear addressing world) there are a lot of subroutines and a great many calls to them. Moving any to another page is perilous or pointless because of the code that the macros generate. I of course try to minimise this code by using the single page call macros, you know... pcall MACRO LABEL ;Page call - only for jumps to page 1 from page 0 bsf PCLATH,3 CALL LABEL bcf PCLATH,3 ;Needed for sanity ENDM I am interested to hear if anyone has been down this path before and thought out a really good way to have a large piece of code with LOTS of subroutines run happily across multiple pages with minimal page swapping macros. Anyone?. Dave. (Totally paged out... >:-o) -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body