Search code examples
avr

Confusion with instruction register and counter register


I have difficulty in understanding the workings of instruction register and counter register in avr micro-controller like an atmega128p.

Is there a way to explain what they do in a simple way?


Solution

  • I suppose you are interested in the difference between the Instruction Register(IR) and Program Counter (PC).

    Their working principles are pretty simple.

    • IR: Holds the instruction that will be or is currently executed
    • PC: Holds the address of the instruction that should be loaded into IR from flash memory in the next clock cycle.

    Note that AVRs normally use a 2-stage pipeline (fetch + execute) therefore the IR is double buffered (inside a clock cycle the next instruction is loaded from flash and the current instruction is executed).