I would probably prefer the equ wherever it will work, because if you make a mistake (like I do a lot), then the error message will be more likely to happen where the mistake is. The #define is really more of a macro, and whenever you use one, as with any macro, you should be aware that you may be obscuring what is really happening, and making a place for an error to slide in where you won't see it when you stare at the code trying to figure out what's happening. After 30 years of programming, I've become convinced that anything that makes it easier to see what's happening in the code, is contributing to reliable code. Use equ's or whatever you have to name registers, because it's easier to understand. I use #define's to name individual bits because that makes code easier to understand, and when I rearrange the I/O pins, there's only one place to change. But don't use a #define or a macro to make 3 lines of code look like one just to make the code shorter unless it REALLY DOES make it easier to understand. > -----Original Message----- > From: Martin SchŠfer [SMTP:Schaefer@ELEKTRONIK21.DE] > Sent: Monday, October 25, 1999 2:56 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: Assembler Question (MPASM) > > Thank you Don, > > but if you want to name a register, which code version would you prefer > and why? Normally one uses the 'equ'-code. But makes this any sense? > > Martin > > > Don Hyde schrieb: > > > The code > > counter equ 0x20 > > > > sets an "assembler constant" to the hex value 20. The conversion of the > > symbols "0x20" to a binary value happens when the "equ" line is scanned > by > > the assembler, which you can tell because if you make a typo, the error > > message occurs at that point. Later when you reference "counter", the > > assembler performs a value substitution at that point, inserting the > binary > > value just as it would insert the value of a label. > > > > the code > > #define counter 0x20 > > > > tells the assembler to save the text "0x20". Later when the assembler > sees > > "counter", it performs a textual substitution. If you made a typo in > the > > 0x20, the error message would appear at the point where you referred to > > "counter", and not on the line where you made the actual typo. Since > it's > > text, you can put anything into a #define that you want > > (for instance #define Serial_In PORTC,7 ), and it works or doesn't work > > depending on the context where you later use it. In this case, > > btfsc Serial_In > > would work, but > > goto Serial_In > > would get an error because a comma is illegal in the target of a goto. > >