andrew kelley wrote: > How would automatic intelligent banking for call's and goto's work > multiple code page PIC's (in a linker or assembler)? I mean, if > you were to have a piece of code on the boundary that would be > pushed onto the next page with the addition of banking > instructions, how would the assembler know what to do for max > efficiency? Andrew: The piclist.com list archive seems to be offline at the moment, so I'll just copy an email I sent a few years ago... ------- Forwarded Message Follows ------ Steve Hardy wrote: > Yes, the perennial phase error. > .... > I encountered this sort of problem when writing a Z80 assembler. > The Z80 has two different flavours of branch: JR and JP. JR only > had a short range (and takes 2 bytes) whereas JP could jump > anywhere (3 byte instruction). I wanted to implement a pseudo-op > called 'J' which used the shortest possible opcode JR or JP. It > turned out that to optimally implement this, the assembler would > potentially have to make a large number of passes, refining its > estimate of the value of each label each time. It is also > conceivable that the assembler could get stuck in an infinite > loop. Steve: This is slightly off-topic, but there's a really simple algorithm that solves the "branch/jump optimization" problem in linear time: 1. Start with all branches set to the shortest size. 2. Put all the branches on a stack. 3. Pull a branch off the stack; if it's out of range, increase it to the next-larger size (some processors have 3 or more branch sizes) and put all the branches that SPAN the just-increased branch on the stack. 4. Repeat step 3 until everything's stable. This algorithm was first shown to me by Dr. Cliff Click, who works in Motorola's PowerPC compiler group. As I said, it runs in linear time and is guaranteed not to get stuck in an infinite loop. I can send you the rigorous mathematical proof if you're interested... It depends on the fact that monotonic functions over complete lattices have a unique minimal fixed point. -Andy ------- End of Forwarded Message ------ === Andrew Warren - fastfwd@ix.netcom.com -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist