Previous page Table of contents Next page
PIC24F Microcontrollers:
Central Processing Unit (CPU)

The fundamental operation of the most Central Processing Units (CPUs) is to execute a sequence for stored instructions called a program. There are four steps that a typical CPU use in his operation: fetch, decode, execute and writeback.

The first step, fetch, is to read the instruction from the program memory. The location of the instruction is determined by a Program Counter (PC). After an instruction is fetched, the Program Counter is incremented by the size of the instruction word in order to point to the next instruction to be fetched. The Program Counter can also be modified by the program execution, making it possible to have certain types of instructions, such as: branches, jumps, subroutine calls and returns.

In the decode phase, the instructions that were fetched from the program memory are broken up into parts that have significance to other portions of the CPU. A significant portion of instructions is the Opcode. This is a number defined in the microcontroller's instruction set, indicating what operation to be performed. Depending on the Opcode, the instruction may contain additional information such as: operands, constant data, destination address, etc.

After the instruction was decoded, the execution step is performed. For instance, if a addition operation was requested, an arithmetic logic unit (ALU) will be connected to a set of inputs and to an output. Depending on the operation that was performed, a Status Register may be updated indicating the status of the last operation: for example indicating that the result of a subtraction operation was a negative value.

The final step, writeback, simply writes back the result of the execute step to a form of memory: an internal register, or a data memory. Some types of instruction manipulate the Program Counter rather than producing any direct result data facilitating loops, conditional program execution (such as executing a part of the program only if the result was negative), or subroutines calls. Other instructions may not effectively do anything at all. This operation ai known as NOP or NOOP (the name is derived from the words: "No Operation"). NOPs are most commonly used for timing purposes, to force memory alignment, to prevent hazards, to occupy a branch delay slot, or as a "place-holder" to be replaced by active instructions later on in program development (or to replace removed instructions when re-factoring would-be problematic or time-consuming code).

After the final step is completed, the entire process repeats with the next instruction cycle. In more complex CPUs, multiple instructions can be fetched, decode and executed simultaneously.

Previous page Table of contents Next page

© Copyright 2008 All Rights Reserved.