Hardware Reference
In-Depth Information
and stores the result back in one of the registers. The process of running two oper-
ands through the ALU and storing the result is called the data path cycle and is
the heart of most CPUs. To a considerable extent, it defines what the machine can
do. Modern computers have multiple ALUs operating in parallel and specialized
for different functions. The faster the data path cycle is, the faster the machine
runs.
2.1.2 Instruction Execution
The CPU executes each instruction in a series of small steps. Roughly speak-
ing, the steps are as follows:
1. Fetch the next instruction from memory into the instruction register.
2. Change the program counter to point to the following instruction.
3. Determine the type of instruction just fetched.
4. If the instruction uses a word in memory, determine where it is.
5. Fetch the word, if needed, into a CPU register.
6. Execute the instruction.
7. Go to step 1 to begin executing the following instruction.
This sequence of steps is frequently referred to as the fetch-decode-execute cycle.
It is central to the operation of all computers.
This description of how a CPU works closely resembles a program written in
English. Figure 2-3 shows this informal program rewritten as a Java method (i.e.,
procedure) called interpret . The machine being interpreted has two registers visi-
ble to user programs: the program counter ( PC ), for keeping track of the address of
the next instruction to be fetched, and the accumulator ( AC ), for accumulating
arithmetic results. It also has internal registers for holding the current instruction
during its execution ( instr ), the type of the current instruction ( instr type ), the ad-
dress of the instruction's operand ( data loc ), and the current operand itself ( data ).
Instructions are assumed to contain a single memory address. The memory loca-
tion addressed contains the operand, for example, the data item to add to the accu-
mulator.
The very fact that it is possible to write a program that can imitate the function
of a CPU shows that a program need not be executed by a ''hardware'' CPU con-
sisting of a box full of electronics. Instead, a program can be carried out by having
another program fetch, examine, and execute its instructions. A program (such as
the one in Fig. 2-3) that fetches, examines, and executes the instructions of another
program is called an interpreter , as mentioned in Chap. 1.
 
 
 
Search WWH ::




Custom Search