COE480 Lecture1
COE480 Lecture1
Computer Architecture
Instruction Set Architecture
MIPS
Lecture 1
1
Instruction Set
3
MIPS reference data
• You should all have the MIPS reference data
• First page:
(1) Core instruction set
Name: The name of the instruction, EX: ADD
Format: Can be R, I or J (See BASIC INSTRUCTION FORMATS)
Operation: What the instruction do.
Opcode: Operation code, the first 6 bits of the instruction [31..26]
Function: the last 6 bits of the instruction [5..0]
Keep these two pages with you ALL THE TIME 4
MIPS Operations/Operands
• All instructions are 32 bit length
• MIPS operations
– Arithmetic operations : add, sub, …
– Logical operations: and, or,…
– Shift operations : sll, srl Shift left or right logical
– Compare operations: compare two operand and perform an action, slt...
– Load/stores: to transfer data from/to memory, lw, sw,…
– Branch/jump operations: beq, bne, j, jr, …
• MIPS operands
– General-purpose registers: available registers used to store data
(first page of the MIPS reference data)
– Memory location: the memory address is stored in a register
– Immediate value: value in decimal
5
MIPS Arithmetic TYPE R
rd rs rt
• <op> <rdestination> <rsource1> <rsource2>
• Examples
– add $t0, $s0, $s2 # $t0 = $s0 + $s2
rd = rs + rt
rd : the register $t0 (number 8)
add $8, $16, $18
– sub $s0, $t0, $t1 # $s0 = $t0 – $t1
6
Register Operands in MIPS
• Assembler names
– $t0, $t1, …, $t9 for temporary values
– $s0, $s1, …, $s7 for saved variables
7
Registers
32 bits 32 bits 32 bits
8
General-Purpose Registers
• GPR: all can be used as operands in instructions
9
General-Purpose Registers
10
Instruction Encoding
• Instructions are encoded in binary numbers
– Assembler translates assembly programs into binary numbers
– Machine decodes binary numbers to figure out what the instruction is
11
Instruction Encoding
• Instructions are encoded in binary numbers
– Assembler translates assembly programs into binary numbers
– Machine decodes binary numbers to figure out what the instruction is
12
Instruction Encoding
• MIPS has several instruction formats
– R-format: arithmetic instructions
– I-format: transfer/branch/immediate format
– J-format: jump instruction format
13
MIPS Instruction Formats
Name Fields Comments
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits All MIPS instructions 32 bits
14
R-Format Instructions
• Define “fields” of the following number of bits
each: 6 + 5 + 5 + 5 + 5 + 6 = 32
6 5 5 5 5 6
• MIPS Instruction:
<op> <rd> <rs> <r t>
rs = 9
rt = 10
rd = 8
16
R-Format Example
• MIPS Instruction:
What is 01098022? 0000 0001 0000 1001 1000 0000 0010 0010
17
R-Format Example
• MIPS Instruction:
What is 01098022? 0000 0001 0000 1001 1000 0000 0010 0010
20
I-Format Example
• MIPS Instruction:
addi $8,$9,7
opcode rs rt immediate
8
001000 01001 01000 0000000000000111
• MIPS Instruction:
What is 2230FFFE? 0010 0010 0011 0000 1111 1111 1111 1110
opcode rs rt immediate
001000 10001 10000 1111111111111110
8 17 16 -2
23
Exercise
Find the MIPS instructions:
0x02324020
0x11200002
0x014b482a
0x2129ffff
24
Solution
Find the MIPS instructions:
25
Logic Instructions
Name Fields Comments
• Examples
– and $t0, $s0, $s2 # $t0 = $s0 ^ $s2
– or $s0, $t0, $t1 # $s0 = $t0 ᵥ $t1
– nor $s0, $t0, $t1 # $s0 = ~($t0 ᵥ $t1)
– xor $s0, $t0, $t1 # $s0 = $t0 $t1
26
Logic Instructions: Example
.text $t0
addi $t0,$0,0x32
addi $t1,$0,0x777
$t1
and $t2,$t1,$t0 $t2
27
Long Immediate
• Sometimes we need a long immediate, e.g., 32 bits
• This value cannot be loaded using one instruction
• Immediate is 16 bits.
• MIPS requires that we use two instructions
• Example: to load $t0 with 0xaa55cc33
– lui $t0, 0xaa55 (Load upper immediate)
$t0 1010101001010101 0000000000000000
28
Loading a memory address
29