I'm trying to come up to speed on AVR assembler functions. Below is a snippet from an AVR tutorial.
In this example, ADSC is a certain bit in Port ADCSRA, both defined somewhere in the header file for this AVR. In that case it starts an AD conversion (in most cases bit 6), if written to the Port ADCSRA. The expression with << causes that a One (binary 0000.0001) is shifted left six times and gets to 0100.0000. This number is written to the port ADCSRA and causes an AD conversion start.
Using this notation has the advantage, that the exact location of the ADSC bit in the ADCSRA port doesn't have to be known exactly. Its location can even change from one header file to another, without changing the source code. Compared to the formulation
the transparency is much higher. And not having to count binary zeroes is another advantage.
------- end snippet -----
Unless there is a convention I don't know about, I disagree with the above. ADSC is actually LESS transparent in the first example, because its value is defined elsewhere.
The tutorial implies that ADSC has a value of 6, but nowhere in the example is this explicitly shown.
If one maintains ADSC as an abstraction, performing the shift as an assembler directive during the ldi muddies the code, AND the bit position of ADSC is still not known. IMHO, ADSC should be defined (elsewhere) as 0b01000000 or 1<<0x06 rather than what "appears" to be 0x06. To increase transparency, the label could be changed to ADSCbit6, to differentiate it from situations where ADSC is NOT bit 6.
Obviously, defining a constant once eliminates the need, and danger, of changing multiple absolute values as hardware changes, but most of what is said in the tutorial seems to be a weak excuse to show the shift left function.
Sorry if this is too esoteric, (or just plain picky):-) but I want to make sure I have a solid foundation, rather than get misled by a poorly written bit of instruction.