I recently read zbaird's "Assembly Language Programming Using The AVRButterfly. " While I didn't actually work through the experiments that Chuck provided in the book with an actual Butterfly, I did study the code and, for the most part, got the jest of the intent.
However, what reading Chuck's book did do was inspire me to play with assembly language on the AVR. I do have about 20 years experience with assembly language on the MC6802 and MC68Hc11 MCU's so, I wasn't exactly starting out from the beginning.
What I did is purchased an Ardunio kit from SmileyMicros, not for the programming features afforded with the Arduino methodology but, rather, because of the Arduino's small board size. The though is that, because of the Arduino's small size, it more easily enables me to mess around with assembly experiments while at work
To date, I have written assembly code to talk to my PC notebook over the USB communications connection. I've also written an interrupted TIMER1 handler and routines to send text and ANSI terminal codes to the terminal, allowing me to place the text anywhere on the PC's screen - using HyperTerminal, of course.
So then, having laid out the ground work, my question is this...
During one of the many debugging efforts, I found myself having trouble deciphering the instruction code and exactly what the HEX code represented.
As always, my first approach is to read the pertinent literature. So I got out the AVR Instruction Set manual - doc0856. What I found is that the instructions seem to be split across the two bytes of each word. As and example:
; Early on in the program I assign a general working register as: .def acca = r20 ; ; ; ; Later in the program: 0000a6 e478 ldi USART0_Data, 'H'
And the assembly users manual description of the Load Register Immediate instruction:
Description: Loads an 8 bit constant directly to register 16 to 31. Operation: Rd <- K Syntax: Operands: Program Counter: LDI Rd,K 16 â‰¤ d â‰¤ 31, 0 â‰¤ K â‰¤ 255 PC <- PC + 1 16-bit Opcode: 1110 KKKK dddd KKKK
Where in the high byte:
1110 is the actual instruction and the high niggle (KKKK) is the upper nibble of the immediate data
and in the second byte:
The high nibble holds dddd, the destination register, followed by the lower nibble of the immediate data (KKKK) in the low nibble of the second byte.
0000a6 e478 ldi USART0_Data, 'H'
In fact, 0x48 (the second and fourth nibbles in the instruction) does equal 'H'
This seems odd to me. Every other MCU I've worked with, the entire instruction filled the entire byte while the immediate data filled the entire next byte.
Is this scheme particular to the AVR or, is this an inherent difference between Von Neumann and Harvard architectures?
JS, you should be proud of me!!!