慶應義塾大学
2009年度 秋学期

コンピューター・アーキテクチャ
Computer Architecture

2009年度秋学期 火曜日3時限
科目コード: 35010 / 2単位
カテゴリ:
開講場所:SFC
授業形態:講義
担当: Rodney Van Meter
E-mail: rdv@sfc.keio.ac.jp

第4回 10月20日 Lecture 4, October 20:
プロセッサー:命令の基本
Processors: Basics of Instruction Sets

Outline of This Lecture

Review: Numbers and Arithmetic

Review: プロセッサー・パフォマンス定式
The Processor Performance Equation

CPU time = (seconds )/ program = (Instructions )/ program × (Clock cycles )/ Instruction × (Seconds )/ Clock cycle


Instruction Sets

命令:基本の概念
Instructions: the Basic Idea

Computers execute instructions, which are usually compiled by a compiler, a piece of software that translates human-readable (usually ASCII) code into computer-readable binary.

コンピューターが命令を実行する。その命令はコンパイラーが人間の 読めるプログラムから通訳してある。例えば:

LOAD	R1, A
ADD	R1, R3
STORE	R1, A
This example shows three instructions, to be executed sequentially. The first instruction LOADs a value into register R1 from memory (we will come back to how the value that is loaded into R1 is found in a minute). The second instruction ADDs the contents of register R3 into register R1, then the third instruction STOREs the result into the original memory location.

CPU: the Central Processing Unit

ちょっと抽象的な絵ですが:

CPU block diagram
簡単に説明すると、CPUはこの機能の部品がある:

メモリー(記録):レジスター、スタック、ヒープ
Memory: Registers, Stacks, and Heaps

It is the job of the compiler to decide how to use the registers, stack, and heap most efficiently. Note that these functions apply to both user programs, or applications, and the operating system kernel.

命令の種類
Types of Instructions

Classes of Instructions Sets

The diagram below shows how data flows in the CPU, depending on the class of instruction set. (TOS = Top of Stack)

differences in data
						  flow for instruction
						  set classes

Memory Addressing

Each operand of an instruction must be fetched before the instruction can be executed. Data may come from (There are other addressing modes, as well, which we will not discuss.)

Immediate
ADD R4,#3
Regs[R4] ← Regs[R4] + 3
Register
ADD R4,R3
Regs[R4] ← Regs[R4] + Regs[R3]
Register Indirect
ADD R4, (R1)
Regs[R4] ← Regs[R4] + Mem[Regs[R1]]
Displacement
ADD R4, 100(R1)
Regs[R4] ← Regs[R4] + Mem[100+Regs[R1]]
Depending on the instruction, the data may be one of several sizes (using common modern terminology):

What an Instruction Looks Like

An instruction must contain the following:

Some architectures always use the same number of arguments, others use variable numbers. In some architectures, the addressing information and address are always the same length; in others they are variable.

In general, the arithmetic instructions are either two address or three address. Two-address operations modify one of the operands, e.g.

ADD R1, R3	; R1 = R1 + R3
whereas three-address operations specify a separate result register, e.g.
ADD R1, R2, R3	; R3 = R1 + R2
(n.b.: in some assembly languages, the target is specified first; in others, it is specified last.)

The MIPS architecture, developed in part by Professors Patterson and Hennessy, is relatively easy to understand. Its instructions are always 32 bits, of which 6 bits are the opcode (giving a maximum of 64 opcodes). rs and rt are the source and target registers, respectively. (Those fields are five bits; how many registers can the architecture support?) Instructions are one of three forms:

宿題
Homework

This week's homework (submit via email):

  1. Take your "hello, world" program and compile to assembly code.
    1. What type of processor is your system?
    2. Find a copy of the Instruction Set Reference Manual for your processor (it should be available online somewhere).
    3. What class of instruction set is your processor, load-store, register-memory, or accumulator? (It's unlikely to be a pure stack machine.)
    4. Determine if your stack grows up or down. (You may need to use a debugger for this.)
    5. How many different opcodes are there for your processor? How long is the opcode field in an instruction?
    6. How many different addressing modes does your processor have?
  2. Write a program to test the speed of your processor on integer arithmetic, in operations per second. Test the four basic functions: add, subtract, multiply, divide. Be careful: you will have to execute many instructions to get a good measurement! If you are using a Unix-like machine (or Cygwin), you may use the "time" command.
  3. Write a program to test the speed of your processor on floating-point arithmetic, in operations per second. Test the four basic functions: add, subtract, multiply, divide.
  4. Install the spim microprocessor onto your machine.

Next Lecture

Next lecture:

第5回 10月27日
Lecture 3, October 27: Processors: Instruction Sets and the Data Path

Readings for next time:

Additional Information

その他