第5章アルゴリズムのハードウェアによる実現:コンピューターシステム設計
Application Programs Abstractionsアプリケーションプログラムの抽象化
Next, the programmer writes a program. The main difference between an algorithm and a program is that the former is written by an algorithm designer and the latter is written by a programmer so that the program can be executed by a machine. These programs are called application programs, or simply, programs, and there are billions of them in existence today. Once the programmer finishes writing the program, there are two more steps before it can be executed by a computer.
英語のヒント
次に、プログラマーがプログラムを書く。アルゴリズムとプログラムの主な違いは、前者をアルゴリズムの設計者が書くのに対し、後者は機械で実行できるようにプログラマーが書く点である。このようなプログラムをアプリケーションプログラム、あるいは単にプログラムといい、現在では何十億ものプログラムが存在する。プログラマーが書き終えてからコンピューターで実行できるようになるまでには、さらに二つの段階がある。
High-Level Programming Language高水準プログラミング言語
The program generated in the previous step is written in a programming language. There are many programming languages in the world currently. A high-level language (HLL) is the most evolved method by which a human can direct a computer on how to perform tasks and applications. The phrase high-level means that it is closer to a natural language rather than a machine level language such as strings of 1s and 0s. That is, HLL is more user-friendly, and it is made to make the life of the programmer easier regardless of the hardware or the machine. If you look at the code of a program, you find that it is still in English, yet a restricted version of English with very specific keywords and formats to remove the ambiguity that usually exists in natural human language.
英語のヒント
前の段階で作成されたプログラムは、プログラミング言語で書かれている。現在、世界には多くのプログラミング言語がある。高水準言語(HLL)は、人間がコンピューターにタスクやアプリケーションの実行方法を指示する、最も進化した方法である。「高水準」とは、1と0の並びのような機械語より、自然言語に近いという意味である。つまり、HLLは利用者にとって使いやすく、ハードウェアや機械の違いにかかわらず、プログラマーの作業を楽にするために作られている。プログラムのコードを見ると、やはり英語で書かれていることがわかる。しかし、それは厳密に指定されたキーワードと形式に制限された英語である。人間の自然言語に通常伴う曖昧さを取り除くためである。
Even though HLLs rely on restrictive versions of English, they still use English at a high level. The machine does not understand English and needs a low-level language; therefore, we need yet another next step: assembly language.
英語のヒント
HLLは制限された英語に基づいているとはいえ、依然として高いレベルで英語を使っている。機械は英語を理解せず、低水準言語を必要とする。そのため、さらに次の段階、すなわちアセンブリ言語が必要になる。
THINK IT THROUGH考えてみよう
One Hundred or One?100種類か、それとも1種類か?
Since HLLs aim to make the life of the programmers easy, why do we have many HLLs? Why not one language that all programmers use?
英語のヒント
HLLがプログラマーの作業を楽にするためのものなら、なぜ数多くのHLLが存在するのだろうか。すべてのプログラマーが使う、一つの言語ではいけないのだろうか。
Programming languages are typically designed to help create readable programs. However, some languages are designed with specific applications in mind. That is, some programming languages are easier to use for designing games, while other languages are meant to address mathematical problems or artificial intelligence. However, we can write any program in any language. But our task will be easier if we use the language that is designed with specific applications in mind.
英語のヒント
プログラミング言語は、通常、読みやすいプログラムを作れるように設計されている。しかし、特定の用途を念頭に置いて設計された言語もある。つまり、ゲームを作りやすい言語もあれば、数学の問題や人工知能を扱うための言語もあるのだ。とはいえ、どんなプログラムでも、どの言語でも書くことはできる。それでも、特定の用途を想定して設計された言語を使えば、作業は楽になる。
Assembly Languageアセンブリ言語
When you look at most mainstream programming languages, you find constructs such as functions, methods, subroutines, and objects. These concepts were invented to help human beings (the programmers) write their programs after understanding the algorithm. High-level languages make life easier for programmers. By using functions, objects, and other constructs, programmers can write programs faster and make them understandable and reusable for others. Computers, on the other hand, need specific instructions to perform tasks (for example, add this number to that other number and store the result in that place). Writing programs in this way is not easy for programmers because it is error prone, takes a lot of time to write correctly, and is not portable from one computer to the next. So, how do we deal with these conflicting requirements for programmers and computers? The answer is compilers.
英語のヒント
主流のプログラミング言語の多くを見ると、関数、メソッド、サブルーチン、オブジェクトなどの構成要素がある。これらの概念は、人間、すなわちプログラマーが、アルゴリズムを理解したうえでプログラムを書きやすくするために考案された。高水準言語はプログラマーの作業を楽にする。関数やオブジェクトなどの構成要素を使えば、プログラムをより速く書けて、ほかの人も理解し、再利用できるようにできる。一方、コンピューターがタスクを実行するには、具体的な命令が必要である。たとえば、「この数をあの数に足し、結果をあの場所に保存する」といったものだ。このような形でプログラムを書くのは、プログラマーにとって容易ではない。誤りが起こりやすく、正しく書くのに時間がかかり、別のコンピューターへ移植できないからである。それでは、プログラマーとコンピューターの間で相反するこの要件に、どう対処すればよいのだろうか。その答えがコンパイラである。
A compiler is a piece of software that takes a program written in a given HLL and generates another program that does the same task as the initial program but is written in a language that is much friendlier to the computer called assembly language. Assembly language is then translated into machine language code so that the program can be executed (Figure 5.7).
英語のヒント
コンパイラは、あるHLLで書かれたプログラムを受け取り、元のプログラムと同じタスクを実行する別のプログラムを生成するソフトウェアである。生成されるプログラムは、アセンブリ言語という、コンピューターにとってはるかに扱いやすい言語で書かれている。その後、実行できるように、アセンブリ言語を機械語のコードに翻訳する(図5.7)。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 5.7 A compiler takes code written in an HLL and converts it to “computer-friendly” and simple code called assembly language. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図5.7 コンパイラはHLLで書かれたコードを受け取り、アセンブリ言語という「コンピューターにとって扱いやすい」単純なコードに変換する。(出典:著作権 Rice University、OpenStax。CC BY 4.0ライセンス)
One low-level language designed to be computer friendly rather than human friendly is called assembly language. It does not use all the constructs found in HLLs such as objects or sophisticated data structure, which leads to two challenges.
英語のヒント
人間よりもコンピューターにとって扱いやすいように設計された低水準言語の一つを、アセンブリ言語という。アセンブリ言語では、オブジェクトや高度なデータ構造など、HLLにある構成要素をすべて使うわけではない。そのため、二つの課題が生じる。
The first challenge is to manage the output of the compiler, which is an assembly language program that you can open and read. It is basically a text file, so it is written in English. Remember, computers do not understand English; they only relate to 1s and 0s. To deal with this challenge we use yet another program, shown in Figure 5.5, called an assembler (note that compilers may invoke assemblers directly). The assembler takes, as input, the assembly program generated by the compiler, and as output, a file that contains the equivalent of that assembly program in terms of 1s and 0s. This generated file is no longer in English, and you cannot open it with your favorite text editor. It is called a machine language file. This is the file that a computer understands. Figure 5.8 shows an example of a program written in an HLL (actually, a middle-level language, which is the C programming language), which is then translated to x86 assembly language and then to binary (refer to Chapter 4 Linguistic Realization of Algorithms: Low-Level Programming Languages).
英語のヒント
第一の課題は、コンパイラの出力を扱うことである。その出力はアセンブリ言語のプログラムであり、開いて読むことができる。基本的にはテキストファイルなので、英語で書かれている。コンピューターは英語を理解せず、1と0しか扱わないことを思い出そう。この課題に対処するため、図5.5に示したアセンブラという別のプログラムを使う(コンパイラがアセンブラを直接呼び出す場合もあることに注意しよう)。アセンブラは、コンパイラが生成したアセンブリプログラムを入力として受け取り、それと等価な内容を1と0で表したファイルを出力する。生成されたファイルは、もはや英語ではなく、使い慣れたテキストエディターで開くことはできない。これを機械語ファイルという。これが、コンピューターの理解するファイルである。図5.8は、HLL(実際には中水準言語であるC言語)で書かれたプログラムを、x86アセンブリ言語、さらに2進コードへ翻訳する例を示している(第4章「アルゴリズムを言語で表現する:低水準プログラミング言語」を参照)。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 5.8 Programmers write in programs using HLLs but computers execute binary code, so we need to perform a translation. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図5.8 プログラマーはHLLを使ってプログラムを書くが、コンピューターが実行するのは2進コードなので、翻訳が必要である。(出典:著作権 Rice University、OpenStax。CC BY 4.0ライセンス)
The second challenge relates to managing the assembly language itself. If you look at the assembly language program, you find that it consists of instructions such as add, divide, and jump. But are these instructions recognized by all the processors (i.e., the main part of the computer that executes the program) in the world? If you give these instructions to a processor such as Intel, AMD, ARM, Qualcomm, or IBM Power, will they all recognize these instructions? The answer depends on a new concept referred to as the instruction set architecture.
英語のヒント
第二の課題は、アセンブリ言語そのものを扱うことに関係している。アセンブリ言語のプログラムを見ると、加算、除算、ジャンプなどの命令で構成されている。しかし、世界中のすべてのプロセッサ、すなわちプログラムを実行するコンピューターの主要部分が、これらの命令を認識するのだろうか。Intel、AMD、ARM、Qualcomm、IBM Powerなどのプロセッサに渡したとき、どれもその命令を認識するのだろうか。答えは、命令セットアーキテクチャーという新しい概念によって決まる。