0% found this document useful (0 votes)
10 views13 pages

Lec 03

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views13 pages

Lec 03

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

CS222: MIPS Instruction Set

Dr. A. Sahu
Dept of Comp. Sc. & Engg.
Indian Institute of Technology Guwahati

1
Outline
• Introduction to MIPS Instruction Set
• MIPS Arithmetic's
• Register Vs Memory, Registers Name
• Byte Ordering
Instructions
• Language
g g of the Machine
• Primitive compared to HLLs
• Easily
l interpreted
d by
b hardware
h d
Instruction set design goals
• Maximize performance
• Minimize cost,
• Reduce
Red e design
desi n time
Type of Instructions

• Instructions for arithmetic


• Instructions to move data
• Instructions for decision making
• Handling constant operands
Example: Instruction Set Architecture
MIPS
• Representative of architectures developed since
the 1980's
• Used by NEC, Nintendo, Silicon Graphics, Sony
• Real architecture but easy to understand

MIPS: Microprocessor
p without Interlocked
Pipeline Stages : ISA
MIPS: Millions Instructions Per Sec:
Measure
MIPS Arithmetic
• All instructions have 3 operands
• Operand order is fixed (destination first)

Example:
C code: A=B+C
MIPS code: add $s0, $s1, $s2

(associated with variables by compiler)


MIPS Arithmetic
• Simplicity favors regularity
• Operands must be registers, only 32 registers
provided (smaller is faster)
• Expressions need to be broken
C code MIPS code
A = B + C + D; add $t0, $s1, $s2
E = F ‐ A; add $s0, $t0, $s3
sub $
$s4,, $s5,
$ , $s0
$
Registers vs. Memory
• Scalars mapped to registers
• Structures, arrays etc in memory

C t l
Control I
Input
t

Memory
Datapath Output

Processor I/O
/
Memory Organization
0 8 bits of data

1 8 bits of data
• Viewed as a large, single‐
dimension array,y, with an 2 8 bits of data

address. 3 8 bits of data


• A memory address is an 4 8 bits of data
index into the array
5 8 bits of data
• "Byte
Byte addressing
addressing" means
8 bits of data
that the index points to a 6

byte of memory
memory. ...
Register Names and Purpose
Register
Name Usage
number
$zero 0 the constant value 0
$v0-$v1
$ $ 2-3 values for results
$a0-$a3 4-7 arguments
$t0-$t7 8-15 temporaries
$s0-$s7 16-23 saved
$t8-$t9 24-25 more temporaries
$
$gp 28 global
l b l pointer
i t
$sp 29 stack pointer
$fp 30 frame pointer
$ra 31 return address
Words and Bytes

• 232 bytes : byte addresses from 0 to 232‐1


• 230 words : byte
y addresses 0,, 4,, 8,, ... 232‐4
Big endian byte order 0 1 2 3
4 5 6 7
Little endian byte 3 2 1 0
order
d 7 6 5 4

3 2 1 0
Non aligned word
Non‐aligned ord 7 6 5 4
Instructions to access memory
• Load and store instructions
• Example:

C code: A[8] = h + A[8];

MIPS code: lw $t0, 32($s3)


add $t0
$t0, $s2,
$s2 $t0
sw $t0, 32($s3)
A simple example
• What does this code do?
swap(int v[ ],int k){
i t temp;
int t
temp = v[k] swap:
[ ] = v[k+1];
v[k] [ ] muli $2
$2, $5 4
$5,4
v[k+1] = temp; add $2, $4,$2
} lw $15, 0($2)
lw $16 4($2)
$16,
sw $16, 0($2)
sw $15, 4($2)
jr
j $31

You might also like