Electronic – Memory architecture and instruction storage – Naimi: AVR Microcontroller

avrcomputer-architecture

LDI R16, 0x25 –> E 2 0 5 –> 1110 0010 0000 0101

Apparently, in AVR, the code and data are stored separately and each
area (code, data area) is accessed by a unique bus.

Now since the Program Counter contains the address to the next
instruction which in this case is LDI: PC --> E (PC points to 'E')

My question is, when loading the data parts (instruction) within 1 clock
cycle, well.. opcode 'E' is directly referred to by the PC. How does the
CPU find the data portion (0010 0000 0101)?

Or have I got it entirely wrong and are the 2 bytes (E + 0010 0000 0101) of the instruction
the 'code' and kept as a single unit in the code area. In which case
what is the data area – is that for instructions that use memory
addresses: eg,

LDS R10, $FFFF
Here code is the bytes for the entire instruction and the data is
probably populated by the assembler from some variable assignment?

Why then does he say:

In Sections 2-2 and 2-3, you learned about data memory space and how to
use the STS and LDS instructions. ?Then the CPU wants to execute the
?LDS
Rn,k? instruction, it puts k on the address bus of the Data Bus, and
receives data through the data bus.
For example, to execute ?LDS R20,
0x90?, the CPU puts 0x90 on the address bus. The location $90 is in the
SRAM (see Figure 2-4). Thus, the SRAM puts the contents of location $90
on the data bus. The CPU gets the contents of location $90 through the
data bus and puts it in R20.

WTH? Could someone clearly explain AVR code/data bus architecture and how
instructions are fetched and executed?

Harvard architecture in AVR

Best Answer

Okay so: LDS R10, $FFFF is the instruction and it's resolved into bytes (2 or whatever bytes) and the entire thing is stored in the 'code'.

AVR 'code' and 'data' are like C, code segment and data segment. The compiler allocates storage for variables/string literals in 'data' (not constants).

The CPU slurps the entire instruction (2 bytes) using the Program Counter register. It decodes it (extract the register/address/opcode info) and executes the instruction by latching the address onto the address bus, and taking the value off the data bus into the register R10.