第5章アルゴリズムのハードウェアによる実現:コンピューターシステム設計
LINK TO LEARNING学習リンク
There has been a debate among companies who are designing hardware as to whether CISC or RISC is better. Read this article chronicling this debate (https://openstax.org/r/76DebCISCvsRISC) from MicrocontrollerTips.
英語のヒント
ハードウェアを設計する企業の間では、CISCとRISCのどちらが優れているかが議論されてきた。MicrocontrollerTipsの、この議論をたどる記事(https://openstax.org/r/76DebCISCvsRISC)を読んでみよう。
Assembly and Machine Codeアセンブリと機械語コード
In our discussion of Figure 4.18 we saw assembly (output of the compiler) and object code, binary code, and machine code, which all designate output of the assembler. Machine code is the binary presentation of the assembly code. In some cases, there are assembly instructions that do not have a counterpart in the machine code called pseudo-assembly. For example, there are instructions in assembly that execute a go to if a number is less than another number. The only conditions known in machine code are equal and not equal, but not less than, less or equal, and so on. We can see this in an instruction set like MIPS.
英語のヒント
図4.18の説明では、コンパイラの出力であるアセンブリと、オブジェクトコード、バイナリコード、機械語コードを見た。後の三つはいずれも、アセンブラの出力を指す。機械語コードは、アセンブリコードを2進数で表したものだ。場合によっては、機械語コードに対応するものがないアセンブリ命令があり、擬似アセンブリと呼ばれる。たとえば、ある数が別の数より小さい場合にジャンプを実行するアセンブリ命令がある。機械語コードが認識する条件は、等しいか等しくないかだけであり、小さい、以下である、といった条件ではない。MIPSのような命令セットで、この例を見ることができる。
The assembler’s job is to ensure that the machine code file only contains instructions that are native to the processor; that is, part of the ISA. So, we can think of the machine code as being a subset of the assembly code. You never find an instruction in the machine code file that is not part of the ISA of the processor for which you want to generate the binary. The reason there are pseudo-assembly instructions is to give the compiler a bit more freedom to generate efficient code. Let us assume that you write a program in C and you think about functions calling each other. If you write a program in C++ or Java, you think in terms of objects, methods, inheritance, and so on (refer to Chapter 4 Linguistic Realization of Algorithms: Low-Level Programming Languages). We call this the programmer view of the language. What if you write (or read) assembly code? What do you see? This view is summarized in Figure 5.17.
英語のヒント
アセンブラの仕事は、機械語ファイルに含まれる命令が、そのプロセッサ固有のもの、つまりISAに属するものだけになるようにすることである。そのため、機械語コードはアセンブリコードの部分集合と考えられる。生成するバイナリの対象プロセッサのISAに属さない命令は、機械語ファイルには決して現れない。擬似アセンブリ命令があるのは、効率のよいコードを生成するために、コンパイラに少し多くの自由を与えるためである。Cでプログラムを書くなら、関数どうしが呼び出し合うことを考えるだろう。C++やJavaなら、オブジェクト、メソッド、継承などの観点で考える(第4章「アルゴリズムを言語で表現する:低水準プログラミング言語」を参照)。これを、その言語についてのプログラマーからの見方という。では、アセンブリコードを書く、あるいは読むときはどうだろうか。何が見えるだろうか。この見方を図5.17にまとめている。

attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license · CC BY 4.0 · Source出典
Figure 5.17 The assembly programmer sees a simpler, but more realistic view of the machine than the HLL programmer. (attribution: Copyright Rice University, OpenStax, under CC BY 4.0 license)
図5.17 アセンブリのプログラマーには、HLLのプログラマーよりも単純で、しかし実際の機械に近い姿が見える。(出典:著作権 Rice University、OpenStax。CC BY 4.0ライセンス)
Figure 5.17 shows the following:
図5.17は、次のことを示している。
• There is a processor (CPU) and memory.
• プロセッサ(CPU)とメモリがある。
• The CPU and the memory are connected by a bus, which is a data pathway. When you access the memory, you may want to get data and must provide an address. Or you may want to write data to memory, so you must provide both the data and the address to which this data will be written. In both cases, the CPU must provide an address, therefore, the address bus is single directional. But the data bus is bidirectional because you can send data to memory or get data from memory.
英語のヒント
• CPUとメモリは、データの通り道であるバスで接続されている。メモリへアクセスしてデータを取得するときは、アドレスを指定する必要がある。メモリへデータを書き込みたいときは、データとその書き込み先アドレスの両方を指定する。どちらの場合もCPUがアドレスを送るので、アドレスバスは一方向である。しかし、データはメモリへ送ることも、メモリから受け取ることもできるので、データバスは双方向である。
• Data is not the only thing you need to bring from the memory to the CPU. The main job of the CPU is to execute instructions on data. For example, adding two numbers involves data (the two numbers) and the command for addition (instruction), which is why there is a single directional bus from memory to CPU for getting instructions from the memory.
英語のヒント
• メモリからCPUへ運ぶ必要があるのは、データだけではない。CPUの主な仕事は、データに対して命令を実行することである。たとえば二つの数を足す場合、データ(二つの数)と、加算の指示(命令)の両方が必要である。そのため、メモリから命令を取得するための、メモリからCPUへ向かう一方向のバスがある。
• The memory holds several things: data, the instructions of the programs (shown as “Text” in Figure 5.17), some data needed by the OS to manage your program, and the resources it needs. The stack and heap are places in the memory to store data depending on the program at hand. The stack is used to store local variables (and some other stuff that we will discuss later), the heap stores dynamically allocated data, an Data in Figure 5.17 is another area in the memory to store global variables.
英語のヒント
• Inside the CPU, there are registers which carry hardware parts that store data, instructions, addresses, and so on. Each register stores one item. An x86 programmer has access to 16 registers, as we will see shortly. Because the CPU is executing a program, which is a series of instructions, the CPU must keep track of what the next instruction to be executed is.
英語のヒント
• CPU内部には、データ、命令、アドレスなどを保存するハードウェア部分を備えたレジスタがある。各レジスタは、一つの項目を保存する。後で見るように、x86のプログラマーは16個のレジスタを使える。CPUは一連の命令であるプログラムを実行するので、次に実行する命令が何かを把握しておく必要がある。
• Keeping track is the job of a specific register, shown separately from the other registers, called the program counter (PC). The PC is updated after executing each instruction to point to the next instruction to be executed. Also, it is useful to keep some information about the result of the instructions executed, such as whether the result generated by the current instruction is positive, negative, or zero, which is the job of the flags. A flag tells a program if a condition has been met.
英語のヒント
• 次の命令を把握するのは、プログラムカウンター(PC)という専用のレジスタの仕事である。図では、ほかのレジスタとは分けて示されている。PCは、各命令を実行した後、次に実行する命令を指すように更新される。また、現在の命令が生成した結果が正か負かゼロかなど、実行済みの命令の結果について情報を保持しておくと便利である。これを担当するのがフラグである。フラグは、ある条件が満たされたかどうかを、プログラムに知らせる。