What is the main topic of Lecture 9?
How a microcontroller program runs internally: CPU architecture components and the fetch–decode–execute cycle, illustrated with a C program translated to assembly on the ATmega328.
Which core CPU registers were introduced earlier in the module and recapped here?
General purpose registers, status register, program counter, and stack pointer.
Which of those registers can the programmer directly access and manipulate?
General purpose registers, status register, and stack pointer (the program counter is mostly handled by hardware, but can be affected indirectly by jumps/calls).
What is the ALU (Arithmetic Logic Unit)?
The part of the processor that performs arithmetic and logical operations on data from storage.
What width is the ALU in the ATmega328?
8-bit.
What are the ALU’s inputs and outputs?
Two 8-bit inputs, an opcode (operation), an 8-bit result, and status flags (e.g. carry, zero) written to the status register.
Where are the ALU’s status flags stored?
In the status register (SREG).
In general, how does the ALU operate on data?
Data are loaded from storage into the ALU inputs, an arithmetic/logic operation (ADD, SUB, AND, OR, etc.) is performed, and the result is written back to storage.
What is an example AVR instruction handled by the ALU?
ADD (add without carry) – it adds two registers and updates flags.
What are the four main highlighted components in the ATmega328 CPU core diagram?
General purpose registers, program counter, stack pointer, and status/control register, plus the ALU.
How many general purpose registers does the ATmega328 have and how wide are they?
32 registers, each 8 bits wide.
What is the width of the program counter (PC) in the ATmega328?
14 bits.
What does the program counter store?
The address of the next instruction or operand to be fetched.
What is the stack pointer used for?
It holds the address of the top (last item) of the stack in SRAM.
What is the stack used for in a microcontroller?
Temporarily storing data, return addresses, and MCU state via push/pop during function calls and interrupts.
What does the status and control register (SREG) hold?
Flags describing the state of the processor after the last instruction (e.g. Zero, Carry) and some control bits (e.g. global interrupt enable).
Where are the general purpose registers located in the memory space?
At the bottom of the data space so they can be accessed directly by the ALU.
What is an accumulator in lower-spec CPUs?
A single register used for most arithmetic and logic operations instead of a register file.
Which simplified block diagram is used in this lecture?
A microcontroller core showing CPU, clock, control unit, MAR, MDR, IR, instruction decoder, and buses.
What does the clock do in a microcontroller?
Generates a periodic high/low signal that synchronises the actions of all internal components.
What waveform does a typical microcontroller clock generate?
A square wave with (ideally) 50% duty cycle and fixed frequency.
What is meant by “duty cycle”?
The fraction of one clock period during which the signal is high (e.g. 50% means high for half, low for half).
What happens at each clock cycle with respect to instruction execution?
One step in the fetch–decode–execute cycle is performed.
What internal clock does the ATmega328 ship with?
An internal RC oscillator at 8 MHz.