Docsity

Understanding Computer Architecture: CPU, Memory, and Machine Language, Lab Reports of Data Acquisition

Toggle sidebar
bg1
In this chapter we will learn how a computer manipulates data and
communicates with peripheral devices such as printers and key-
boards. In doing so, we will explore the basics of computer archi-
tecture and learn how computers are programmed by means of
encoded instructions, called machine language instructions.
CHAPTER
2
2.1 Computer Architecture
CPU Basics
The Stored-Program Concept
2.2 Machine Language
The Instruction Repertoire
An Illustrative Machine Language
2.3 Program Execution
An Example of Program
Execution
Programs Versus Data
*2.4 Arithmetic/Logic
Instructions
Logic Operations
Rotation and Shift Operations
Arithmetic Operations
*2.5 Communicating with
Other Devices
The Role of Controllers
Direct Memory Access
Handshaking
Popular Communication Media
Communication Rates
*2.6 Other Architectures
Pipelining
Multiprocessor Machines
*Asterisks indicate suggestions for
optional sections.
Data Manipulation
PDFaid.Com
#1 Pdf Solutions
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Understanding Computer Architecture: CPU, Memory, and Machine Language and more Lab Reports Data Acquisition in PDF only on Docsity!

In this chapter we will learn how a computer manipulates data and

communicates with peripheral devices such as printers and key-

boards. In doing so, we will explore the basics of computer archi-

tecture and learn how computers are programmed by means of

encoded instructions, called machine language instructions.

C H A P T E R

2.1 Computer Architecture

CPU Basics The Stored-Program Concept

2.2 Machine Language

The Instruction Repertoire An Illustrative Machine Language

2.3 Program Execution

An Example of Program Execution Programs Versus Data

*2.4 Arithmetic/Logic

Instructions

Logic Operations Rotation and Shift Operations Arithmetic Operations

*2.5 Communicating with

Other Devices

The Role of Controllers Direct Memory Access Handshaking Popular Communication Media Communication Rates

*2.6 Other Architectures

Pipelining Multiprocessor Machines *Asterisks indicate suggestions for optional sections.

Data Manipulation

PDFaid.Com

#1 Pdf Solutions

74 Chapter 2 Data Manipulation

In Chapter 1 we studied topics relating to the storage of data inside a computer. In this chapter we will see how a computer manipulates that data. This manipu- lation consists of moving data from one location to another as well as performing operations such as arithmetic calculations, text editing, and image manipulation. We begin by extending our understanding of computer architecture beyond that of data storage systems.

2.1 Computer Architecture The circuitry in a computer that controls the manipulation of data is called the central processing unit, or CPU (often referred to as merely the processor). In the machines of the mid-twentieth century, CPUs were large units comprised of perhaps several racks of electronic circuitry that reflected the significance of the unit. However, technology has shrunk these devices drastically. The CPUs found in today’s desktop computers and notebooks are packaged as small flat squares (approximately two inches by two inches) whose connecting pins plug into a socket mounted on the machine’s main circuit board (called the motherboard ). In smartphones, mini-notebooks, and other Mobile Internet Devices (MID), CPU’s are around half the size of a postage stamp. Due to their small size, these processors are called microprocessors.

CPU Basics

A CPU consists of three parts (Figure 2.1): the arithmetic/logic unit, which contains the circuitry that performs operations on data (such as addition and subtraction); the control unit, which contains the circuitry for coordinating the machine’s activities; and the register unit, which contains data storage cells (similar to main memory cells), called registers, that are used for temporary storage of information within the CPU. Some of the registers within the register unit are considered general-purpose registers whereas others are special-purpose registers. We will discuss some of

Arithmetic/logic unit

Register unit

Central processing unit Main memory

Control unit

Bus

Registers

. . .

Figure 2.1 CPU and main memory connected via a bus

76 Chapter 2 Data Manipulation

A breakthrough (credited, apparently incorrectly, to John von Neumann) came with the realization that a program, just like data, can be encoded and stored in main memory. If the control unit is designed to extract the program from memory, decode the instructions, and execute them, the program that the machine follows can be changed merely by changing the contents of the com- puter’s memory instead of rewiring the CPU. The idea of storing a computer’s program in its main memory is called the stored-program concept and has become the standard approach used today—so standard, in fact, that it seems obvious. What made it difficult orig- inally was that everyone thought of programs and data as different entities: Data were stored in memory; programs were part of the CPU. The result was a prime example of not seeing the forest for the trees. It is easy to be caught in such ruts, and the development of computer science might still be in many of them today without our knowing it. Indeed, part of the excitement of the science is that new insights are constantly opening doors to new theo- ries and applications.

Cache Memory

It is instructive to compare the memory facilities within a computer in relation to their functionality. Registers are used to hold the data immediately applicable to the oper- ation at hand; main memory is used to hold data that will be needed in the near future; and mass storage is used to hold data that will likely not be needed in the immediate future. Many machines are designed with an additional memory level, called cache memory. Cache memory is a portion (perhaps several hundred KB) of high-speed memory located within the CPU itself. In this special memory area, the machine attempts to keep a copy of that portion of main memory that is of current interest. In this setting, data transfers that normally would be made between regis- ters and main memory are made between registers and cache memory. Any changes made to cache memory are then transferred collectively to main memory at a more opportune time. The result is a CPU that can execute its machine cycle more rapidly because it is not delayed by main memory communication.

Questions & Exercises

1. What sequence of events do you think would be required to move the contents of one memory cell in a computer to another memory cell? 2. What information must the CPU supply to the main memory circuitry to write a value into a memory cell? 3. Mass storage, main memory, and general-purpose registers are all stor- age systems. What is the difference in their use?

2.2 Machine Language 77

2.2 Machine Language

To apply the stored-program concept, CPUs are designed to recognize instruc- tions encoded as bit patterns. This collection of instructions along with the encoding system is called the machine language. An instruction expressed in this language is called a machine-level instruction or, more commonly, a machine instruction.

The Instruction Repertoire

The list of machine instructions that a typical CPU must be able to decode and execute is quite short. In fact, once a machine can perform certain elementary but well-chosen tasks, adding more features does not increase the machine’s the- oretical capabilities. In other words, beyond a certain point, additional features may increase such things as convenience but add nothing to the machine’s fun- damental capabilities. The degree to which machine designs should take advantage of this fact has lead to two philosophies of CPU architecture. One is that a CPU should be designed to execute a minimal set of machine instructions. This approach leads to what is called a reduced instruction set computer (RISC). The argument in favor of RISC architecture is that such a machine is efficient, fast, and less expensive to manufacture. On the other hand, others argue in favor of CPUs with the ability to execute a large number of complex instructions, even though many of them are technically redundant. The result of this approach is known as a complex instruction set computer (CISC). The argument in favor of CISC architecture is that the more complex CPU can better cope with the ever increasing complexities

Who Invented What?

Awarding a single individual credit for an invention is always a dubious undertaking. Thomas Edison is credited with inventing the incandescent lamp, but other researchers were developing similar lamps, and in a sense Edison was lucky to be the one to obtain the patent. The Wright brothers are credited with inventing the airplane, but they were competing with and benefited from the work of many contemporaries, all of whom were preempted to some degree by Leonardo da Vinci, who toyed with the idea of flying machines in the fifteenth century. Even Leonardo’s designs were appar- ently based on earlier ideas. Of course, in these cases the designated inventor still has legitimate claims to the credit bestowed. In other cases, history seems to have awarded credit inappropriately—an example is the stored-program concept. Without a doubt, John von Neumann was a brilliant scientist who deserves credit for numerous contributions. But one of the contributions for which popular history has chosen to credit him, the stored-program concept, was apparently developed by researchers led by J. P. Eckert at the Moore School of Electrical Engineering at the University of Pennsylvania. John von Neumann was merely the first to publish work reporting the idea and thus computing lore has selected him as the inventor.

2.2 Machine Language 79

memory cell is commonly referred to as a LOAD instruction; conversely, a request to transfer the contents of a register to a memory cell is called a STORE instruction. In Figure 2.2, Steps 1 and 2 are LOAD instructions, and Step 4 is a STORE instruction. An important group of instructions within the data transfer category consists of the commands for communicating with devices outside the CPU-main memory context (printers, keyboards, display screens, disk drives, etc.). Since these instructions handle the input/output (I/O) activities of the machine, they are called I/O instructions and are sometimes considered as a category in their own right. On the other hand, Section 2.5 describes how these I/O activities can be handled by the same instructions that request data transfers between the CPU and main memory. Thus, we shall consider the I/O instructions to be a part of the data transfer group.

Arithmetic/Logic The arithmetic/logic group consists of the instructions that tell the control unit to request an activity within the arithmetic/logic unit. Step 3 in Figure 2.2 falls into this group. As its name suggests, the arithmetic/logic unit is capable of performing operations other than the basic arithmetic operations. Some of these additional operations are the Boolean operations AND, OR, and XOR, introduced in Chapter 1, which we will discuss in more detail later in this chapter. Another collection of operations available within most arithmetic/logic units allows the contents of registers to be moved to the right or the left within the reg- ister. These operations are known as either SHIFT or ROTATE operations, depending on whether the bits that “fall off the end” of the register are merely discarded (SHIFT) or are used to fill the holes left at the other end (ROTATE).

Control The control group consists of those instructions that direct the execution of the program rather than the manipulation of data. Step 5 in Figure 2.2 falls into this category, although it is an extremely elementary example. This group contains many of the more interesting instructions in a machine’s repertoire, such as the family of JUMP (or BRANCH) instructions used to direct the CPU to execute an instruction other than the next one in the list. These JUMP instruc- tions appear in two varieties: unconditional jumps and conditional jumps.

Step 1. LOAD a register with a value from memory.

Step 2. LOAD another register with another value from memory. Step 3. If this second value is zero, JUMP to Step 6. Step 4. Divide the contents of the first register by the second register and leave the result in a third register.

Step 5. STORE the contents of the third register in memory.

Step 6. STOP.

Figure 2.3 Dividing values stored in memory

80 Chapter 2 Data Manipulation

An example of the former would be the instruction “Skip to Step 5”; an example of the latter would be, “If the value obtained is 0, then skip to Step 5.” The dis- tinction is that a conditional jump results in a “change of venue” only if a certain condition is satisfied. As an example, the sequence of instructions in Figure 2. represents an algorithm for dividing two values where Step 3 is a conditional jump that protects against the possibility of division by zero.

An Illustrative Machine Language

Let us now consider how the instructions of a typical computer are encoded. The machine that we will use for our discussion is described in Appendix C and summarized in Figure 2.4. It has 16 general-purpose registers and 256 main memory cells, each with a capacity of 8 bits. For referencing purposes, we label the registers with the values 0 through 15 and address the memory cells with the values 0 through 255. For convenience we think of these labels and addresses as values represented in base two and compress the resulting bit pat- terns using hexadecimal notation. Thus, the registers are labeled 0 through F, and the memory cells are addressed 00 through FF. The encoded version of a machine instruction consists of two parts: the op-code (short for operation code) field and the operand field. The bit pattern appearing in the op-code field indicates which of the elementary operations, such as STORE, SHIFT, XOR, and JUMP, is requested by the instruction. The bit patterns found in the operand field provide more detailed information about the opera- tion specified by the op-code. For example, in the case of a STORE operation, the information in the operand field indicates which register contains the data to be stored and which memory cell is to receive the data. The entire machine language of our illustrative machine (Appendix C) con- sists of only twelve basic instructions. Each of these instructions is encoded using a total of 16 bits, represented by four hexadecimal digits (Figure 2.5). The op-code for each instruction consists of the first 4 bits or, equivalently, the first hexadecimal digit. Note (Appendix C) that these op-codes are represented by the hexadecimal digits 1 through C. In particular, the table in Appendix C shows

Central processing unit

Bus

Registers

0

1

2

F

. ..

Program counter

Instruction register

Main memory

Address

00

01

02

03

FF

. . .

. . .

Cells

Figure 2.4 The architecture of the machine described in Appendix C

82 Chapter 2 Data Manipulation

As another example of how the operand field is used to clarify the general instruction given by op-code, consider an instruction with the op-code 7 (hexa- decimal), which requests that the contents of two registers be ORed. (We will see what it means to OR two registers in Section 2.4. For now we are interested merely in how instructions are encoded.) In this case, the next hexadecimal digit indicates the register in which the result should be placed, while the last two hexadecimal digits indicate which two registers are to be ORed. Thus the instruc- tion 70C5 translates to the statement “OR the contents of register C with the con- tents of register 5 and leave the result in register 0.” A subtle distinction exists between our machine’s two LOAD instructions. Here we see that the op-code 1 (hexadecimal) identifies an instruction that loads a register with the contents of a memory cell, whereas the op-code 2 (hexa- decimal) identifies an instruction that loads a register with a particular value. The difference is that the operand field in an instruction of the first type con- tains an address, whereas in the second type the operand field contains the actual bit pattern to be loaded. Note that the machine has two ADD instructions: one for adding two’s com- plement representations and one for adding floating-point representations. This distinction is a consequence of the fact that adding bit patterns that represent val- ues encoded in two’s complement notation requires different activities within the arithmetic/logic unit from adding values encoded in floating-point notation. We close this section with Figure 2.7, which contains an encoded version of the instructions in Figure 2.2. We have assumed that the values to be added are stored in two’s complement notation at memory addresses 6C and 6D and the sum is to be placed in the memory cell at address 6E.

156C

166D

5056

306E

C

Load register 5 with the bit pattern found in the memory cell at address 6C.

Load register 6 with the bit pattern found in the memory cell at address 6D.

Add the contents of register 5 and 6 as though they were two’s complement representation and leave the result in register 0.

Store the contents of register 0 in the memory cell at address 6E.

Halt.

Encoded instructions Translation

Figure 2.7 An encoded version of the instructions in Figure 2. 2

2.3 Program Execution 83

2.3 Program Execution

A computer follows a program stored in its memory by copying the instructions from memory into the CPU as needed. Once in the CPU, each instruction is decoded and obeyed. The order in which the instructions are fetched from mem- ory corresponds to the order in which the instructions are stored in memory unless otherwise altered by a JUMP instruction. To understand how the overall execution process takes place, it is necessary to consider two of the special purpose registers within the CPU: the instruction register and the program counter (see again Figure 2.4). The instruction regis- ter is used to hold the instruction being executed. The program counter contains the address of the next instruction to be executed, thereby serving as the machine’s way of keeping track of where it is in the program. The CPU performs its job by continually repeating an algorithm that guides it through a three-step process known as the machine cycle. The steps in the

Questions & Exercises

1. Why might the term move be considered an incorrect name for the oper- ation of moving data from one location in a machine to another? 2. In the text, JUMP instructions were expressed by identifying the desti- nation explicitly by stating the name (or step number) of the destination within the JUMP instruction (for example, “Jump to Step 6”). A draw- back of this technique is that if an instruction name (number) is later changed, we must be sure to find all jumps to that instruction and change that name also. Describe another way of expressing a JUMP instruction so that the name of the destination is not explicitly stated. 3. Is the instruction “If 0 equals 0, then jump to Step 7” a conditional or unconditional jump? Explain your answer. 4. Write the example program in Figure 2.7 in actual bit patterns. 5. The following are instructions written in the machine language described in Appendix C. Rewrite them in English. a. 368A b. BADE c. 803C d. 40F 6. What is the difference between the instructions 15AB and 25AB in the machine language of Appendix C? 7. Here are some instructions in English. Translate each of them into the machine language of Appendix C.

a. LOAD register number 3 with the hexadecimal value 56. b. ROTATE register number 5 three bits to the right. c. AND the contents of register A with the contents of register 5 and leave the result in register 0.

2.3 Program Execution 85

terminates and the next machine cycle begins. If, however, the contents of these registers are equal, the machine places the value 58 (hexadecimal) in its program counter during the execute step. In this case, then, the next fetch step finds 58 in the program counter, so the instruction at that address will be the next instruction to be fetched and executed. Note that if the instruction had been B058, then the decision of whether the program counter should be changed would depend on whether the contents of register 0 was equal to that of register 0. But these are the same registers and thus must have equal content. In turn, any instruction of the form B0XY will cause a jump to be executed to the memory location XY regardless of the con- tents of register 0.

B 2 5 8

This part of the operand is the address to be placed in the program counter.

This part of the operand identifies the register to be compared to register 0.

Op-code B means to change the value of the program counter if the contents of the indicated register is the same as that in register 0.

Instruction

Figure 2.9 Decoding the instruction B 258

Comparing Computer Power

When shopping for a personal computer, you will find that clock speeds are often used to compare machines. A computer’s clock is a circuit, called an oscillator, which generates pulses that are used to coordinate the machine’s activities—the faster this oscillating circuit generates pulses, the faster the machine performs its machine cycle. Clock speeds are measured in hertz (abbreviated as Hz) with one Hz equal to one cycle (or pulse) per second. Typical clock speeds in desktop computers are in the range of a few hundred MHz (older models) to several GHz. (MHz is short for mega- hertz, which is a million Hz. GHz is short for gigahertz, which is 1000 MHz.) Unfortunately, different CPU designs might perform different amounts of work in one clock cycle, and thus clock speed alone fails to be relevant in comparing machines with different CPUs. If you are comparing a machine based on an Intel processor to one based on ARM, it would be more meaningful to compare perform- ance by means of benchmarking, which is the process of comparing the performance of different machines when executing the same program, known as a benchmark. By selecting benchmarks representing different types of applications, you get meaning- ful comparisons for various market segments.

86 Chapter 2 Data Manipulation

An Example of Program Execution

Let us follow the machine cycle applied to the program presented in Figure 2.7, which retrieves two values from main memory, computes their sum, and stores that total in a main memory cell. We first need to put the program somewhere in memory. For our example, suppose the program is stored in consecutive addresses, starting at address A0 (hexadecimal). With the program stored in this manner, we can cause the machine to execute it by placing the address (A0) of the first instruction in the program counter and starting the machine (Figure 2.10). The CPU begins the fetch step of the machine cycle by extracting the instruction stored in main memory at location A0 and placing this instruction (156C) in its instruction register (Figure 2.11a). Notice that, in our machine, instructions are 16 bits (two bytes) long. Thus the entire instruction to be fetched occupies the memory cells at both address A0 and A1. The CPU is designed to take this into account so it retrieves the contents of both cells and places the bit patterns received in the instruction register, which is 16 bits long. The CPU then adds two to the program counter so that this register contains the address of the next instruction (Figure 2.11b). At the end of the fetch step of the first machine cycle, the program counter and instruction register contain the following data:

Program Counter: A Instruction Register: 156C

Next, the CPU analyzes the instruction in its instruction register and con- cludes that it is to load register 5 with the contents of the memory cell at address 6C. This load activity is performed during the execution step of the machine cycle, and the CPU then begins the next cycle. This cycle begins by fetching the instruction 166D from the two memory cells starting at address A2. The CPU places this instruction in the instruction

CPU Main memory

Registers Program counter

Instruction register

Bus

F

A

Address Cells

A0 15 A A A A A A A A A

6C

6D

6E

C

Program counter contains address of first instructions.

Program is stored in main memory beginning at address A0.

. ..

Figure 2.10 The program from Figure 2. 7 stored in main memory ready for execution

88 Chapter 2 Data Manipulation

next instruction (306E) from the two memory cells starting at memory location A6 and increments the program counter to A8. This instruction is then decoded and executed. At this point, the sum is placed in memory location 6E. The next instruction is fetched starting from memory location A8, and the program counter is incremented to AA. The contents of the instruction register (C000) are now decoded as the halt instruction. Consequently, the machine stops during the execute step of the machine cycle, and the program is completed. In summary, we see that the execution of a program stored in memory involves the same process you and I might use if we needed to follow a detailed list of instructions. Whereas we might keep our place by marking the instructions as we perform them, the CPU keeps its place by using the program counter. After determining which instruction to execute next, we would read the instruction and extract its meaning. Then, we would perform the task requested and return to the list for the next instruction in the same manner that the CPU executes the instruc- tion in its instruction register and then continues with another fetch.

Programs Versus Data

Many programs can be stored simultaneously in a computer’s main memory, as long as they occupy different locations. Which program will be run when the machine is started can then be determined merely by setting the program counter appropriately. One must keep in mind, however, that because data are also contained in main memory and encoded in terms of 0s and 1s, the machine alone has no way of know- ing what is data and what is program. If the program counter were assigned the address of data instead of the address of the desired program, the CPU, not knowing any better, would extract the data bit patterns as though they were instructions and execute them. The final result would depend on the data involved. We should not conclude, however, that providing programs and data with a common appearance in a machine’s memory is bad. In fact, it has proved a use- ful attribute because it allows one program to manipulate other programs (or even itself) the same as it would data. Imagine, for example, a program that mod- ifies itself in response to its interaction with its environment and thus exhibits the ability to learn, or perhaps a program that writes and executes other pro- grams in order to solve problems presented to it.

Questions & Exercises

1. Suppose the memory cells from addresses 00 to 05 in the machine described in Appendix C contain the (hexadecimal) bit patterns given in the following table:

Address Contents 00 14 01 02 02 34 03 17 04 C 05 00

2.3 Program Execution 89

If we start the machine with its program counter containing 00, what bit pattern is in the memory cell whose address is hexadecimal 17 when the machine halts?

2. Suppose the memory cells at addresses B0 to B8 in the machine described in Appendix C contain the (hexadecimal) bit patterns given in the following table:

a. If the program counter starts at B0, what bit pattern is in register number 3 after the first instruction has been executed? b. What bit pattern is in memory cell B8 when the halt instruction is executed?

3. Suppose the memory cells at addresses A4 to B1 in the machine described in Appendix C contain the (hexadecimal) bit patterns given in the following table:

Address Contents B0 13 B1 B B2 A B3 02 B4 33 B5 B B6 C B7 00 B8 0F

Address Contents A4 20 A5 00 A6 21 A7 03 A8 22 A9 01 AA B AB B AC 50 AD 02 AE B AF AA B0 C B1 00

When answering the following questions, assume that the machine is started with its program counter containing A4.

a. What is in register 0 the first time the instruction at address AA is executed? b. What is in register 0 the second time the instruction at address AA is executed? c. How many times is the instruction at address AA executed before the machine halts?