source= http://www.piclist.com/postbot.asp?id=piclist\2003\01\22\213213a For the XOR switch statement trick see the MACRO by Tom Hartman at http://www.piclist.com/swstmt On the binary testing idea: Although written for the SX rather than the PIC, I have an... interesting... macro that will implement a bit test jump table which is actually more efficient (on the SX anyway) than the more traditional PC math jump table for tables with 4 or fewer addresses. Anyone who can make sense of it is welcome to try for a MPASM version... ; BinJump ,
[,
] ; Call with the first parameter of the register to tbe tested and ; the following parameters a list of addresses to jump to based on ; the value of the register. ; More effecient than a long jump table for 4 or fewer addresses binjmp2 MACRO index, one, two ;assumes that pageaddr is set to current value of page bits on entry. noexpand pageaddr = $>>9 ifdef one if (pageaddr == one >> 9) expand jnb index.0,one noexpand else pageaddr = $ >> 9 expand jnb index.0,@one noexpand endif else pageaddr = $ >> 9 expand jnb index.0,@one noexpand endif ifdef two if (pageaddr == two >> 9) expand jmp two noexpand else pageaddr = $ >> 9 expand jmp @two noexpand endif else pageaddr = $ >> 9 expand jmp @two noexpand endif endm binjmp4 MACRO index, one, two, three, four local :1set ;assumes that pageaddr is set to current value of page bits on entry. if (pageaddr == ($+9)>>9) ;:1set can't be more than 9 words away. expand jb index.1, :1set noexpand else expand sb index.1 page :1set jmp :1set noexpand endif binjmp2 index, one, two expand :1set noexpand pageaddr = $ >> 9 ;can't get here except by jump and so must be paged binjmp2 index, three, four endm binjump MACRO local :2Set, :1Set, parms, index parms = \0 - 1 index = \1 ;Call with the first parameter of the register to tbe tested and ;the following parameters a list of addresses to jump to based on ;the value of the register. ;More effecient than a long jump table for 4 or fewer addresses expand page $ noexpand pageaddr = $ >> 9 if parms > 4 if parms == 5 expand jb \1.2, @\6 ;=4 noexpand binjmp4 \1,\2,\3,\4,\5 else ;6 or more if (pageaddr == ($+19)>>9) expand jb \1.2, :2Set ;>4 ;@$+16 noexpand else expand sb \1.2 page :2set jmp :2set ;>4 ;@$+16 noexpand endif binjmp4 \1,\2,\3,\4,\5 expand :2Set noexpand pageaddr = $ >> 9 ;can't get here except by jump and so must be paged if parms > 6 if parms > 7 binjmp4 \1,\6,\7,\8,\9 else ;7 expand jb \1.2, @\8 ;=2 or 6 noexpand binjmp4 \1,\2,\3,\6,\7 endif else ;6 binjmp2 \1,\6,\7 endif endif else ;4 or less if parms > 2 if parms == 3 expand jb \1.1, @\4 ;=2 or 6 noexpand binjmp2 \1,\2,\3 else ;4 binjmp4 \1,\2,\3,\4,\5 endif else ;2 binjmp2 \1, \2, \3 endif endif endm --- James Newton: PICList.com webmaster, former Admin #3 mailto:jamesnewton@piclist.com 1-619-652-0593 phone http://www.piclist.com/member/JMN-EFP-786 PIC/PICList FAQ: http://www.piclist.com -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu