Operands
i) Register Operands
1 2 3 4
add $s0, $s1, $s2 # f = g + h
1) operation by name
2) operand getting result (“destination”)
3) 1st operand for operation (“source1”)
4) 2nd operand for operation (“source2”)
·
MIPS has 32 x 32 bit register file (32 bit=1 word)
·
Syntax is rigid: 1 operator, 3 operands
–Why? Keep
hardware simple via regularity
·
Register name
Register name
|
Number
|
usage
|
$zero
|
0
|
Constant 0
|
$at
|
1
|
reserved for assembler
|
$v0
|
2
|
expression evaluation and results of a function
|
$v1
|
3
|
expression evaluation and results of a function
|
$a0
|
4
|
Argument 1
|
$a1
|
5
|
Argument 2
|
$a2
|
6
|
Argument 3
|
$a3
|
7
|
Argument 4
|
$t0
|
8
|
temporary (not preserved across call)
|
$t1
|
9
|
temporary (not preserved across call)
|
$t2
|
10
|
temporary (not preserved across call)
|
$t3
|
11
|
temporary (not preserved across call)
|
$t4
|
12
|
temporary (not preserved across call)
|
$t5
|
13
|
temporary (not preserved across call)
|
$t6
|
14
|
temporary (not preserved across call)
|
$t7
|
15
|
temporary (not preserved across call)
|
$s0
|
16
|
saved temporary (preserved across call)
|
$s1
|
17
|
saved temporary (preserved across call)
|
$s2
|
18
|
saved temporary (preserved across call)
|
$s3
|
19
|
saved temporary (preserved across call)
|
$s4
|
20
|
saved temporary (preserved across call)
|
$s5
|
21
|
saved temporary (preserved across call)
|
$s6
|
22
|
saved temporary (preserved across call)
|
$s7
|
23
|
saved temporary (preserved across call)
|
$t8
|
24
|
temporary (not preserved across call)
|
$t9
|
25
|
temporary (not preserved across call)
|
$k0
|
26
|
reserved for OS kernel
|
$k1
|
27
|
reserved for OS kernel
|
$gp
|
28
|
pointer to global area
|
$sp
|
29
|
stack pointer
|
$fp
|
30
|
frame pointer
|
$ra
|
31
|
return address (used by function call)
|
·
Design
principle : Smaller is faster
ii) Memory Operands
·
Data are stored in memory
·
“data transfer instructions”
–Transfer data between
memory and registers
–Load lw: move data from memory to a register
–Store st: move data from a register to
memory
·
Memory
is byte addressed ( 1 byte = 8 bit)
·
Code for byte addressable memory
Original
|
Updated
|
a[12]
= h + a[8]
assume
g, h = $s1, $s2
base
address = $s3
lw $t0 , 8($s3)
add $s1, $s2, $t0
sw 12($s3).
$s1
|
a[12]
= h + a[8]
assume
g, h = $s1, $s2
base
address = $s3, word data
lw $t0, 32
($s3)
add
$s1, $s2, $t0
sw 48($s3).
$s1
|
iii) Immediate Operands or Constant
·
Small constants used frequently
e.g., A = A + 5;
B = B + 1;
·
Solutions? Why not?
– put 'typical constants' in memory and load them
– create hard-wired registers (like $zero) for
constants
·
MIPS Instructions:
~ addi $29, $29, 4
~ ori $29, $29, 4
why only
“addi” and no “subi”
– use a negative
constants eg :
addi $s2. $s1, -1
·
Design Principle: Make the common case fast
KU MAN YI B031210161
0 comments:
Post a Comment