MIPS (Millions of Instructions Per Second)
MIPS adalah singkatan dari Millions of Instructions Per Second. Itu adalah ukuran untuk kecepatan perhitungan pada suatu program. Seperti pengukuran lainnya, seringkali disalahgunakan daripada digunakan secara benar (sangat sulit untuk membandingkan MIPS bagi komputer-komputer yang berbeda jenis).
Arithmetic Operations
- Add and subtract, three operands
o Two sources and one destination
add a, b, c # a gets b + c
- All arithmetic operations have this form
- Design Principle 1: Simplicity favours regularity
o Regularity makes implementation simpler
o Simplicity enables higher performance at lower cost
Arithmetic Example
- C code:
f = (g + h) - (i + j);
- Compiled MIPS code:
add t0, g, h # temp t0 = g + h
add t1, i, j # temp t1 = i + j
sub f, t0, t1 # f = t0 - t1
Register Operands
- Arithmetic instructions use register operands
- MIPS has a 32 × 32-bit register file
o Use for frequently accessed data
o Numbered 0 to 31
o 32-bit data called a “word”
- Assembler names
o $t0, $t1, …, $t9 for temporary values
o $s0, $s1, …, $s7 for saved variables
- Design Principle 2: Smaller is faster
o c.f. main memory: millions of locations
Register Operand Example
- C code:
f = (g + h) - (i + j);
o f, …, j in $s0, …, $s4
- Compiled MIPS code:
add $t0, $s1, $s2
add $t1, $s3, $s4
sub $s0, $t0, $t1
Memory Operands
- Main memory used for composite data
o Arrays, structures, dynamic data
- To apply arithmetic operations
o Load values from memory into registers
o Store result from register to memory
- Memory is byte addressed
o Each address identifies an 8-bit byte
- Words are aligned in memory
o Address must be a multiple of 4
- MIPS is Big Endian
o Most-significant byte at least address of a word
o c.f. Little Endian: least-significant byte at least address.
Memory Operand Example 1
- C code:
g = h + A[8];
o g in $s1, h in $s2, base address of A in $s3
- Compiled MIPS code:
o Index 8 requires offset of 32
§ 4 bytes per word
lw $t0, 32($s3) # load word
add $s1, $s2, $t0
Memory Operand Example 2
- C code:
A[12] = h + A[8];
o h in $s2, base address of A in $s3
- Compiled MIPS code:
o Index 8 requires offset of 32
lw $t0, 32($s3) # load word
add $t0, $s2, $t0
sw $t0, 48($s3) # store word