From: Self To: PICLIST@MITVMA.MIT.EDU Subject: Re: Current assembler adress Reply-to: ruben@mail.bip.net Date: Tue, 27 Jan 1998 13:07:02 Hello Morgan. I use these macros for automaticaly setting and resetting PA0 and PA1 to the right values for a 16C57. #define lcd_bank 3 org 0 ;bank0 ... xcall lcd_bank,sendchar ;A call to bank 3 from bank 0. would expand to: #define lcd_bank 3 org 0 ;bank0 ... bsf f_pa0 bsf f_pa1 call sendchar ;A call to bank 3 from bank 0. bcf f_pa1 bcf f_pa0 The xgoto only sets the bankselsect bits before the goto instruction. I use the bset and breset macros to set the bankswitches for several calls. #define lcd_bank 3 org 0 ... bset lcd_bank ;set bank to lcd_bank call lcd_init call lcd_send_start_msg breset lcd_bank ;switch back from lcd_bank to current bank. would expand to #define lcd_bank 3 org 0 ... bsf f_pa0 ;set bank to lcd_bank bsf f_pa1 call lcd_init call lcd_send_start_msg bcf f_pa1 ;switch back from lcd_bank to current bank. bcf f_pa0 The point is that only the bits that needs to be modified are modified. If a xcall is used to a location within the same bank no bankselect bits are thus modified. As you can see the '$' is used to find out the current adress. I have to supply the bank argument to the macro because if the preprocessor use a forward reference it doesn't know how many instructions the macro will expand to which will give me an error of something like 'label doesn't have the same adress in pass 1 and pass 2.'. In labels after the macro invocation and before the next ORG statement. ;---- Long call macro --------------------------------------------------------- xcall macro bank,label local this_bank this_bank set ($>>9) & 0x03 if ((this_bank & 0x01) != (bank & 0x01)) if (bank & 0x01) bsf f_pa0 else bcf f_pa0 endif endif if ((this_bank & 0x02) != (bank & 0x02)) if (bank & 0x02) bsf f_pa1 else bcf f_pa1 endif endif call label if ((this_bank & 0x02) != (bank & 0x02)) if (bank & 0x02) bcf f_pa1 else bsf f_pa1 endif endif if ((this_bank & 0x01) != (bank & 0x01)) if (bank & 0x01) bcf f_pa0 else bsf f_pa0 endif endif endm ;---- Long goto macro ---------------------------------------------------------- xgoto macro bank,label local this_bank this_bank set ($>>9) & 0x03 if ((this_bank & 0x01) != (bank & 0x01)) if (bank & 0x01) bsf f_pa0 else bcf f_pa0 endif endif if ((this_bank & 0x02) != (bank & 0x02)) if (bank & 0x02) bsf f_pa1 else bcf f_pa1 endif endif goto label endm ;---- bank set macro ----------------------------------------------------------- bset macro bank local this_bank this_bank set ($>>9) & 0x03 if ((this_bank & 0x01) != (bank & 0x01)) if (bank & 0x01) bsf f_pa0 else bcf f_pa0 endif endif if ((this_bank & 0x02) != (bank & 0x02)) if (bank & 0x02) bsf f_pa1 else bcf f_pa1 endif endif endm ;---- bank reset macro -------------------------------------------------------- breset macro bank local this_bank this_bank set ($>>9) & 0x03 if ((this_bank & 0x02) != (bank & 0x02)) if (bank & 0x02) bcf f_pa1 else bsf f_pa1 endif endif if ((this_bank & 0x01) != (bank & 0x01)) if (bank & 0x01) bcf f_pa0 else bsf f_pa0 endif endif endm ;------------------------------------------------------------------------------ > How to get it? > > I want to make macros thet themselves decide if it is necessary so set page > bits and PCLATH when calling and jumping. > > So, in assemly time the macro have to know the adress of where it is compiled. > Another assembler i've used used a * to represent current adress. > It could be used like this: > > current_ROMadress=* > > Where current_ROMadress is a macro variable which will be processed and > compared with the adress we want to call, and only if needed the PCLATH > setting code need to be compiled. (saves space and execution time, without > I have to mind about it) > > (I'm using MPLAB 3.30) > > Thanks in advance > /Morgan > > Morgan Olsson, MORGANS REGLERTEKNIK, Sweden, ph: +46 (0)414 70741; fax 70331 > ============================================================================ > ----------------------------------- Ruben Jšnsson AB Liros Elektronik, Sweden maxruben@mail.bip.net -----------------------------------