On Fri, 15 Feb 2002 00:59:40 -0800 Ray Gallas writes: > Obviously, MACROs must have some good reason for existing, > otherwise, > why would anyone use them? So my question is, what's the difference > between a MACRO, and just using a subroutine? Why would one choose > one > over the other in a given situation? > When the assembler finds a call subroutine instruction, it inserts the CALL instruction with the address of the subroutine. The existing program counter is put on the stack and the address of the subroutine is put in the program counter. When the return instruction is encountered by the processor in the subroutine, it pulls the return address from the stack and continues execution with the instruction after the call. With a macro, on the other hand, the actual code of the macro is inserted into the program EVERY TIME THE MACRO IS "INVOKED." So, using a macro invocation (sounds religious, doesn't it...) results in a larger program. However, it is a little faster (no return address storage and recovery) and results in a less deep stack (which can really be a concern on a PIC... How many times have you been deep in mainline code subroutine calls and then have an interrupt cause a stack overflow?). What I REALLY like about macros is the use of big arguments and multiple arguments. For example, the code below calls a subroutine that puts a message up on the lcd, but I don't have to deal with loading the high byte and low byte of the pointer into the message. Just call it as MsgToLcd(SomeMessage) and it happens! MsgToLcd macro msg ; Set up pointers and send a messag to LCD movlw high(msg) movwf MsgHi movlw low(msg) movwf MsgLo call LcdMsg endm I also have macros for setting banks (bank0, bank1, bank2, etc.) so I don't have to remember all those rp bits. I also have macros for saveContext and RestoreContext for use in my interrupt service routine. Harold FCC Rules Online at http://hallikainen.com/FccRules Lighting control for theatre and television at http://www.dovesystems.com ________________________________________________________________ GET INTERNET ACCESS FROM JUNO! Juno offers FREE or PREMIUM Internet access for less! Join Juno today! For your FREE software, visit: http://dl.www.juno.com/get/web/. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body