Академический Документы
Профессиональный Документы
Культура Документы
❖ Embedded systems:
After power-up, the processor starts to execute all their
programs from the nonvolatile memory.
THE CIRCUIT OF THE PROGRAM COUNTER
The program counter consists of D-type flip-flops and other additional logic gates as
shown in figure 1.
The D value may be transferred to Q on either the rising or the falling edge (but not both
edges) of the CLK input.
The CLK signal is the clock input signal.
The Q signals of all the flip-flops of the program counter determine the address of the
next instruction to be fetched.
The set and reset inputs are active low and cannot be low at the same time.
➢ When set is low, the Q signal is forced to 1.
THE CIRCUIT OF
THE PROGRAM
COUNTER
Figure 2. A simplified block diagram of the program counter (PC) of an 8-bit microcontroller
THE CIRCUIT OF THE
PROGRAM COUNTER
To have a better understanding of how the µprocessor/µcontroller read and execute instructions, we
assume that we have:
An 8-bit µprocessor X with:
An 8-bit accumulator (A)
4. Control unit places 0x0020 on the data memory address bus and
the value 0x00 on the data memory data bus to perform a write CPU
operation. The value 0x00 is to be stored at data memory location
0x0020, as shown in Figure 4.
0x00 00 0x20
Data Memory xx Data Memory
data bus address bus
xx
xx
xx
xx
PC status
xx Before read 0x0003
xx After read 0x0003
Data Memory
CPU CPU
Figure 5. Instruction 1-opcode read cycle Figure 6. Instruction 1-data memory write cycle
ld ptr,#0x2000 (Machine code 90 20 00)
1. The value in the PC (0x0006) is placed on the program memory ptr: 0x2000
address bus with a request to read the contents of that location. CPU
2. The 8-bit value at the location 0x0006 is the instruction opcode Program Memory Program Memory
0x90. At the end of this read cycle, the PC is incremented to data bus address bus
0x0007. The opcode byte 0x90 is fetched. Figure 7 shows the 75
opcode read cycle. PC status
20
3. The control unit recognizes that this instruction requires two more Before read 0x0006
00
read cycles to the program memory to fetch the 16-bit value to be After 1st read 0x0007
75 After 2nd read 0x0008
placed in the ptr register. These 2 bytes are stored immediately
after the opcode byte. The control unit continues to perform two 21 After 3rd read 0x0009
more read cycles to the program memory. At the end of each read 14
cycle, the processor X stores the received byte in the ptr register 0x90 90 0x0006
upper and lower bytes, respectively. After these two read
0x20 20 0x0007
operations, the PC is incremented to 0x0009.
0x00 00 0x0008
Program Memory
Figure 7. Instruction 1-opcode read cycle
ld A,@ptr (Machine code E0)
Program Memory
4. The data memory returns the contents to the processor and the Data Memory Data Memory
processor places it in accumulator A. The process is shown in data bus address bus
figure 9. 00
0x20 20
xx
xx
xx
ED 0x2000
xx PC status
xx Before read 0x000A
Program Memory
1. The value in the PC (0x000C) is placed on the program memory address bus with a request to read the contents of that location.
2. The 8-bit value at the location 0x000C is the instruction opcode 0x70. At the end of this read cycle, the PC is incremented to
0x000D. The program memory returns the opcode byte 0x70 to the CPU.
3. The processor recognizes that this is a conditional branch instruction and it needs to fetch the branch offset from the program. So
it places the PC value (0x000D) on the program memory address bus with a read request. At the end of this read cycle, the
processor increments the PC to 0x000E.
4. The program memory returns the branch offset 0x02 to the CPU. The CPU checks the contents of accumulator A to determine
whether the branch should be taken. Let’s assume that A contains zero and the branch is not taken. The PC remains at 0x000E. If
A contains a nonzero value, the next instruction will be skipped.
inc 0x20 (Machine code 05 20)
1. The value in the PC (0x000E) is placed on the program memory address bus with a request to read the contents of that location.
2. The 8-bit value at the location 0x000E is the instruction opcode 0x05. At the end of this read cycle, the PC is incremented to
0x000F. The program memory returns the opcode byte 0x05 to the CPU.
3. The processor recognizes that it needs to increment a data memory location; this requires it to fetch an 8-bit address from the
program memory.
4. The processor places the value in the PC on the program memory address bus with a read request. At the end of the read cycle,
the PC is incremented to 0x0010 and the value 0x20 is returned to the CPU.
5. The processor places the value 0x20 on the data memory address bus with a request to read the contents of that location. The
data memory returns the value of that memory location at the end of the read cycle, which will be placed in the MDR.
7. The processor places the contents on the data memory data bus and places the value 0x0020 on the data memory address bus
and indicates this is a write cycle. At the end of the cycle, the value in the MDR is written into the data memory location at 0x20.
dbnz 0x21, loop (Machine code D5 21 0A)
1. The value in the PC (0x0010) is placed on the program memory address bus with a request to read the contents of that location.
2. The 8-bit value at the location 0x0010 is the instruction opcode 0xD5. At the end of this read cycle, the PC is incremented to
0x0011. The program memory returns the opcode byte 0xD5 to the CPU.
3. The CPU recognizes that it needs to read a data memory address and a branch offset from the program memory.
4. Processor X performs two more read operations to the program memory. The program memory returns 0x21 and 0x0A. At the
end of these two read cycles, the PC is incremented to 0x0013.
5. Processor X places 0x21 on the data memory address bus with a read request. At the end of the read cycle, the value of the data
memory location at 0x21 is returned to the CPU which will be held in the MDR.
6. Processor X decrements the contents of the MDR. The contents of the MDR are then placed on the data memory data bus.
Processor X also places the address 0x21 on the data memory address bus with a write request to store the contents of the MDR
in data memory.
7. If the value stored in the MDR is not zero, processor X adds 0x0A to the PC and places the result in the PC (this causes a branch
behavior). Otherwise, the PC is not changed.