8 Chapter 1 Computer Abstractions and Technology How are programs written in a high-level language,such as C or Java,trans- lated into the language of the hardware,and how does the hardware execute the resulting program?Comprehending these concepts forms the basis of understanding the aspects of both the hardware and software that affect program performance. What is the interface between the software and the hardware,and how does software instruct the hardware to perform needed functions?These concepts are vital to understanding how to write many kinds of software. What determines the performance of a program,and how can a program- mer improve the performance?As we will see,this depends on the original program,the software translation of that program into the computer's language,and the effectiveness of the hardware in executing the program. What techniques can be used by hardware designers to improve performance? This book will introduce the basic concepts of modern computer design.The interested reader will find much more material on this topic in our advanced book,Computer Architecture:A Quantitative Approach. What are the reasons for and the consequences of the recent switch from sequential processing to parallel processing?This book gives the motivation, describes the current hardware mechanisms to support parallelism,and multicore surveys the new generation of "multicore"microprocessors (see Chapter 7). microprocessor A microprocessor containing Without understanding the answers to these questions,improving the perfor- multiple processors mance of your program on a modern computer,or evaluating what features might ("cores")in a single make one computer better than another for a particular application,will be a integrated circuit. complex process of trial and error,rather than a scientific procedure driven by insight and analysis. This first chapter lays the foundation for the rest of the book.It introduces the basic ideas and definitions,places the major components of software and hardware in perspective,shows how to evaluate performance and power,introduces inte- grated circuits(the technology that fuels the computer revolution),and explains the shift to multicores. In this chapter and later ones,you will likely see many new words,or words that you may have heard but are not sure what they mean.Don't panic!Yes,there is a lot of special terminology used in describing modern computers,but the ter- acronym A word minology actually helps,since it enables us to describe precisely a function or constructed by taking the capability.In addition,computer designers(including your authors)love using initial letters of a string of acronyms,which are easy to understand once you know what the letters stand for! words.For example: RAM is an acronym for To help you remember and locate terms,we have included a highlighted defini- Random Access Memory, tion of every term in the margins the first time it appears in the text.After a short and CPU is an acronym time of working with the terminology,you will be fluent,and your friends will for Central Processing be impressed as you correctly use acronyms such as BIOS,CPU,DIMM,DRAM, Unit. PCIE,SATA,and many others
8 Chapter 1 Computer Abstractions and Technology ■ How are programs written in a high-level language, such as C or Java, translated into the language of the hardware, and how does the hardware execute the resulting program? Comprehending these concepts forms the basis of understanding the aspects of both the hardware and software that affect program performance. ■ What is the interface between the software and the hardware, and how does software instruct the hardware to perform needed functions? These concepts are vital to understanding how to write many kinds of software. ■ What determines the performance of a program, and how can a programmer improve the performance? As we will see, this depends on the original program, the software translation of that program into the computer’s language, and the effectiveness of the hardware in executing the program. ■ What techniques can be used by hardware designers to improve performance? This book will introduce the basic concepts of modern computer design. The interested reader will find much more material on this topic in our advanced book, Computer Architecture: A Quantitative Approach. ■ What are the reasons for and the consequences of the recent switch from sequential processing to parallel processing? This book gives the motivation, describes the current hardware mechanisms to support parallelism, and surveys the new generation of “multicore” microprocessors (see Chapter 7). Without understanding the answers to these questions, improving the performance of your program on a modern computer, or evaluating what features might make one computer better than another for a particular application, will be a complex process of trial and error, rather than a scientific procedure driven by insight and analysis. This first chapter lays the foundation for the rest of the book. It introduces the basic ideas and definitions, places the major components of software and hardware in perspective, shows how to evaluate performance and power, introduces integrated circuits (the technology that fuels the computer revolution), and explains the shift to multicores. In this chapter and later ones, you will likely see many new words, or words that you may have heard but are not sure what they mean. Don’t panic! Yes, there is a lot of special terminology used in describing modern computers, but the terminology actually helps, since it enables us to describe precisely a function or capability. In addition, computer designers (including your authors) love using acronyms, which are easy to understand once you know what the letters stand for! To help you remember and locate terms, we have included a highlighted definition of every term in the margins the first time it appears in the text. After a short time of working with the terminology, you will be fluent, and your friends will be impressed as you correctly use acronyms such as BIOS, CPU, DIMM, DRAM, PCIE, SATA, and many others. multicore microprocessor A microprocessor containing multiple processors (“cores”) in a single integrated circuit. acronym A word constructed by taking the initial letters of a string of words. For example: RAM is an acronym for Random Access Memory, and CPU is an acronym for Central Processing Unit
1.1 Introduction 9 To reinforce how the software and hardware systems used to run a program will affect performance,we use a special section,Understanding Program Performance, throughout the book to summarize important insights into program performance. The first one appears below. The performance of a program depends on a combination of the effectiveness of Understanding the algorithms used in the program,the software systems used to create and trans- late the program into machine instructions,and the effectiveness of the computer Program in executing those instructions,which may include input/output(I/O)operations. Performance This table summarizes how the hardware and software affect performance. Hardware or software How this component affects Where is this component performance topic covered? Algorithm Determines both the number of source-level Other books! statements and the number of l/0 operations executed Programming language, Determines the number of computer Chapters 2 and 3 compiler,and architecture instructions for each source-level statement Processor and memory system Determines how fast instructions can be Chapters 4,5,and 7 executed l/O system(hardware and Determines how fast I/0 operations may be Chapter 6 operating system) executed Check Yourself sections are designed to help readers assess whether they compre- Check hend the major concepts introduced in a chapter and understand the implications Yourself of those concepts.Some Check Yourself questions have simple answers;others are for discussion among a group.Answers to the specific questions can be found at the end of the chapter.Check Yourself questions appear only at the end of a section, making it easy to skip them if you are sure you understand the material. 1.Section 1.1 showed that the number of embedded processors sold every year greatly outnumbers the number of desktop processors.Can you confirm or deny this insight based on your own experience?Try to count the number of embedded processors in your home.How does it compare with the number of desktop computers in your home? 2.As mentioned earlier,both the software and hardware affect the performance of a program.Can you think of examples where each of the following is the right place to look for a performance bottleneck? ■The algorithm chosen The programming language or compiler ■The operating system ■The processor The I/O system and devices
1.1 Introduction 9 To reinforce how the software and hardware systems used to run a program will affect performance, we use a special section, Understanding Program Performance, throughout the book to summarize important insights into program performance. The first one appears below. The performance of a program depends on a combination of the effectiveness of the algorithms used in the program, the software systems used to create and translate the program into machine instructions, and the effectiveness of the computer in executing those instructions, which may include input/output (I/O) operations. This table summarizes how the hardware and software affect performance. Understanding Program Performance Hardware or software component How this component affects performance Where is this topic covered? Algorithm Determines both the number of source-level statements and the number of I/O operations executed Other books! Programming language, compiler, and architecture Determines the number of computer instructions for each source-level statement Chapters 2 and 3 Processor and memory system Determines how fast instructions can be executed Chapters 4, 5, and 7 I/O system (hardware and operating system) Determines how fast I/O operations may be executed Chapter 6 Check Yourself sections are designed to help readers assess whether they comprehend the major concepts introduced in a chapter and understand the implications of those concepts. Some Check Yourself questions have simple answers; others are for discussion among a group. Answers to the specific questions can be found at the end of the chapter. Check Yourself questions appear only at the end of a section, making it easy to skip them if you are sure you understand the material. 1. Section 1.1 showed that the number of embedded processors sold every year greatly outnumbers the number of desktop processors. Can you confirm or deny this insight based on your own experience? Try to count the number of embedded processors in your home. How does it compare with the number of desktop computers in your home? 2. As mentioned earlier, both the software and hardware affect the performance of a program. Can you think of examples where each of the following is the right place to look for a performance bottleneck? ■ The algorithm chosen ■ The programming language or compiler ■ The operating system ■ The processor ■ The I/O system and devices Check Yourself
10 Chapter 1 Computer Abstractions and Technology In Paris they simply stared when I spoke to them in French;I never 1.2 Below Your Program did succeed in making those idiots understand their own language. A typical application,such as a word processor or a large database system,may consist of millions of lines of code and rely on sophisticated software libraries that Mark Twain,The implement complex functions in support of the application.As we will see,the Innocents Abroad,1869 hardware in a computer can only execute extremely simple low-level instructions. To go from a complex application to the simple instructions involves several layers of software that interpret or translate high-level operations into simple computer instructions. Figure 1.2 shows that these layers of software are organized primarily in a hier- archical fashion,with applications being the outermost ring and a variety of systems software systems software sitting between the hardware and applications software. Software that provides There are many types of systems software,but two types of systems software are services that are central to every computer system today:an operating system and a compiler.An commonly useful, including operating operating system interfaces between a user's program and the hardware and pro- systems,compilers, vides a variety of services and supervisory functions.Among the most important loaders,and assemblers functions are operating system Handling basic input and output operations Supervising program that manages the resources of Allocating storage and memory a computer for the benefit Providing for protected sharing of the computer among multiple applications of the programs that run using it simultaneously. on that computer. Examples of operating systems in use today are Linux,MacOS,and Windows. Applications software 9sos。 Hardware FIGURE 1.2 A simplified view of hardware and software as hierarchical layers,shown as concentric circles with hardware in the center and applications software outermost.In complex applications,there are often multiple layers of application software as well.For example,a database system may run on top of the systems software hosting an application,which in turn runs on top of the database
10 Chapter 1 Computer Abstractions and Technology 1.2 Below Your Program A typical application, such as a word processor or a large database system, may consist of millions of lines of code and rely on sophisticated software libraries that implement complex functions in support of the application. As we will see, the hardware in a computer can only execute extremely simple low-level instructions. To go from a complex application to the simple instructions involves several layers of software that interpret or translate high-level operations into simple computer instructions. Figure 1.2 shows that these layers of software are organized primarily in a hierarchical fashion, with applications being the outermost ring and a variety of systemssoftware sitting between the hardware and applications software. There are many types of systems software, but two types of systems software are central to every computer system today: an operating system and a compiler. An operating system interfaces between a user’s program and the hardware and provides a variety of services and supervisory functions. Among the most important functions are ■ Handling basic input and output operations ■ Allocating storage and memory ■ Providing for protected sharing of the computer among multiple applications using it simultaneously. Examples of operating systems in use today are Linux, MacOS, and Windows. In Paris they simply stared when I spoke to them in French; I never did succeed in making those idiots understand their own language. Mark Twain, The Innocents Abroad, 1869 systems software Software that provides services that are commonly useful, including operating systems, compilers, loaders, and assemblers. operating system Supervising program that manages the resources of a computer for the benefit of the programs that run on that computer. FIGURE 1.2 A simplified view of hardware and software as hierarchical layers, shown as concentric circles with hardware in the center and applications software outermost. In complex applications, there are often multiple layers of application software as well. For example, a database system may run on top of the systems software hosting an application, which in turn runs on top of the database. Applications software Systems software Hardware
1.2 Below Your Program 11 Compilers perform another vital function:the translation of a program written compiler A program in a high-level language,such as C,C++,Java,or Visual Basic into instructions that translates high-level that the hardware can execute.Given the sophistication of modern programming language statements languages and the simplicity of the instructions executed by the hardware,the into assembly language statements. translation from a high-level language program to hardware instructions is complex.We give a brief overview of the process here and then go into more depth in Chapter 2 and Appendix B. From a High-Level Language to the Language of Hardware To actually speak to electronic hardware,you need to send electrical signals.The easiest signals for computers to understand are on and off,and so the computer alphabet is just two letters.Just as the 26 letters of the English alphabet do not limit how much can be written,the two letters of the computer alphabet do not limit what computers can do.The two symbols for these two letters are the numbers 0 and 1,and we commonly think of the computer language as numbers in base 2,or binary numbers.We refer to each"letter"as a binary digit or bit.Computers are binary digit Also called slaves to our commands,which are called instructions.Instructions,which are just a bit.One of the two collections of bits that the computer understands and obeys,can be thought of as numbers in base 2 (0 or 1) numbers.For example,the bits that are the components of information. 1000110010100000 instruction A command tell one computer to add two numbers.Chapter 2 explains why we use numbers that computer hardware understands and obeys. for instructions and data;we don't want to steal that chapter's thunder,but using numbers for both instructions and data is a foundation of computing. The first programmers communicated to computers in binary numbers,but this was so tedious that they quickly invented new notations that were closer to the way humans think.At first,these notations were translated to binary by hand,but this process was still tiresome.Using the computer to help program the computer,the pioneers invented programs to translate from symbolic notation to binary.The first of these programs was named an assembler.This program translates a symbolic assembler A program version of an instruction into the binary version.For example,the programmer that translates a symbolic would write version of instructions into the binary version. add A.B and the assembler would translate this notation into 1000110010100000 This instruction tells the computer to add the two numbers A and B.The name assembly language coined for this symbolic language,still used today,is assembly language.In con- A symbolic representation trast,the binary language that the machine understands is the machine language. of machine instructions. Although a tremendous improvement,assembly language is still far from the machine language notations a scientist might like to use to simulate fluid flow or that an accountant A binary representation of might use to balance the books.Assembly language requires the programmer machine instructions
Compilers perform another vital function: the translation of a program written in a high-level language, such as C, C++, Java, or Visual Basic into instructions that the hardware can execute. Given the sophistication of modern programming languages and the simplicity of the instructions executed by the hardware, the translation from a high-level language program to hardware instructions is complex. We give a brief overview of the process here and then go into more depth in Chapter 2 and Appendix B. From a High-Level Language to the Language of Hardware To actually speak to electronic hardware, you need to send electrical signals. The easiest signals for computers to understand are on and off, and so the computer alphabet is just two letters. Just as the 26 letters of the English alphabet do not limit how much can be written, the two letters of the computer alphabet do not limit what computers can do. The two symbols for these two letters are the numbers 0 and 1, and we commonly think of the computer language as numbers in base 2, or binary numbers. We refer to each “letter” as a binary digit or bit. Computers are slaves to our commands, which are called instructions. Instructions, which are just collections of bits that the computer understands and obeys, can be thought of as numbers. For example, the bits 1000110010100000 tell one computer to add two numbers. Chapter 2 explains why we use numbers for instructions and data; we don’t want to steal that chapter’s thunder, but using numbers for both instructions and data is a foundation of computing. The first programmers communicated to computers in binary numbers, but this was so tedious that they quickly invented new notations that were closer to the way humans think. At first, these notations were translated to binary by hand, but this process was still tiresome. Using the computer to help program the computer, the pioneers invented programs to translate from symbolic notation to binary. The first of these programs was named an assembler. This program translates a symbolic version of an instruction into the binary version. For example, the programmer would write add A,B and the assembler would translate this notation into 1000110010100000 This instruction tells the computer to add the two numbers A and B. The name coined for this symbolic language, still used today, is assembly language. In contrast, the binary language that the machine understands is the machine language. Although a tremendous improvement, assembly language is still far from the notations a scientist might like to use to simulate fluid flow or that an accountant might use to balance the books. Assembly language requires the programmer compiler A program that translates high-level language statements into assembly language statements. binary digit Also called a bit. One of the two numbers in base 2 (0 or 1) that are the components of information. instruction A command that computer hardware understands and obeys. assembler A program that translates a symbolic version of instructions into the binary version. assembly language A symbolic representation of machine instructions. machine language A binary representation of machine instructions. 1.2 Below Your Program 11
12 Chapter 1 Computer Abstractions and Technology to write one line for every instruction that the computer will follow,forcing the programmer to think like the computer. The recognition that a program could be written to translate a more powerful language into computer instructions was one of the great breakthroughs in the early days of computing.Programmers today owe their productivity-and their high-level sanity-to the creation of high-level programming languages and compilers that programming translate programs in such languages into instructions.Figure 1.3 shows the rela- language A portable tionships among these programs and languages. language such as C,C++, Java,or Visual Basic that is composed of words and algebraic notation High-level swap(int v[],int k) that can be translated by language (int temp: a compiler into assembly program temp v[k]: language. (in C) v[k]=v[k+1]: v[k+1]temp: Compiler Assembly swap: language mu1ti$2.$5,4 program add $2,$4.$2 (for MIPS) lw $15,0($2) lw $16, 4($2) SW $16,0($2) SW $15,4($2) jr $31 Assembler Binary machine 00000000101000100000000100011000 language 0000000010000010000100000100001 program 10001101111000100000000000000000 (for MIPS) 10001110000100100000000000000100 10101110000100100000000000000000 10101101111000100000000000000100 00000011111000000000000000001000 FIGURE 1.3 C program compiled into assembly language and then assembled into binary machine language.Although the translation from high-level language to binary machine language is shown in two steps,some compilers cut out the middleman and produce binary machine language directly. These languages and this program are examined in more detail in Chapter 2
12 Chapter 1 Computer Abstractions and Technology to write one line for every instruction that the computer will follow, forcing the programmer to think like the computer. The recognition that a program could be written to translate a more powerful language into computer instructions was one of the great breakthroughs in the early days of computing. Programmers today owe their productivity—and their sanity—to the creation of high-level programming languages and compilers that translate programs in such languages into instructions. Figure 1.3 shows the relationships among these programs and languages. high-level programming language A portable language such as C, C++, Java, or Visual Basic that is composed of words and algebraic notation that can be translated by a compiler into assembly language. FIGURE 1.3 C program compiled into assembly language and then assembled into binary machine language. Although the translation from high-level language to binary machine language is shown in two steps, some compilers cut out the middleman and produce binary machine language directly. These languages and this program are examined in more detail in Chapter 2. swap(int v[], int k) {int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; } swap: multi $2, $5,4 add $2, $4,$2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31 00000000101000100000000100011000 0000000010000010000100000100001 10001101111000100000000000000000 10001110000100100000000000000100 10101110000100100000000000000000 10101101111000100000000000000100 00000011111000000000000000001000 Assembler Compiler Binary machine language program (for MIPS) Assembly language program (for MIPS) High-level language program (in C)