MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.
-
Upload
lorin-newman -
Category
Documents
-
view
227 -
download
0
description
Transcript of MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.
![Page 1: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/1.jpg)
MIPS Instruction Set Architecture
Prof. SirerCS 316
Cornell University
![Page 2: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/2.jpg)
InstructionsLoad/store architecture Data must be in registers to be operated on Keeps hardware simple
Emphasis on efficient implementationInteger data types: byte: 8 bits half-words: 16 bits words: 32 bits
MIPS supports signed and unsigned data types
![Page 3: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/3.jpg)
MIPS Instruction TypesArithmetic/Logical
three operands: result + two sources operands: registers, 16-bit immediates signed and unsigned versions
Memory Access load/store between registers and memory half-word and byte operations
Control flow conditional branches: pc-relative addresses jumps: fixed offsets
![Page 4: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/4.jpg)
Arithmetic Instructions (1)
if op == 0 && func == 0x21 R[rd] = R[rs] + R[rt]
if op == 0 && func == 0x23 R[rd] = R[rs] - R[rt]
if op == 0 && func == 0x25 R[rd] = R[rs] | R[rt]
funcshamtrdrtrsop6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
ADD rs, rt, rdADDU rs, rt, rdAND rs, rt, rdOR rs, rt, rdNOR rs, rt, rd
![Page 5: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/5.jpg)
Arithmetic Ops
memory
inst
32
pc
2
00
new pccalculation
register file
control
5 5 5
alu
![Page 6: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/6.jpg)
Arithmetic Instructions (2)
if op == 8 R[rd] = R[rs] + sign_extend(immediate)
if op == 12 R[rd] = R[rs] & immediate
immediaterdrsop6 bits 5 bits 5 bits 16 bits
ADDI rs, rt, valADDIU rs, rt, valANDI rs, rt, valORI rs, rt, val
![Page 7: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/7.jpg)
Sign ExtensionOften need to convert a small (8-bit or 16-bit) signed value to a larger (16-bit or 32-bit) signed value “1” in 8 bits: 00000001 “1” in 16 bits: 0000000000000001 “-1” in 8 bits: 11111111 “-1” in 16 bits:1111111111111111
Conversion from small to larger numbers involves replicating the sign bit
![Page 8: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/8.jpg)
Arithmetic Ops with Immediates
memory
inst
32
pc
2
00
new pccalculation
register file
control
5 5 5
alu
mux
sign extend16
32
![Page 9: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/9.jpg)
Memory Operations
lb, lbu, lh, lhu, lwsb, sh, swExamples lw r3, 0(r4) int array[32]; x = array[0] lw r3, 16(r4) int array[32]; x = array[4]
immediatertrsop6 bits 5 bits 5 bits 16 bits
![Page 10: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/10.jpg)
Load
memory
inst
32
pc
2
00
new pccalculation
register file
control
5 5 5
alu
sign extend
1632
datamemory
addr d out
![Page 11: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/11.jpg)
Store
memory
inst
32
pc
2
00
new pccalculation
register file
control
5 5 5
alu
sign extend
1632
datamemory
addr d out
d in
![Page 12: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/12.jpg)
EndiannessTake a 32-bit hexadecimal value e.g. 0x01020304
Store the word at location 0x1000Read the byte at location 0x1000 What do you get?
Little endian
Big endian
04030201
01020304
0x1003 0x1002 0x1001 0x1000
0x1000 0x1001 0x1002 0x1003
![Page 13: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/13.jpg)
EndiannessThe way the bytes are ordered within a word generally does not matter, except when casting between integral data types
casting four bytes to an int casting two bytes to a short casting two shorts to an int
Such casting is typically required when sending data from one host to another networks use big-endian representation for
ints x86’s use little-endian representation for ints
![Page 14: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/14.jpg)
Control Flow (Absolute Jump)
j, jal Absolute addressingnew PC = high 4 bits of current PC || target || 00
Cannot jump from 0xffff000000000000 to 0x0000100000000000
Better to make all instructions fit in 32 bits than to support really large absolute jumps
Examples j L01 goto L01
targetop6 bits 26 bits
![Page 15: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/15.jpg)
Absolute Jump
memory
inst
32
pc
2
00
new pccalculation
register file
control
5 5 5
alu
sign extend
1632
datamemory
addr d out
d in
![Page 16: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/16.jpg)
Control Flow (Jump Register)
new PC = R[rs]
Can jump to any address stored in a register
func000 000 000 000 000
rsop6 bits 5 bits 15 bits 6 bits
![Page 17: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/17.jpg)
Jump Register
memory
inst
32
pc
2
00
new pccalculation
register file
control
5 5 5
alu
sign extend
1632
datamemory
addr d out
d in
![Page 18: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/18.jpg)
Control Flow (Branches)
Some branches depend on the relative values of two registersif op == 4 # BEQ if R[rs] == R[rt]
new PC = old PC + sign_extend(immediate << 2)BEQ, BNE
immediatertrsop6 bits 5 bits 5 bits 16 bits
![Page 19: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/19.jpg)
Branch
memory
inst
32
pc
2
00
new pccalculation
register file
control
5 5 5
alu
sign extend
1632
datamemory
addr d out
d in
=?
![Page 20: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/20.jpg)
Control Flow (Branches)
Some branches depend on the value of a single registerif op == 1 && subop == BLTZ if R[rs] < 0
new PC = old PC + sign_extend(immediate << 2)BGEZ, BGTZ, BLTZ, BLEZ
immediatesuboprsop6 bits 5 bits 5 bits 16 bits
![Page 21: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/21.jpg)
Branch
memory
inst
32
pc
2
00
new pccalculation
register file
control
5 5 5
alu
sign extend
1632
datamemory
addr d out
d in
=? <=0?
![Page 22: MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.](https://reader034.fdocuments.in/reader034/viewer/2022050902/5a4d1b6c7f8b9ab0599b3ab5/html5/thumbnails/22.jpg)
SummaryFull-blown processor
Next time: we’ll make it go faster