(The Morgan Kaufmann Series in Computer Architecture and Design) David A. Patterson, John L. Hennessy - Computer Organization and Design RISC-V Edition_ The Hardware Software Interface-Morgan Kaufmann-24-101-12-15.pdf
Document Details
Uploaded by Deleted User
Tags
Full Transcript
1.3 Below Your Program 13 In Paris they simply...
1.3 Below Your Program 13 In Paris they simply stared when I spoke to 1.3 Below Your Program them in French; I never did succeed in making those idiots understand A typical application, such as a word processor or a large database system, may their own language. 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 primitive instructions involves several layers of software that interpret or translate high-level operations into simple computer instructions, an example of the great idea of abstraction. Figure 1.3 shows that these layers of software are organized primarily in a hierarchical fashion, with applications being the outermost ring and a variety of systems software sitting between the hardware and the application 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: systems software Software that provides Handling basic input and output operations services that are Allocating storage and memory commonly useful, including operating Providing for protected sharing of the computer among multiple applications systems, compilers, using it simultaneously loaders, and assemblers. Examples of operating systems in use today are Linux, iOS, Android, and Windows. operating system Supervising program that manages the resources of a computer for the benefit DWLRQVRIWZD of the programs that run SOLF UH $S on that computer. V VRI WZD WHP \V U H 6 +DUGZDUH FIGURE 1.3 A simplified view of hardware and software as hierarchical layers, shown as concentric circles with hardware in the center and application 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. 14 Chapter 1 Computer Abstractions and Technology compiler A program Compilers perform another vital function: the translation of a program written that translates high-level in a high-level language, such as C, C+ +, Java, or Visual Basic into instructions language statements that the hardware can execute. Given the sophistication of modern programming into assembly language languages and the simplicity of the instructions executed by the hardware, the 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. From a High-Level Language to the Language of Hardware To speak directly 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 digit Also called binary numbers. We refer to each “letter” as a binary digit or bit. Computers are a bit. One of the two slaves to our commands, which are called instructions. Instructions, which are just numbers in base 2 (0 or 1) collections of bits that the computer understands and obeys, can be thought of as that are the components numbers. For example, the bits of information. instruction A command 1001010100101110 that computer hardware understands and obeys. 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 software to translate from symbolic notation to binary. The first of assembler A program these programs was named an assembler. This program translates a symbolic version that translates a symbolic of an instruction into the binary version. For example, the programmer would write version of instructions into the binary version. add A, B and the assembler would translate this notation into 1001010100101110 This instruction tells the computer to add the two numbers A and B. The name coined assembly language for this symbolic language, still used today, is assembly language. In contrast, the A symbolic representation 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. to write one line for every instruction that the computer will follow, forcing the programmer to think like the computer. 1.3 Below Your Program 15 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.4 shows the relationships among these programs and languages, which are more examples of the power of abstraction. High-level swap(size_t v[], size_t k) high-level language { programming program size_t temp; language A portable (in C) temp = v[k]; language such as C, C++, v[k] = v[k+1]; Java, or Visual Basic that v[k+1] = temp; is composed of words } and algebraic notation that can be translated by a compiler into assembly language. Compiler Assembly swap: language slli x6, x11, 3 program add x6, x10, x6 (for RISC-V) lw x5, 0(x6) lw x7, 4(x6) sw x7, 0(x6) sw x5, 4(x6) jalr x0, 0(x1) Assembler Binary machine 00000000001101011001001100010011 language 00000000011001010000001100110011 program 00000000000000110011001010000011 (for RISC-V) 00000000100000110011001110000011 00000000011100110011000000100011 00000000010100110011010000100011 00000000000000001000000001100111 FIGURE 1.4 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. 16 Chapter 1 Computer Abstractions and Technology A compiler enables a programmer to write this high-level language expression: A + B The compiler would compile it into this assembly language statement: add A, B As shown above, the assembler would translate this statement into the binary instructions that tell the computer to add the two numbers A and B. High-level programming languages offer several important benefits. First, they allow the programmer to think in a more natural language, using English words and algebraic notation, resulting in programs that look much more like text than like tables of cryptic symbols (see Figure 1.4). Moreover, they allow languages to be designed according to their intended use. Hence, Fortran was designed for scientific computation, Cobol for business data processing, Lisp for symbol manipulation, and so on. There are also domain-specific languages for even narrower groups of users, such as those interested in machine learning, for example. The second advantage of programming languages is improved programmer productivity. One of the few areas of widespread agreement in software development is that it takes less time to develop programs when they are written in languages that require fewer lines to express an idea. Conciseness is a clear advantage of high- level languages over assembly language. The final advantage is that programming languages allow programs to be independent of the computer on which they were developed, since compilers and assemblers can translate high-level language programs to the binary instructions of any computer. These three advantages are so strong that today little programming is done in assembly language. 1.4 Under the Covers Now that we have looked below your program to uncover the underlying software, let’s open the covers of your computer to learn about the underlying hardware. The input device underlying hardware in any computer performs the same basic functions: inputting A mechanism through data, outputting data, processing data, and storing data. How these functions are which the computer is performed is the primary topic of this book, and subsequent chapters deal with fed information, such as a different parts of these four tasks. keyboard. When we come to an important point in this book, a point so significant that output device we hope you will remember it forever, we emphasize it by identifying it as a Big A mechanism that Picture item. We have about a dozen Big Pictures in this book, the first being the conveys the result of a five components of a computer that perform the tasks of inputting, outputting, computation to a user, processing, and storing data. such as a display, or to Two key components of computers are input devices, such as the microphone, another computer. and output devices, such as the speaker. As the names suggest, input feeds the