I speak Spanish to God, Italian to women, Franch to men, and German to my horse. Charles V, Holy Roman Emperor (1500-1558)
2.1 Introduce
2.2 Operations of the computer Hardware
2.3 Operands of the Compter Hardware
2.4 Signed and unsigned Number
2.5 Representing Instructions in the computer
2.6 Logical Operations
2.7 Instructions for Making Decisions
2.8 Supporting Procedures in computer Hardware
2.9 MIPS Addressing for 32-Bit Immediates and Addresses
2.10 Parallelism and Instructions: synchronization
2.11 Translating and starting a Program
2.12 A C short Example to put It All Together
2.13 Advanced Material : complling C
2.14 Real stuff : ARMv7 (32-bit) Instructions
2.15 Real stuff: x86 Instructions
2.16 Real stuff: ARMv8(64-bit) Instructions
2.17 Fallacies and pitfalls
2.18 concluding Remarks
2.19Historical Perspective and Further Reading
2.20 Exercises
2.1 Introduction
To command a computer‘s hardware, you must speak its language. The words of a computer‘s language are called instructions, and its vocabulary is called an instruction set. In this chapter, you will see the instruction set of a real computer, both in the form written by people and in the form read by the computer. We introduce instructions in a top-down fashion. Starting from a notation that looks like a restricted programming language, we refine it step-by-step until you see the real language of a real computer. Chapter 3 continues our downward descent, unveiling the hardware for arthmetic and the representation of floatin-point numbers.
You might think that the languages of computers would be as diverse as those of people, but in reality computer languages are quite similar, more like regional dialects than like independent languages. Hence, once you learn one, it is easy to pick up others.
The chosen instruction set comes from MIPS Technologies, and is an elegant example of the instruction sets designed since the 1980s. To demonstrate how easy it is to pick up other instruction sets, we will take a quick look at three other popular instruction sets.
- ARMv7 is similar to MIPS. MOre than 9 billion chips with ARM processors were manufactured in 2011, making it the most popular instruction set in the world.
- The second example is the Intel X86, which powers both the PC and the cloud of the PostPC Era.
- The third example is ARMv8, Which extends the address size of the ARMv7 from 32 bits to 64 bits. Ironically, as we shall see, this 2013 instruction set is closer to MIPS than it is to ARMv7.
This similarity of instruction set occurs because all computers are constructed from hardware technologies based on similar underlying principles and because there are a few basic operations that all computers must provide. Moreover, computer designers have a common goal: to find a language that makes it easy to build the hardware and the complier while maximizing performance and minimizing cost and energy. This goal is time honored; the following quote was written before you could buy a computer, and it is true today as it was in 1947:
It is easy to see by formal-logical methods that there exist certain [instruction sets] that are in abstract adequate to control and cause the execution of any sequence of operations... The really decisive considerations from the present point of view, in selecting an [instruction set], are more of a practical nature: simplicity of the equipment demanded by the [instruction set], and the clarity of its application to the actually important problems together with the speed of its handling of those problems.
Burks, Goldstine, and von Neumann, 1974
The "simplicity of the equipment" is as valuable a consideration for today‘s computers as it was for those of the 1950s. The goal of this chapter is to teach an instruction set that follows this advice, showing both how it is represented in hardware and the relationship between high-level programming languages and this more primitive one. Our examples are in the C programming language; Section 2.13 shows how these would change for an object-oriented language like java.
By learning how to represent instructions, you will also discover the secret of computing: the stored-program concept. Moreover, you will exercise your "foreign language" skills by writing programs in the language of the computer and running them on the simulator that comes with this book. You will also see the impact of programming language and compiler optimization on performance. We conclude with a look at the historical evolution of instruction sets and an overview of other computer dialects.
We reveal first instruction set a piece at a time, giving the rationale along with the computer structures. This top-down, step-by-step tutorial weaves the components with their explanations, making the computer‘s language more palatable. Figure 2.1 gives a sneak preview of the instruction set coverd in this chapter.
2.2 Operations of the Computer Hardware
Every computer must be able to perform arithmetic. The MIPS assembly language notation :
add a, b, c
instructions a computer to add the two variables b and c and to put their sum in a.
This notation is rigid in that each MIPS arithmetic instruction performs only one operation and must always have exactly three variables. For example, suppopse we want to place the sum of four variables b, c, d, and e into variable a. (In this section we are being deliberately vague what a "variable" is; in the next section we‘ll explain in detail.)
The following sequence of instructions adds the four variables:
add a, b, c # The sum of b and c is placed in a
add a, a, d #The sum of b, c, and d is now in a
add a, a, e #The sum of b, c, d, and e is now in a
Thus, it takes three instructions to sum the four variables.
The words to the right of the sharp symbol (#) on each line above are comments for the human reader, so the computer ignoes them. Note that unlike other programming languages, each line of this language can contain at most one instruction. Another difference from C is that comments always terminate at the end of a line.
The natural number of operands for an operation like addition is three: the two numbers being added together and a place to put the sum. Requiring every instruction to have exactly three operands, no more and no les, conforms to the philosophy of keeping the hardware simple: hardware for a variable number of operands is more complicated than hardware for a fixed number. This situation illustrates the first of three underlying principles of hardware design:
Design Principle 1: Simplicity favors regularity.