Everyone jumps into the MACRO world like this and then usually abandons it for the reasons given. One suggestion that I can make: Learn to write your code in lower case. All that yelling gives me a headache! -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Andrew Warren Sent: Wednesday, July 30, 2003 1:36 PM To: PICLIST@MITVMA.MIT.EDU Subject: Re: Newbie looking for "extended instructions" macro resources? Ed Sutton wrote: > I am a PIC 16F8 newbie. One of the first things I was thinking is > start building an include file containining macros for making > helpful "extended instructions". > > This must have been done a thousand times by PIC experts. Actually, no... But it HAS been done a thousand times by PIC newbies. > ;***************************************** > ;* Macro to assign a literal to a memory location via W > ;* > ;* Note: Modifies W register > '* > ;***************************************** > MOVLWF macro l, m > MOVLW l > MOVWF M > endm Here's a small list of problems with that, in no particular order: 1. No one else will know what your non-standard macros do, so you'll never be able to post code here without explaining. 2. In this specific example, "MOVLWF" is very close to "MOVLW" and "MOVWF"; a small lapse of attention while typing will result in code that assembles without errors and LOOKS approximately correct, but nevertheless fails to work. 3. The PIC instruction sets includes a bunch of test-and-skip instructions. Sooner or later, you'll put one of them immediately above a multiple-instruction macro, and your code will break. Of course, it'll still assemble correctly and look like it should work, so it'll be difficult to debug. 4. This may never be important to you, but if you ever need to perform really extreme optimization on your code, you'll want to see each of the real PIC instructions. The further you move from that view -- through macros, compiled C, interpreted BASIC, etc. -- the harder it is to optimize. There are a number of macros built into MPASM; they're documented in the "MPASM User's Guide with MPLINK and MPLIB" (in Table B.11, on page 184, of version G). I'd limit my use of pseudo-opcode macros to those, if I were you... But that's just my opinion. -Andy === Andrew Warren -- aiw@cypress.com === Principal Design Engineer === Cypress Semiconductor Corporation === === Opinions expressed above do not === necessarily represent those of === Cypress Semiconductor Corporation -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu