OT: 6502 and AVR similarities/differences
Posted: Tue Jan 12, 2016 7:04 pm
My intent here is *not* to start a processor war, but rather to discuss applying 6502 programming skills to the (8-bit) AVR architecture. Some inexpensive and accessible (DIP-packaged) versions are available which are ideal for simple projects.
The AVR instruction set seems to have been influenced in part by the 6502. Many instruction mnenomics are similar, or even identical. But from a programming standpoint, the AVR has some differences:
1. Half the branch length as 6502 (-64 to +63).
2. No real indexing modes, must use an indirect register. However after initialization, these can auto-increment or auto-decrement.
3. Modified Harvard architecture, separate instructions are required to read from RAM and ROM.
4. A more complete instruction set (but also more to remember).
5. No zero-page, but 32 registers which can be used in a similar fashion.
6. Better support for signed branches and comparisons.
Because the AVR can only act upon registers, a little more strategy is required. I tend to keep a few often-used constants in registers (like 0, 1, 255, etc). The penalty for loading an immediate from memory is only one extra cycle, but judicious use of the register file can make the code faster and more readable.
(Out of time, will try to add more later. I hope this was interesting so far.)
The AVR instruction set seems to have been influenced in part by the 6502. Many instruction mnenomics are similar, or even identical. But from a programming standpoint, the AVR has some differences:
1. Half the branch length as 6502 (-64 to +63).
2. No real indexing modes, must use an indirect register. However after initialization, these can auto-increment or auto-decrement.
3. Modified Harvard architecture, separate instructions are required to read from RAM and ROM.
4. A more complete instruction set (but also more to remember).
5. No zero-page, but 32 registers which can be used in a similar fashion.
6. Better support for signed branches and comparisons.
Because the AVR can only act upon registers, a little more strategy is required. I tend to keep a few often-used constants in registers (like 0, 1, 255, etc). The penalty for loading an immediate from memory is only one extra cycle, but judicious use of the register file can make the code faster and more readable.
(Out of time, will try to add more later. I hope this was interesting so far.)