第5章アルゴリズムのハードウェアによる実現:コンピューターシステム設計
Procedure Call Operations手続き呼び出し操作
One last item is related to procedure call—x86 has two instructions: CALL and RET to implement. However, the situation is more complicated than this. In HLLs, you have the concept of local variables and global variables. How is this enforced in assembly? Remember, the assembly program generated must behave in the same way you intended when you wrote the HLL program.
英語のヒント
最後に、手続き呼び出しについてである。x86には、その実装のためにCALLとRETという二つの命令がある。しかし、話はそれだけでは済まない。HLLには、ローカル変数とグローバル変数という概念がある。アセンブリでは、これをどう実現するのだろうか。生成されるアセンブリプログラムは、HLLで書いたときに意図したとおりに動作しなければならないことを、思い出そう。
Assembly uses the concept of a stack, the very well-known data structure that works as last-in-first-out, to simulate the notion of local variables, passing arguments to procedure, and saving some of the registers in memory during a procedure call. Why do we need to save some registers? Because we have only 16 registers in x86, and programmers use way more variables than that in their HLL.
英語のヒント
アセンブリでは、後入れ先出しで動作する、よく知られたデータ構造であるスタックを使って、ローカル変数という仕組みを再現し、手続きへ引数を渡し、手続き呼び出し中にレジスタの一部をメモリへ退避する。なぜレジスタを退避する必要があるのだろうか。x86には16個のレジスタしかないのに、プログラマーはHLLでもっと多くの変数を使うからである。
Vector Instructionsベクトル命令
You may have realized that we have not mentioned floating points at all in the x86 operations. This is because there is another set of instructions and another set of registers for floating points—the vector instructions. These instructions operate not on individual registers, but on a vector (i.e., a group of numbers). So, an addition operation can add 32 numbers to another 32 numbers at once. That is, the first number is added to the corresponding first number in the second vector, the second number to second number, and so forth. These operations are usually very efficient in many applications.
英語のヒント
x86の演算について、浮動小数点にはまったく触れていないことに気づいたかもしれない。それは、浮動小数点には別の命令群とレジスタ群、すなわちベクトル命令があるためである。これらの命令は、個々のレジスタではなく、ベクトル、つまり数の集まりを対象に動作する。したがって、一つの加算操作で、32個の数を別の32個の数に一度に足せる。つまり、最初の数を第2のベクトルの最初の数に、2番目の数を2番目の数に足す、という具合である。こうした演算は、多くのアプリケーションで非常に効率的である。