2. Microprocessor Microcontroller Architecture
2. Microprocessor Microcontroller Architecture
Architecture
Chapter 2
References
Computers as Components, Marilyn Wolf,
2012, The Morgan Kaufmann Series in
Computer Architecture and Design
Memory
Main memory (Random Access Memory or RAM)
Read only memory (Basic System Software, BIOS)
Cache (memory inside the processor)
software
instruction set
hardware
Word Length
The size of words that a processor is designed to operate
on (8-bit, 16-bit, 32-bit, 64-bit etc)
width of general purpose registers, and width of the
internal data buses is equal to processor word length
The operands for the ALU operations cannot be longer
than the word length
Memory word length need not be the same
e.g. It is possible to have a 32-bit processor (word length = 32 bits),
but memory organized as 8-bit memory words
Byte addressable
Assigns an address to each byte
Assuming a word length is 32 bits, word locations have addresses 0, 4,
8, …
Big- and Little-Endian Addressing
Two ways to assign byte address across words
OPCODE (4 bits)
0100 means add, 0101 means subtract, …
Mode 2: Direct—the instruction contains the address of the operand. Direct addressing may also
be referred to as "absolute" addressing. The address must be known at compile time.
Mode 3: Register Indirect—specifies the register holding the address of the operand. This addressing
mode is used to access memory operands pointed to by “base pointers” that are stored in registers
Mode 4: Base (Indexed) — a variation of register indirect mode, where the effective address of the
operand is calculated by the addition of a "base" register and a offset (signed displacement) included as a
field in the instruction. We could name this mode as “Register Indirect with Offset.”
Addr Contents
Memory Addr
Instruction
0x017A add r0,
0x0178 ------
[r7+ 0xA39D]
0x0179 ------
• Compile the example instruction into 0x017A opc r0 r7 reg/base one
the appropriate memory locations 0x017B 0xA39D instruction
Mode 5: PC Relative — a variation of “base mode,” where the effective address of the operand
(typically an address to jump to) is calculated by the addition of the current PC and a offset (signed
displacement) included as a field in the instruction.
Addr Contents
Memory Addr
Instruction
0x017A jmp [PC 0x0178 ------
+ 0x439D] 0x0179 ------
• Compile the example instruction into 0x017A opc PC_rel one
the appropriate memory locations 0x017B 0x439D instruction
Mode 5: PC Relative — a variation of “base mode,” where the effective address of the operand
(typically an address to jump to) is calculated by the addition of the current PC and a offset (signed
displacement) included as a field in the instruction.
Addr Contents
Memory Addr
Instruction
0x017A jcs [PC 0x0178 ------
+ 0x439D] 0x0179 ------
• Compile the example instruction into 0x017A opc PC_rel
the appropriate memory locations 0x017B 0x439D
The difference between this example and the 0x017C ------
previous one is that the “jmp” here is conditional. If 0x017D ------
the C-flag is set, the PC changes; if the C-flag is clear,
the PC does not change. : :
• 0x4518 ------
What “address” does the PC get if C=1?
0x4519 instr we’ll jmp to
PC 0x017C + 0x439D 0x451A ------
• :
What “address” does the PC get if C=0?
PC 0x017C
Indirect Address
When f has value 0x00
Uses INDF and FSR registers
INDF is not an actual register
Accessing INDF register means accessing the memory location (a
register in PIC terminology) pointed to by FSR register
PIC16F Addressing Modes …
PIC16F Program Counter
The low byte PC<7:0> comes from the PCL register,
which is a readable and writable register.
The high byte (PC<12:8>) is not directly readable or
writable and comes from PCLATH
On any reset, the PC is cleared
Modifying PC
During a write to PCL, (executing any instruction with f=
0x02), all 13 bits of the PC will change
PCLATH<4:0> → PCH
ALU Output → PCL
During a CALL or GOTO instruction
PCLATH<4:3> → PCH<4:3>
IR<10:0> → PCH<2:0>,PCL
PIC16F Program Counter …
PIC16F Instructions
Most instructions take only one instruction cycle to
complete
One instruction cycle = 4 Q cycles
Q1: Instruction Decode Cycle or forced No Operation
Q2: Instruction Read Cycle or No Operation
Q3: Process the Data
Q4: Instruction Write Cycle or No Operation