I have made a small utility that I run just before the assembler (sort of a preprocessor) which does just what You want. The utility which I call PICBIT (I know there is something else also called PICBIT) scans the source file for my special declarations and then produces a file which can be included in the sourcefile. It also scans other includefiles (even includefiles in includefiles) in the source and handles them correctly. Here is the special declaration in my main sourcefile or any includefile included in this: ;@BITNAME REGISTER BIT Which creates the following lines in the produced includefile: b_BITNAME EQU BIT m_BITNAME EQU 1< G'day to all. > > I am reworking some code and would like to improve some of my register > handling. > > I currently use #define statements where ever possible to identify > bits. They have the great benefit that I don't have to keep track of > which bits belong with which registers and have eliminated many hours > of tracking down stupid mistakes. > > Some while back, I came up with a series of macros that generate masks > based upon those bit defines. Again, they help minimize my mistakes. > > Those macros take the form of: > movbw MACRO reg,bit ;load w with selected bit > movlw b'00000001' << bit > endm ;Z, C & DC unchanged > > Typical usage is: > > #define _TICK AD1FLG,4 ;defined way up near the front > of the co > de > > movfw AD1FLG ;TMR0 tick bit different from FLAGS > tick bit? xorwf TMR0,W ; andbw _TICK > ;mask all but bit of interest bz WdogLoop > ;same? movbw _TICK xorwf AD1FLG,F ;flip FLAGS > tick bit for next time thru > > The chunk of code above illustrates what my problem is now. The bit > defines themselves work just fine, but I want the register that the > bit belongs to also to be automated. In other words, if I manipulate > a bit and then stick it back into its register, I want the code to be > able figure out which register it belongs to. > > I could do it the same way as I did the bits (create macros for every > usable instruction) but there just has to be a better way. > > One of my attempts looks like: > bitreg MACRO reg,bit,dest ;determine register belonging > to bit > reg,dest > endm > > with usage as follows: > movbw _DISPF2 ;generate flash at 1/2 packet rate > btfsc _FLASH ; > xorwf bitreg,_DISPF2,F > > and resulting in the following messages: > Error[108] E:\PIC\PLC\CIS3P0A.ASM 3383 : Illegal character (,) > Warning[225] E:\PIC\PLC\CIS3P0A.ASM 3383 : Invalid label in operand > (bitreg) > > That little 3 line snippet above is supposed to assemble as: > movlw b'01000000' > btfsc DISPCNT,7 > xorwf FLAG,F > > where _DISPF2 is bit 6 of register FLAG > > Any thoughts? Ideas? > > dwayne > > > Dwayne Reid > Trinity Electronics Systems Ltd Edmonton, AB, CANADA > (780) 489-3199 voice (780) 487-6397 fax > > Celebrating 16 years of Engineering Innovation (1984 - 2000) > > * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * > Do NOT send unsolicited commercial email to this email address. > This message neither grants consent to receive unsolicited > commercial email nor is intended to solicit commercial email. ============================== Ruben Jvnsson AB Liros Elektronik Box 9124, 200 39 Malmv, Sweden TEL INT +46 40142078 FAX INT +46 40947388 ruben@pp.sbbs.se ==============================