YP.1.7 How Do We Get the Electrons to Do The Work?(双语)

from:

[1] Introduction to Computing System, from Bits and Gates to C and Beyond. Yale N. Patt and Sanjay J. Patel. McGraw-Hill Higher Education.(英)

[2] 计算系统基础_陈道蓄_第一章引言http://resource.jingpinke.com/details?uuid=ff808081-22c93527-0122-c936e141-1a96&objectId=oid:ff808081-22c93527-0122-c936e141-1a97 (中)

1.7 How Do We Get the Electrons to Do The Work?

Figure 1.6 shows the process we must go through to get the electrons (which actually do the work) to do our bidding. We call the steps of this process the "Levels of Transformation." As we will see, at each level we have choices. If we ignore any of the levels, our ability to make the best use of our computing system can be very adversely affected.

 levels of transformation

Figure 1.6 Levels of transformation

 "Levels of Transformation." As we will see, at each level we have choices. If we ignore any of the levels, our ability to make the best use of our computing system can be very adversely affected.

1.7.1 The Statement of the Problem

We describe the problems we wish to solve with a computer in a "natural language."  Natural languages are languages that people speak, like English, French, Japanese, Italian, and so on. They have evolved over centuries in accordance with their usage. They are fraught with a lot of things unacceptable for providing instructions to a computer. Most important of these unacceptable attributes isambiguity. Natural language is filled with ambiguity. To infer the meaning of a sentence, a listener is often helped by the tone of voice of the speaker, or at the very least, the context of the sentence.

An example of ambiguity in English is the sentence, "Time flies like an arrow." At least three interpretations are possible, depending on whether (1) one is noticing how fast time passes, (2) one is at a track meet for insects, or (3) one is writing a letter to the Dear Abby of Insectville. In the first case, a simile, one is comparing the speed of time passing to the speed of an arrow that has been released. In the second case, one is telling the timekeeper to do his/her job much like an arrow would. In the third case, one is relating that a particular group of flies (time flies, as opposed to fruit flies) are all in love with the same arrow.

Such ambiguity would be unacceptable in instructions provided to a computer. The computer,electronic idiot that it is, can only do as it is told. To tell it to do something where there are multiple interpretations would cause the computer to not know which interpretation to follow.

1.7.2 The Algorithm

The first step in the sequence of transformations is to transform thenatural language description of the problemto an algorithm, and in so doing, get rid of the objectionable characteristics. An algorithm is a step-by-step procedure that is guaranteed to terminate, such that each step is precisely stated and can be carried out by the computer. There are terms to describe each of these properties. 

We use the term definitenessto describe the notion that each step is precisely stated. A recipe for excellent pancakes that instructs the preparer to "stir until lumpy" lacks definiteness, since the notion of lumpiness is not precise.

We use the term effective computability to describe the notion that each step can be carried out by a computer. A procedure that instructs the computer to "take the largest prime number" lacks effective computability, since there is no largest prime number.

We use the term finiteness to describe the notion that the procedure terminates. For every problem there are usually many different algorithms for solving that problem. One algorithm may require the fewest number of steps. Another algorithm may allow some steps to be performed concurrently. A computer that allows more than one thing to be done at a time can often solve the problem in less time, even though it is likely that the total number of steps to be performed has increased.

1.7.3 The Program

The next step is to transform thealgorithm into a computer program, in one of the programming languages that are available. Programming languages are "mechanical languages." That is, unlike natural languages, mechanical languages did not evolve through human discourse. Rather, they were invented for use in specifying a sequence of instructions to a computer. Therefore, mechanical languages do not suffer from failings such as ambiguity that would make them unacceptable for specifying a computer program.

There are more than 1,000 programming languages. Some have been designed for use with particular applications, such as Fortran for solving scientific calculations and COBOL for solving business data-processing problems. In the second half of this book, we will use C, a language that was designed for manipulating low-level hardware structures. 

Other languages are useful for still other purposes. Prolog is the language of choice for many applications that require the design of an expert system. LISP was for years the language of choice of a substantial number of people working on problems dealing with artificial intelligence. Pascal is a language invented as a vehicle for teaching beginning students how to program.

There are two kinds of programming languages,high-level languages and low-level languages. High-level languages are at a distance (a high level) from the underlying computer. At their best, they are independent of the computer on which the programs will execute. We say the language is "machine independent." All the languages mentioned thus far are high-level languages. Low-level languages are tied to the computer on which the programs will execute. There is generally one such low-level language for each computer. That language is called theassembly language for that computer.

1.7.4 The ISA

The next step is to translate the program into the instruction set of the particular computer that will be used to carry out the work of the program. Theinstruction set architecture (ISA) is the complete specification of the interface between programs that have been written and the underlying computer hardware that must carry out the work of those programs.

The ISA specifies the set of instructions the computer can carry out, that is, what operations the computer can perform and what data is needed by each operation. The termoperandis used to describe individual data values. The ISA specifies the acceptable representations for operands. They are calleddata typesAdata type is a legitimate representation for an operand such that the computer can perform operations on that representation. The ISA specifies the mechanisms that the computer can use to figure out where the operands are located. These mechanisms are called addressing modes.

The number of operations, data types, and addressing modes specified by an ISA vary among the different ISAs. Some ISAs have as few as a half dozen operations, whereas others have as many as several hundred. Some ISAs have only one data type, while others have more than a dozen. Some ISAs have one or two addressing modes, whereas others have more than 20. The x86, the ISA used in the PC, has more than 100 operations, more than a dozen data types, and more than two dozen addressing modes.

The ISA also specifies the number of unique locations that comprise the computer's memory and the number of individual 0s and 1s that are contained in each location.

Many ISAs are in use today. The most common example is the x86, introduced by Intel Corporation in 1979 and currently also manufactured by AMD and other companies. Other ISAs are the Power PC (IBM and Motorola), PA-RISC (Hewlett Packard), and SPARC (Sun Microsystems). 

The translation from a high-level language (such as C) to the ISA of the computer on which the program will execute (such as x86) is usually done by a translating program called acompiler.To translate from a program written in C to the x86 ISA, one would need an x86 C compiler. For each high-level language and each desired target computer, one must provide a corresponding compiler.

The translation from the unique assembly language of a computer to its ISA is done by anassembler.

1.7.5 The Microarchitecture

The next step is to transform the ISA into an implementation. The detailed organization of an implementation is called itsmicroarchitecture.So, for example, the x86 has been implemented by several differentmicroprocessors over the years, each having its own unique microarchitecture. The original implementation was the 8086 in 1979. More recently, in 2001, Intel introduced the Pentium IV microprocessor.

Motorola and IBM have implemented the Power PC ISA with more than a dozen different microprocessors, each having its own microarchitecture. Two of the more recent implementations are the Motorola MPC 7455 and the IBM Power PC 750FX.

Each implementation is an opportunity for computer designers to make different trade-offs between the cost of the microprocessor and the performance that microprocessor will provide. Computer design is always an exercise in trade-offs, as the designer opts for higher (or lower) performance at greater (or lesser) cost. 

The automobile provides a good analogy of the relationship between an ISA and a microarchitecture that implements that ISA. The ISA describes what the driver sees as he/she sits inside the automobile. All automobiles provide the same interface (an ISA different from the ISA for boats and the ISA for airplanes). Of the three pedals on the floor, the middle one is always the brake. The one on the right is the accelerator, and when it is depressed, the car will move faster. The ISA is about basic functionality. All cars can get from point A to point B, can move forward and backward, and can turn to the right and to the left.

The implementation of the ISA is about what goes on under the hood引擎罩. Here all automobile makes and models are different, depending on what cost/performance trade-offs the automobile designer made before the car was manufactured. So, some automobiles come with disc brakes, others (in the past, at least) with drums. Some automobiles have eight cylinders, others run on six cylinders, and still others have four. Some are turbocharged涡轮增压, some are not. In each case, the "microarchitecture" of the specific automobile is a result of the automobile designers' decisions regarding cost and performance.

1.7.6 The Logic Circuit

The next step is to implement each element of the microarchitecture out of simple logic circuits. Here, also, there are choices, as the logic designer decides how to best make the trade-offs between cost and performance. So, for example, even for the simple operation of addition, there are several choices of logic circuits to perform this operation at differing speeds and corresponding costs.

1.7.7 The Devices

Finally, each basic logic circuit is implemented in accordance with the requirements of the particular device technology used. So, CMOS circuits are different from NMOS circuits, which are different, in turn, from gallium镓 arsenide砷化物 circuits.

1.7.8 Putting It Together

In summary, from the natural language description of a problem to the electrons running around that actually solve the problem, many transformations need to be performed. If we could speak electron, or the electrons could understand English, perhaps we could just walk up to the computer and get the electrons to do our bidding. Since we can't speak electron and they can't speak English, the best we can do is this systematic sequence of transformations. At each level of transformation, there are choices as to how to proceed. Our handling of those choices determines the resulting cost and performance of our computer. 

In this book, we describe each of these transformations. We show howtransistors combine to form logic circuits, howlogic circuits combine to form the microarchitecture, and how themicroarchitecture implements a particular ISA, in our case, the LC-3. We complete the process by going from the English language description of a problem to a C program that solves the problem, and we show how that C program is translated (i.e., compiled) to the ISA of the LC-3.

We hope you enjoy the ride.

1.7   如何让电子解决问题

图1.6显示了我们让电子执行我们的命令的过程。我们把这个过程称为“逐层转换”。我们将会看到,在每一个层上,我们都会有几种选择。如果我们忽视了任何一层的话,那么想要最大限度的利用好计算系统将会受到极大的影响。

1.7.1 问题的陈述

我们用“自然语言”来描述那些我们希望计算机来解决的问题。自然语言就是人类所讲的语言。这些语言已经随着它们的使用发展了几个世纪。这些语言中充满了计算机不能接受的指令,最重要的就是它的不明确性。为了推断出一句话的含义,听者通常会根据说话人的发音的语调,或者至少根据语句的上下文来推断。

如果要把这种意思不明确的语言作为指令提供给计算机,计算机是不可能理解的。计算机是一个纯粹的电子白痴,它只能机械的按照我们的命令去做。如果用一句有歧义的话叫它做事,它就会无所适从。

1.7.2 算法

要想进行一系列的转换,第一个步骤就是把一个问题的自然语言描述转换成一个算法,在这样做的过程中,舍弃自然语言一些有歧义的特点。算法是一个逐步的过程,它一定能够运行结束,而且每个步骤都被精确地描述,并能被计算机执行。我们用一些专门的术语来描述这些性质。

术语“确定性”(definiteness)用来描述每个步骤都必须精确表达的概念。例如,煎饼的烹饪法要求“搅拌直到成块”是缺乏确定性的,因为“成块”的概念是不精确的。

术语“有效可计算性”(effective computability)描述每个步骤都能被计算机执行的概念。一个叫计算机“找出最大的素数”的程序缺乏有效计算,因为根本没有最大的素数。

术语“有限性”(finiteness)描述程序能最终结束的概念。

要解决一个问题通常有许多不同的算法。某一个算法可能需要最少的步骤;另外一个算法可能允许有些步骤同时运行。一台能同时做多件事的计算机通常能用比较少的时间解决问题,即使执行的步骤总数可能会增加。

1.7.3 程序

下一步是用一种现有的编程语言把算法转换为一个程序。编程语言是“机械语言”。也就是说,和自然语言不同,机械语言不是在人类交谈中演化形成的。相反地,它们是被发明用来详细说明一系列计算机指令的。因此机械语言不会遇到一些歧义性的东西而使得它们变得不可接受。

目前世界上的程序设计语言超过1,000种。其中一些是为特定的应用服务的,例如用于科学计算的Fortran语言和用于商业数据处理的COBOL语言。在本书的第二部分中,我们使用C语言,它被设计用来操作低层硬件结构。

    其它的语言比如说Prolog是需要设计一种专家系统时可选择的语言,LISP是一种研究人工智能问题的工作者可选择的语言,Pascal是一门教初学者怎样编程的入门语言。

    编程语言分为低级语言和高级语言两类。高级语言和低层计算机有一定的距离,它独立于用来执行程序的计算机之外,我们称它“独立于机器”。上面提到的这些语言都是高级语言。低级语言与执行程序的计算机紧密相关。基本上每种计算机都有自己的一门低级语言。我们称它为相应机器的汇编语言

1.7.4 指令集体系结构(ISA)

下一步就是把程序翻译成执行程序作业的机器的指令集。指令集体系结构(ISA)是编写的程序和执行程序的底层计算机硬件之间的接口的完整的定义。                             

    指令集结构指明了计算机能够执行的指令集,也就是说计算机能够执行的操作和每一步操作所需的数据。“操作数”是用来描述一个个数据的值。指令集结构指明了操作数能够被接受的表示方法,它们叫做“数据类型”,它是操作数的合法表示,以便计算机对其表示方法进行运算。指令集结构规定了计算机能够在哪里找到操作数,这种规定叫做寻址模式

    不同的指令集结构规定的操作数数据类型寻址模式的数量,随不同的指令集结构而不同。有些指令集结构有数百种操作,而有些则少至十来个。有些指令集结构只有一种数据类型,而有些却多达十几种。有的只有一两种寻址模式,而有些却有二十多种。IA-32有一百多种操作,十几种数据类型和二十几种寻址模式。

    指令集结构同样也规定了计算机存储单元的数量,以及每个存储单元所包含的0和1的数量。

    许多指令集结构到今天都还在应用。举个最普遍的例子,用于个人计算机的IA-32指令集结构,是在1979年被英特尔发明的,至今仍被AMD和其它的公司所生产。其它的指令集结构有PowerPC(IBM和Motorola),Alpha(康柏计算机公司),PA-RISC(HP)和SPARC(SUN和HAL)。

    把高级语言(像C语言)翻译成计算机能够执行的指令集结构(如IA-32)的工作通常由一个被叫做编译器的翻译程序来完成。为了可以把一个用C语言写的程序翻译到IA-32的指令集结构,必须要使用一个IA-32的编译器。对于每一种高级语言和每一种目标机器,都必须提供一个相应的编译器

    从一种计算机的汇编语言到它的指令集结构的翻译工作,是由汇编器来完成的。

1.7.5 微体系结构

    下一步就是把指令集体系结构转换为其实现。这种实现的详细组织被称为微体系结构。比如说,在过去的几年中,被不同的微处理器使用的IA-32,每一种都有它自己的微结构。这种最初的实现是1979年的8086。更近一点的时候,在1999年,英特尔推出了奔腾III微处理器。而康柏计算机公司已经在四个不同的微处理器(包括21064,21164,21264,21364)中实现了Alpha ISA,每一个都有它独自的微结构,

    对于计算机设计者来说,每一种实现都是一次对微处理器的费用和性能之间的平衡。计算机设计永远是进行这种平衡的一种操作,因为设计者在使用更高(低)成本时会设计计算机有更好(差)的性能表现。

    汽车就是一个关于ISA和实现它的微结构之间的关系的很好的比喻。指令集结构就像司机坐在汽车里时能看到的东西。所有的汽车都会有同样的接口(一个不同于船只和飞机的指令集结构):在底部的三个踏板中,中间的那个永远是用来刹车的。右边那个就是加速器,当被压下的时候,汽车就会加速。这些指令集结构都是来实现一些基本功能。所有的汽车可以从A地到达B地,可以向前或者向后移动,也向右或者向左转弯。

微结构的实现就像在车蓬下运行的东西。所有汽车的制造和模型都是不一样的,这取决于在汽车制造之前设计者在使用成本和设计功能上的平衡。所以,有些汽车就会有盘式制动器,而有些是鼓式制动器(至少,过去是这样的)。有一些汽车是有八个汽缸,有些有六个,甚至有些是四个的。有些汽车是用涡轮加压的,而有些却没有。有时候,一辆汽车的微结构是设计者在考虑了汽车成本以及性能后的结果。

1.7.6 逻辑电路

下一步就是组成微结构的每一个单元的实现。这也会有很多选择,因为逻辑设计者可以决定如何才可以尽量平衡成本和性能。比如说,即使是做一个很简单的加法器,在不同的速度和相应的成本下也会有很多种逻辑电路的选择去实现这种运算。

1.7.7设备

最终,每一种基本的逻辑电路都是根据它所需要的特定设备所采用的技术来实现的。所以,CMOS电路不同于NMOS电路,并且也不同于砷化镓电路

1.7.8 总结

总的说来,从用自然语言描述一个问题到通过电子的运行来解决这个问题,需要完成许多层转换。如果我们能说“电子语言”,或者电子能理解我们的语言,也许我们仅仅需要走近电脑让它执行我们的命令。但是我们不会说“电子语言”,而它们也不会说人类的语言,我们所能做得最好的就是系统地有序的进行转换。在每一层转换上如何进行都有许多种选择。我们对这些选择的处理决定了最终计算机的成本和性能。

在本书中,我们描述了每一个转换:我们演示了晶体管是怎样组合从而形成逻辑电路的,逻辑电路又是怎样结合从而形成微结构的,而微结构又是怎样来实现特殊的指令集结构(在我们的实例中,就是LC-3)。我们从用自然语言描述一个问题开始直到用C语言程序解决它而完成了这个过程,还讲述了怎样把C语言程序翻译到LC-3的指令集结构中。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值