Instruction Set Design II
Tom Kelliher, CS 240
Feb. 6, 2004
ASAP, make sure you can log-into phoenix.
Read 3.5, A.1--5, A.9.
Instruction Set Design I.
- Instruction operands: registers.
- Accessing memory.
- Instruction formats.
Conditional instructions, SPIM.
(Continued.)
Properties of registers:
- Number of registers. 32 for MIPS, including the hardwired register.
Two ways of naming: numbers, convention ``nicknames''. Why not more? Size
of register file, size of operand fields within instructions.
Other register files: x86, SPARC and the register window (Berkeley RISC,
about 128 registers, spilling).
Register renaming: ISA registers vs. physical registers.
- Number of bits/register. 32. Word size.
Implications: size of address space, datapath width.
- General purpose vs. special purpose.
MIPS, M68000, x86.
See pg. A-23 for the full register naming convention. Note the limited
number of s and t registers.
Our simple convention:
- Use
$s0, $s1, etc. for C variables.
- Use
$t0, $t1, etc. for temps.
Recall:
f = (g + h) - (i + j);
Assume f through j are in $s0 through $s4,
respectively. Compile the statement.
-
HLL have complex data structures such as arrays and structs. How are they
handled?
-
Data transfer instructions: load, store. operands: memory address,
register.
-
Actual MIPS instructions: lw, sw.
Base and offset addressing: lw $s0, 8($s1)
-
MIPS memory is byte addressable, so word addresses differ by 4:

-
Endianess:
- Big endian machines: HP PA-RISC, IBM Power, MIPS, SPARC.
- Little Endian: x86.
- MIPS can go either way!
Compile the following:
g = h + A[8];
where g is in $s1, h is in $s2, and the base
address of A, an array of 100 words, is in $s3.
Base, offset addressing.
Compile each of the following:
A[12] = h + A[8];
A[j] = h + A[i];
Notes:
- Base, offset addressing, using constant offsets, is similarly useful
for accessing members of structures.
- Variables in registers are simpler to use and faster than variables
in memory. Compilers must be clever in optimizing register use.
Spilling registers.
How do we encode instructions for storage in memory? Issues:
- Compactness --- smaller programs use less memory bus bandwidth and
less memory space.
- Decoding ease --- simplify the instruction decoder.
- Length --- fixed or variable.
- Size --- one or multiple words.
Example instruction: add $s2, $s0, $s1

Fields:
- Op: Opcode.
- Rs: First source operand.
- Rt: Second source operand.
- Rd: Destination operand.
- Shamt: Shift amount --- ignore for now.
- Func: Function. Further specification of the opcode.
In assembly: Op/Func Rd, Rs, Rt
Notes:
- Memorize field positions and sizes for all three formats.
Necessary later.
- Example encodings:

- How do we fit Memory instructions into r-format? We can't!
- Design principle 3: Good design demands good compromises.
- Introduce another format --- added complexity tradeoff.
Example instruction: lw $s0 8($s1)

Fields:
- Op: Opcode.
- Rs: Source register.
- Rt: Destination register.
- Address: 16-bit signed immediate value.
Offset range?
In assembly: Op/Func Rt, address(Rs)
Notes:
- This format also used for immediate operands:
addi $1, $2, 123.
- Example encodings:

Thomas P. Kelliher
Thu Feb 5 13:49:49 EST 2004
Tom Kelliher