Tom Kelliher, CS 240
Sept. 2, 2005
Read 2.5-2.6.
Introduction
Logical and conditional instructions in MIPS.
Instruction semantics:
add a, b, c # This, BTW, is a comment. sub a, a, bDe-compile into a single HLL statement:
add a, b, c add a, a, d add a, a, e
Compile each of the following:
a = b + c; d = a - e; f = (g + h) - (i + j);
Where are the operands?
$0
to $31
or $s0
, $t0
, etc.
Example:
add $1, $2, $3
Properties of registers:
Other register files: x86, SPARC and the register window (Berkeley RISC, about 128 registers, spilling).
Register renaming: ISA registers vs. physical registers.
Implications: size of address space, datapath width.
MIPS, M68000, x86.
See pg. A-24 (CD) for the full register naming convention. Note the limited number of s and t registers.
Our simple convention:
$s0
, $s1
, etc. for C variables.
$t0
, $t1
, etc. for temps.
Recall:
f = (g + h) - (i + j);Assume f through j are in
$s0
through $s4
,
respectively. Compile the statement.
Base and offset addressing: lw $s0, 8($s1)
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:
Example:
lw $1, 4($0) lw $2, 8($0) add $1, $1, $2 sw $1 0($0)
Example instruction: add $s2, $s0, $s1
Fields:
Op/Func Rd, Rs, Rt
Notes:
Assembly | Op | Rs | Rt | Rd | Shamt | Func |
add $1, $2, $3 |
0 | 2 | 3 | 1 | 0 | 32 |
sub $4, $5, $6 |
0 | 5 | 6 | 4 | 0 | 34 |
Example instruction: lw $s0 8($s1)
Fields:
Offset range?
Op/Func Rt, address(Rs)
Notes:
addi $1, $2, 123
.
Assembly | Op | Rs | Rt | Address |
lw $1, 1000($2) |
35 | 2 | 1 | 1000 |
sw $3, -12($4) |
43 | 4 | 3 | -12 |