美文网首页
软件在“洞”里(二) —— 读《计算思维史话》(九)

软件在“洞”里(二) —— 读《计算思维史话》(九)

作者: 刘东利2020 | 来源:发表于2023-06-04 06:33 被阅读0次

    为了解释指令集和一般程序之间的差别,作者举了一个例子,称之为“档案管理员模型”(The file clerk model):

    The file clerk was given a job to do and then had to move back and forth to racks of filing cabinets, taking files out and putting them back, scribbling notes on pieces of paper, passing notes around, and so on, until the job was completed.

    这个模型都包括什么呢?

    - 档案柜,里面有各种卡片存储着各种信息

    - 假设档案员是个新手、或者说他需要傻瓜操作,那么

    - 我们创建了档案员如何执行查找、计算、执行等基本必要操作的卡片

    - 便签本,档案员用于临时记录一下信息

    在这个模型中:

    If there is enough room on the scratch pad, the clerk could store this information on the pad for the duration of the calculation.

    This is an example of a trade-off in the hardware design: the balance between the clerk having to shuffle cards in and out versus increasing the amount of stor�age space needed on the pad.

    什么放在便签本上,什么放在档案柜里面呢?

    Let us teach the file clerk how to use the scratch pad. The instructions can be divided into two groups.

    One group is a core set of simple procedures that come with the pad – add, transfer, and so on. In a computer, these instructions, called the instruction set, are the ones that have been implemented in the hard�ware: they do not change when we change the problem. They are like the clerk’s intrinsic abilities.

    Then there is a set of instructions specific to the task at hand, such as calculating the total number of sales for the state of Washington. This set of specialized instructions is the “program.” The program’s instructions can be broken down into operations from the core set as we have seen. The pro�gram represents the detailed instructions about how to use the clerk’s intrinsic abilities to do the specific job.

    如果用工厂的一个工位来做类比:

    - “指令集”是工人手边所有工具

    - “便签本”是工作台用来放工具的

    - “程序”是作业指导书

    三者加总就告诉工人如何适用工具来完整加工、组装等工作:

    To get the right answer, the clerk must follow exactly the instructions that constitute the “program” in precisely the right order.

    与此同时:

    We can ensure this by designating an area on the scratch pad to keep track of which steps have been completed. In a computer, this area is called a program counter.

    类似于流水线作业中的工人,有些工序是需要确认才能放行的 —— 在计算机这里是每个都确认,program counter就起到了check list的作用:

    The program counter tells the clerk where he is in the list of instructions that constitute the program.

    As far as the clerk is concerned, this number is just an “address” that tells him where to look for the card with the instruction about what to do next. The clerk goes and gets this instruction and stores it on the pad. In a computer, this storage area is called the instruction register.

    Before carrying out the instruc�tion, the clerk prepares for the next one by adding one to the number in the program counter.

    The clerk will also need some temporary storage areas on the pad to do the arithmetic, save intermediate values, and so on. In a computer, these storage areas are called registers.

    “便签本”也就有了另外一种作用,除了存储指令,还可以存储某些WIP —— 因为计算处理的对象都是“数据”,是无形的,所以就没必要在自己的工位上划分不同的“形状”、“空间”的存储了,都是寄存器。

    总结:

    These elementary instructions now enable us to get the computer to do many different types of calculations. The machine is able to perform complex operations by breaking them down into the basic operations it understands.

    是计算机能将“计算”的基本工具“原子化”(ICT领域的人喜欢说这个词,哈哈),才使得计算机有了无限可能:

    As Richard Feynman says, “The inside of a com�puter is as dumb as hell but it goes like mad!”

    A computer can perform many millions of simple operations a second, and multiply two numbers far faster than any human.

    天下武功,唯快不破

    However, it is important to remember that, at its heart, a computer is just like a very fast, dumb file clerk. It is only because a computer can do the basic operations so quickly that we do not realize that it is in fact doing things very stupidly. 

    It is only because a computer can do the basic operations so quickly that we do not realize that it is in fact doing things very stupidly.

    相关文章

      网友评论

          本文标题:软件在“洞”里(二) —— 读《计算思维史话》(九)

          本文链接:https://www.haomeiwen.com/subject/wwzmedtx.html