Hardware Reference
In-Depth Information
For the program counter circuit shown in Figure 1.4,
Whenever power is turned on to the microcontroller, the program counter is forced
to 0 and the instruction fetch will start from address 0.
If the instruction being executed is a conditional branch instruction and the branch
condition is true, then the branch signal will be 1, the sum of the current PC and
branch offset will be loaded into the PC, and instruction execution will continue
from that address.
If the instruction being executed is a jump instruction, then the value Jump target
will be loaded into the PC.
If the instruction being executed is not a program flow control instruction, then
the PC is simply incremented by 1 after each instruction byte is fetched.
Other microprocessors or microcontrollers may have a different program flow control
scheme and may fetch more instruction bytes in one fetch. In that case the program counter
shown in Figure 1.4 will need to be modified accordingly.
1.6.2 Where Does the Processor Start to Execute the Program?
As discussed earlier in this chapter, the program counter holds the address of the next
instruction to be fetched, so the value of the program counter must be known when power
is turned on. One approach is to force the PC to a fixed value when power is turned on. The
circuit shown in Figure 1.4 forces the PC to 0 whenever power is turned on. Many 8-bit micro-
controllers including Microchip PIC, all Intel 8051 variants, and Atmel AVR use this approach
because it is easy to implement.
Another approach is to fetch the program starting address from a fixed (known) memory
location whenever the power is turned on. The Freescale microcontrollers use this approach.
The HCS12 microcontroller from Freescale fetches the program starting address from memory
locations at 0xFFFE and 0xFFFF into PC and then start program execution from there. This
approach is slightly more complicated.
Another way to restart program execution is to apply a reset signal to the processor. All
microprocessors and microcontrollers have a reset pin that allows the user to force the proces-
sor to start from scratch. The effect is identical to turning on the power.
1.6.3 Instruction Execution Process
The instruction sets of most commercial processors are irregular and complicated. The
complexity of the instruction set makes it difficult to explain the instruction execution pro-
cess. In the following, we assume that there is an 8-bit processor X with instruction set shown
in Table 1.2. The opcode of any instruction is 1 byte and is always the first byte of the instruc-
tion. The processor X has an 8-bit accumulator A and a 16-bit pointer register ptr . The data
memory and program memory are separate and are each 64 kB in size. The register ptr is used to
point to data memory and supports indirect memory addressing for data memory. The instruc-
tion set of the processor X allows the instructions to use an 8-bit address to access the lowest
256 bytes (addresses 0 to 255) of data memory. The processor X can use the 16-bit ptr register to
access any location of the 2 16 data memory locations.
To facilitate the access of data memory, processor X includes the memory data reg-
ister ( MDR ) to hold the data received from data memory and data to be written to the data
memory.
 
Search WWH ::




Custom Search