















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















-^
3
Register-to-register arithmetic instructions use the R-type format.
op
rs
rt
rd
shamt
func
6 bits
5 bits
5 bits
5 bits
5 bits
6 bits
This format includes six different fields.^ —
op is an operation code or opcode that selects a specificoperation.
p —
rs and rt are the first and second source registers. —
rd is the destination register. —
shamt is only used for shift instructions. —
func is used together with op to select an arithmeticinstruction.
-^
The green card in the textbook lists opcodes and function codesfor all of the MIPS instructions
5
for
all of the MIPS instructions.
op
rs
rt
rd
shamt
func
6 bits
5 bits
5 bits
5 bits
5 bits
6 bits
000000
01001
01010
10100
00000
100000
6
Load, store, branch, and immediate instructions all use the I-typeformatformat.
op
rs
rt
address
6 bits
5 bits
5 bits
16 bits
-^
For uniformity, op, rs and rt are in the same positions as in the R-format.
-^
The meaning of the register fields depends on the exact instruction
-^
The meaning of the register fields depends on the exact instruction.^ —
rs is a source register—an address for loads and stores, or anoperand for branch and immediate arithmetic instructions. —
rt is a source register for branches and stores, but a destination
i^
f^
h^
h^
I^
i^
i
register for the other I-type instructions.
-^
The address is a 16-bit signed two’s-complement value.– It can range from -32,768 to +32,767.– But that’s not always enough!
8
-^
But
that s not always enough!
op
rs
rt
address
6 bits
5 bits
5 bits
16 bits
100011
11101
01000
1111 1111 1111 1100
101011
11101
00100
0000 0000 0001 0000
001000
01001
10100
1111 1111 1111 1111
9
-^
-^
lui
$at,
0x
#^
0x1001 0000
lw
$t1,
0x0004($at)
#^
Read
from
Mem[0x1001 0004]
11
-^
12
Empirical studies of real programs show that most branches go
l^
h^
32 767 i
i^
b^
h
to targets less than 32,767 instructions away—branches aremostly used in loops and conditionals, and programmers aretaught to make code bodies short.
-^
If you do need to branch further you can use a jump with a
-^
If you do need to branch further, you can use a jump with abranch. For example, if “Far” is very far away, then the effect of:
beq
$s0, $s1, Far
...
can be simulated with the following actual code.
bne
$s0, $s1, Next
j^
Far
Next:
...
Again, the MIPS designers have taken care of the common casefi
14
first.
Finally, the jump instruction uses the J-type instruction format.
op
address
6 bits
26 bits
-^
The jump instruction contains a
word
address, not an offset
word addresses must be divisible by four.S
i^
t^
d^
f^
i^
“j^
t^
dd
4000 ” it’
h t
j^
t
say “jump to instruction 1000.”
28
.
y^
p^
g
-^
For even longer jumps, the jump register, or jr, instruction can beused.
15
jr
$ra
#^
Jump to 32-bit address
in
register
$ra
17
hex
hex
hex
hex
hex
hex
hex
ten
hex
18
-^
Select the opcode (first 6 bits) to determine the format:
-^
Look at opcode: 0 means R-Format, 2 or 3 mean J-Format, otherwise I-Format
-^
Next step: separation of fields R R I R I J Format:
-^
Next step: separation of fields R R I R I J Format:
20
-^
Fields separated based on format/opcode:
-^
Next step: translate (“disassemble”) MIPS assembly instructions RR I R I J Format:
21