I have just added a bunch of enhancements to the PIC assembler pre-processor PREPIC. It is included in the PIC development tools release that can be downloaded from http://www.embedinc.com/pic/dload.htm. The updated PREPIC documentation file can be viewed at http://www.embedinc.com/pic/prepic.txt.htm. The major enhancements are the ability to pass arguments to subroutines, and preprocessor macros that look like native PIC assembler macros. Unlike MPASM macros, PREPIC macros can determine whether a particular argument was passed, and can use these arguments arbitrarily, including building new symbol names. Since PREPIC has its own symbols, various computations can be performed to produce assembler code while guaranteeing not to collide with assembler symbols. Since PREPIC runs before the assembler, you can even use it to "hook" native assembler opcodes and directives. The PREPIC macro can emit the expected MPASM code, but also save or look at preprocessor state and perform other operations. Just as a example not pretending to be useful, I created a macro for RES and a new macro SETVAR. The enhanced RES does the same thing the basic RES does, but also defines additional pre-processor constants based on the variable name that indicate the size of the variable and the bank it is in. SETVAR uses that information to set the variable to a constant value. Yes, I know more optimizations are possible. The point was to demonstrate some of the new PREPIC capabilities, not to be useful code. Here is the original source file: //********************************************************************* // // Macro [name] RES, n // // Do RES but also create NAME_BANKADR to indicate a address // in the same bank as the new variable NAME, and NAME_SIZE to // indicate the variable size in bytes. // // The global preprocessor variable BANKADR_CURR contains a address // within the bank that RES will allocate memory in. If it does not // exist, then the variable will be assumed to be in unbanked // memory. // /macro res /write [qstr [arg -1] res [arg 1]] /if [exist 0 arg] then ;label was supplied ? /var local adr integer = -1 ;init bank adr to indidate unbanked /if [exist "bankadr_curr"] then ;bank address supplied ? /set adr bankadr_curr ;use the supplied bank address /endif /const [arg -1]_bankadr integer = adr /endif /const [arg -1]_size integer = [arg 1] /endmac //********************************************************************* // // Macro SETVAR name, [val] // // Set the variable NAME to the value VAL. The default for VAL is 0. // /macro setvar /var local val integer = 0 ;get default value /if [exist 2 arg] then ;value was supplied ? /set val [arg 2] ;use the supplied value /endif dbankif [arg 1]_bankadr ;set bank for access to the variable /var local byten integer = 0 /var local bval integer ;value for the current byte /block /set bval [and 255 [shiftr val [* byten 8]]] ;get value for this byte /if [= bval 0] /then clrf ([arg 1])+[v byten] /else movlw [v bval] movwf ([arg 1])+[v byten] /endif /set byten [+ byten 1] /if [< byten [arg 1]_size] then /repeat /endif /endblock /endmac //********************************************************************* // // Some real code. // /var exist bankadr_curr integer = 128 ;set address within this bank bank1 udata myvar res 4 ;my very own variable junk res 2 ;trash can code setvar myvar, 65538 ------------------------------------------------- Here is the resulting MPASM file produced from the above: bank1 udata myvar res 4 ;my very own variable junk res 2 ;trash can code dbankif myvar_bankadr ;set bank for access to the variable movlw 2 movwf (myvar)+0 clrf (myvar)+1 movlw 1 movwf (myvar)+2 clrf (myvar)+3 ******************************************************************** Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products (978) 742-9014. Gold level PIC consultants since 2000. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist