----- Original Message ----- From: James Newton. Admin 3 To: Sent: Saturday, February 16, 2002 12:03 AM Subject: Re: [PIC]:Basic question about macros > source= http://www.piclist.com/postbot.asp?id=piclist\2002\02\15\115958a > > Nick has hit on the real power of Macros... they allow one to extend the > language of the assembler. Sorry but I really think this is secondary to their ability to help overcome the shortfalls of a given processor :-) Consider a processor such as a 6502 which has a 16 bit address space and only 8 bit index registers. It uses page zero variables as dedicated 16 bit indirect base registers. Writing functions for this processor that use a dedicated set of page zero variables causes problems when you try to use the function in both the main line and an interrupt service routine OR another function that uses the same page zero variables. Using a macro, the function can be turned into a template and several versions of the function (using different page zero variables) can be easily generated. > You can define new assembly language instructions, or fill in for > instructions that you like to use but that aren't available on your current > target. There are macro sets that allow you to program using PIC > instructions in assemblers designed for the SX and for the SX in MPASM. I > even started on a macro set for 6800 instructions for the SX... not > finished, but I can be done. I agree, but then why not go the whole hog and produce a meta assembler that can understand 6800 or Z80 instructions and addressing modes and generate the equivalent PIC or SX binary? The xcasm meta assembler can currently do this if you want. > They can be set up to make complex decision and generate code for you. On > the PIClist.com site there are macros to calculate SPBRG? SBRGP? (What the > heck ever that bit rate register is) settings for PICs, generate comparison > and branching code and even help with banks and paging. > > In my work with the SX, whenever I find myself doing the same damn thing > over and over, I stop and write a macro for it. I have quite a library and > most of my code looks pretty high level even though it is written for the > little assembler in the SXKey. I don't even think about pages because my > macros automatically build a jump table in low memory for the subroutines > that happen to fall into the second half of each page. > > A truly great macro pre-processor is what makes C into C++. If you are refering to the AT&T C++ CFRONT C pre-processor that converts C++ into C, I thought it was actually a compiler that generates C source instead of assembler source, not really a C pre-processor in the same sense as the normal C pre-processor that provides macros via #define directives in standard C. >And the holy > grail of macro languages is a meta language that allows you to build new > languages. Been there done that (about 15 years ago). Parts of that system are used today in xcasm, zmech (a case tool of which there just so happens to be a PIC version available) and xebot ;-) The problem with using a macro processor to define a language is that it needs the capability to invoke different macros with the same name depending on the context in which the macro is presented in the source. To describe the way the macro processor should unambiguously distinguish the contexts requires a non-trivial description of the relationships between each macro and the context in which it can appear. The simplest way to do describe it is to use extended BNF and have the macro processor sort it all out internally. e.g. expr ::= identifier | unary_op expr | expr binary_op expr There are other systems you might like to play with that accept grammar rules and generate parsers for you such as YACC and BISON, but they are not for the faint hearted. Putting it much more simply, the macro processor has to do complex pattern matching and you have to provide the complex patterns. Unlike most other meta assemblers, xcasm directly uses extended BNF to describe the assembler syntax, mnemonics and addressing modes. > > All power is in the macros! Definitely! Regards Sergio http://www.xcprod.com/titan -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads