2.2 Instruction Execution

A computer is controlled by a program, which is composed of sequences of instructions. At the assembly language level, each instruction specifies one fundamental operation to be performed by the CPU. Instructions can be classified into six basic categories:

  1. Data movement instructions move data from one location in memory to another, between memory and registers, among registers, or between memory and I/O devices.

  2. Arithmetic instructions perform various mathematical operations, such as the addition of one quantity to another.

  3. Logical instructions perform Boolean operations, such as AND, OR, and EXCLUSIVE OR.

  4. Comparative instructions examine a value, or compare values, as part of setting up decisions for conditional program flow.

  5. Control instructions, such as branches or jumps, change the dynamic execution of a sequence of instructions by causing program execution to go to a specified instruction, either unconditionally or based on the results of a comparative, logical, or arithmetic instruction.

  6. Semaphore instructions provide the basis upon which operating systems can protect shared data and synchronize simultaneously running processes and threads.

These conceptual categories do not necessarily map one-to-one onto any actual machine architecture. For instance, the Itanium architecture uses two very different instruction types for data movement: one type to move data between memory and registers and another type to move data among registers.

Instructions are stored in memory, as are the data on which they operate. Depending on the architecture, an instruction in memory can occupy several consecutive words or bytes (Tables 1-3, 1-4, and 1-5). Each architecture has its own representation of instructions, but every instruction is typically composed of two basic components:

  • an operation code (opcode), which specifies the function to be performed (e.g., add, subtract, compare, jump); and

  • one or more operand specifiers, which describe the locations of the information units that must be accessed when the operation is performed; these information units (more precisely, their contents) are the operands of the instruction.

The processor fetches an instruction from memory, decodes the operation code, and executes the appropriate function on its operands.

The location (memory address) of the next instruction to be executed is held in a special internal CPU register called the instruction pointer (IP) or the program counter (PC). When a program is first loaded into memory, the IP is initialized with the address of the first instruction of the program. Using the IP, the CPU fetches this instruction along with any operand specifiers. The operands themselves are then fetched, the operation is performed, and any results generated are stored back in memory or in a register. Figure 2-4 shows the complete cycle of fetching, interpreting, and decoding an instruction.

Figure 2-4. Instruction execution

graphics/02fig04.gif

Whenever an instruction is fetched, the IP is modified to point to the next instruction. In this way, the processor can readily execute instructions one after another in sequence. A few instruction types produce skip, branch, or jump effects; these are the machine language equivalents of GOTO in a language such as BASIC. When one of these instruction types is executed, it changes the contents of the IP in such a way that a new location, no longer the next one in sequence, will be taken as the information unit containing the "next" instruction to be executed.

A complete computer program will consist of both instructions and data, with each instruction or data element loaded at a unique address in memory when the program runs. If we were to inspect arbitrary memory units, we would have great difficulty differentiating data from instructions because both are merely sequences of binary digits. Moreover, there may well be numerous sorts of data elements, such as integers, floating-point numbers, or character strings. How does the computer "know" that some of these numbers are machine instructions, while others are data?

When a program is produced using a compiler or assembler and other system software, its starting address is made part of the stored form of the program. The loading process sets that address, which could be anywhere in memory, into the IP just before the program starts to run. Once this single master "pointer" is known, everything has a context: Instructions come along in sequence unless there are changes in the direction of program flow, and the operand specifiers within each instruction guide the processor towards finding and appropriately working with each of the data locations.



ItaniumR Architecture for Programmers. Understanding 64-Bit Processors and EPIC Principles
ItaniumR Architecture for Programmers. Understanding 64-Bit Processors and EPIC Principles
ISBN: N/A
EAN: N/A
Year: 2003
Pages: 223

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net