|
From: | E. Weddington |
Subject: | Re: [avr-gcc-list] What Happened to the sbi() and cbi() Macros???? |
Date: | Fri, 04 Feb 2005 07:32:52 -0700 |
User-agent: | Mozilla Thunderbird 1.0 (Windows/20041206) |
Pertti Kellomäki wrote:
This is what has been objected to in many posts. I am still mystified what metric makes SFR &=~mask; simpler and cleaner than cbi(SFR, bit_num); It is not that I cannot decode the first form. I can still after twenty years write RCA 1802 assembly in hex from my head. I just prefer "clear this bit in SFR for me" to "negate this bitfield, do a bitwise and, and assign the result to SFR".
In practice, when you read that, you don't break it down into individual operations. You look at it as a whole and begin to see patterns:
set bit: v |= m clear bit: v &= ~m toggle bit: v ^= m read bit: v & mThe downside to reading it as a whole, is when you're debugging somebody else's code who may not have written it very well, causing strange errors.
However, the upside is that you can then begin to combine them in unique ways to achieve a pretty efficient operation:
v = ((v & ~m1) | m2 ^ m3); YMMV. Eric
[Prev in Thread] | Current Thread | [Next in Thread] |