2. Instructions: Language of the computer (指令:计算机语言)

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. 

  1.   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.
  2.   The second example is the Intel X86, which powers both the PC and the cloud of the PostPC Era. 
  3.        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.  

时间: 2024-11-05 12:28:00

2. Instructions: Language of the computer (指令:计算机语言)的相关文章

The basic introduction to MIX language and machine

reference: The MIX Computer, The MIX Introduction sets, The basic info storage unit in MIX computer is the byte, which stores positive values in the range of 0 to 63. In MIX, Byte only has 6 bytes, and the word Byte refer to MIX 6-byte. A MIX word is

Architecture description language

Architecture description languages (ADLs) are used in several disciplines: system engineering, software engineering, and enterprise modellingand engineering. The software engineering community uses an architecture description language as a computer l

【译】x86程序员手册30-8.2 I/O指令

8.2 I/O Instructions I/O指令 The I/O instructions of the 80386 provide access to the processor's I/O ports for the transfer of data to and from peripheral devices. These instructions have as one operand the address of a port in the I/O address space. T

Hypervisor, computer system, and virtual processor scheduling method

A?hypervisor?calculates the total number of processor cycles (the number of processor cycles of one or more physical processors) in a first length of time based on the sum of the operating frequencies of the respective physical processors and the fir

[AS/400] Control Language(CL) 基本概念

本文内容源于 Go4AS400 简介 AS400 Control Language(CL) 是由指令(Command)组合而成,用于控制操作和调用系统功能.在 CL 程序中,指令用于和系统 OS400 进行交互. 以下是 CL 程序的主要功能 可以交互式地调用,也可以在批量模式下调用程序 决定程序的调用顺序 处理文件和其他对象(objects) 监控所有类型的消息 在不同的任务之间通信 改变对象的属性,然后进行处理 注,在 AS400 中,对象范指各种类型的概念,例如程序,文件. 尽管 CL 的

OpenFlow Switch学习笔记(六)——Instructions和Actions

本文主要重点讨论OpenFlow Switch规范的指令集,它们深刻影响着数据包在Switch中的处理行为,下面开始从以下几个部分谈起. 1.Instructions 每一个Flow Entry里都包含有一系列的Instructions,这些Instructions会在与该Flow Entry成功匹配的数据包上执行,进而导致数据包头信息的修改.Action Set的更新或者改变Pipeline Processing的处理行为.Instructions大致有下列几种类型,OpenFlow Swit

Advantages and disadvantages of python language

写一篇英文的稿子练练英语- -. Python, as a high-level programming language, was born by accident, but it is inevitable that it will be loved by programmers. Uncle turtle to the positioning of Python is "elegant", "clear", "simple", so Pyt

XML处理指令

“处理指令(PIs)允许文档包含用于应用程序的指令.指令并不是文档字符数据的一部分,但是必须通过应用程序传递”. 处理指令可以用于将信息传递给应用程序.处理指令可以出现在文档任意位置的标记外部.可以出现在序言中,包括文档的类型定义(DTD),文本内容或者文档之后. 处理指令,允许文档中包含由应用程序来处理的指令.在XML文档中,有可能会包含一些非XML格式的数据,这些数据XML处理器无法处理,我们就可以通过处理指令来通知其它应用程序来处理这些数据. 处理指令(PI)的语法和XML声明类似,以<?

计算机程序和C++语言简介

C++程序设计 第一章 计算机程序和C++语言简介 1.计算机是一台能够存储并处理数据的电子设备,包含硬件和软件两部分. 2.计算机硬件由: 1)中央处理单元(Central Processing Unit,CPU) 2)内存(主存) 3)外存储设备(磁盘.光盘.磁带) 4)输入输出设备(显示器.键盘.鼠标.打印机) 5)通信设备(调制解调器.网卡) 这些设备通过总线连接起来.数据传输通过总线进行.[总线又分为控制总线.数据总线.地址总线] 3.CPU 1)cpu通常由两部分组成:控制单元(co