MIPS
7.1 THE ORGANIZATION OF COMPUTER
Computer
contain five basic main component which are input, output, memory, datapath,
and control that connected through system bus that act as the communication
channel for all components.
System Bus
7.2
MICROPROCESSOR OPERATIONS
There are three basic steps that most processors will repeat in order to execute one machine instruction. Process of completing these three steps is call a machine cycle.
7.3
INTRODUCTION TO MIPS R2000
What is MIPS?
- Reduced instruction set
computer (RISC) instruction set architecture.
- Also known as Microprocessor
without Interlocked Pipeline Stages.
What is first MIPS model?
- R2000, introduced in 1985
- Contain 32-bit general purpose registers
- No condition code registers which designers
considered it a potential bottleneck
MIPS R2000 Architecture
7.3.1
MEMORY ALLOCATION
7.3.2
DATA ALIGNMENT
TYPE
|
SIZE(BINARY)
|
SIZE(HEXADECIMAL)
|
Byte
|
8 bits
e.g. 00100101
|
2 bits
e.g. 4B
|
Word
|
4 bytes, 32 bits
e.g. 0101001000101…..
|
8 bits
e.g. 54721EFG
|
Double Word
|
8 bytes, 64 bits
e.g. 10000000000000……..
|
16 bits
e.g. 55124257754BCFEA
|
Table 1: MIPS Data Sizes
Double Word
|
|||||||
Word
|
Word
|
||||||
Half Word
|
Half Word
|
Half Word
|
Half Word
|
||||
Byte
|
Byte
|
Byte
|
Byte
|
Byte
|
Byte
|
Byte
|
Byte
|
Table
2: Data Alignment
7.3.3
REGISTERS
Types
Of Registers
Register
Name (Mnemonic Name)
|
Register
Name
|
Usage
|
$zero
|
$0
|
Constant 0
|
$at
|
$1
|
Assembler Temporary (reserved)
|
$v0-$v1
|
$2-$3
|
Expression evaluation and result of a
subroutine
|
$a0-$a3
|
$4-$7
|
Arguments to a subroutine
|
$t0-$t7
|
$8-$15
|
Temporary (not preserved across a
function call)
|
$s0-$s7
|
$16-$23
|
Saved Temporary (preserved across a
function call)
|
$t8-$t9
|
$24-$25
|
More Temporary
|
$gp
|
$28
|
Global Pointer (preserved on call)
|
$sp
|
$29
|
Stack Pointer (preserved on call)
|
$fp
|
$30
|
Frame Pointer (preserved on call)
|
$ra
|
$31
|
Return Address (automatically used in
some instruction)
|
Table
3: MIPS Register Conventions
Register
Name
|
Register
Number
|
Usage
|
BadVAddr
|
8
|
Memory address at which address
exception occurred
|
Status
|
12
|
Interrupt mask and enable bits
|
Cause
|
13
|
Exception type and pending interrupt
bits
|
EPC
|
14
|
Address of instruction that caused
exception
|
Table
4: Trap Registers
Number
|
Name
|
Cause
of Exception
|
0
|
Int
|
Interrupt (hardware)
|
4
|
AdEL
|
Address error exception (load or
instruction fetch)
|
5
|
AdES
|
Address error exception (stores)
|
6
|
IBE
|
Bus error on instruction fetch
|
7
|
DBUS
|
Bus error on data load or store
|
8
|
SYSCALL
|
Syscall exception
|
9
|
BKPT
|
Breakpoint exception
|
10
|
RI
|
Reserved instruction exception
|
12
|
OVF
|
Arithmetic overflow exception
|
13
|
Tr
|
Trap
|
Table
5: Exception Code Register
7.3.4
SYSTEM CALL
For
MIPS architecture, SPIM simulator provides an “exception handler” that
stimulates a tiny operating system that can do input from the keyboard and
output to the monitor. Assembly programs request a service by loading the
system call (syscal) instruction.
Service
|
System
Call Code
|
Arguments
|
Result
|
Print_int
|
1
|
$a0 = integer
|
|
Print_float
|
2
|
$f12 = float
|
|
Print_double
|
3
|
$f12 = double
|
|
Print_string
|
4
|
$a0 = string
|
|
Read_int
|
5
|
$v0 = integer
|
|
Read_float
|
6
|
$f0 = float
|
|
Read_double
|
7
|
$f0 = double
|
|
Read_string
|
8
|
$a0 = buffer
$a1 = length
|
|
Sbrk (allocate memory)
|
9
|
$a0 = amount
|
$v0 = address
|
Exit
|
10
|
||
Print_char
|
11
|
$a0 = char
|
|
Read_char
|
12
|
$v0 = char
|
Table
6: System Call Function
Diagram
1: Example to exit program
7.3.5
MIPS ASSEMBLY LANGUAGES PROGRAM FORMAT
Two types of statements of MIPS
assembler program:
1. Assembler
directive that tells the assembler how to translate a program but cannot be
translated into machine code.
2. Executable
instruction where upon execution will be translated into machine code.
Sometimes can be referred as program code.
MIPS PROGRAM FORMAT
Column 1
|
Column 2
|
Column 3
|
Column 4
|
Label Opcode Operand Commend
- used to make a - field that denoted - contains registers, - anything that
specific point in the basic operation shift amount, label follows # on a line.
program code. and format of an to jump into and
- when instruction of instruction. constant or address.
branch or jump call - use mnemonic
for a specific label language for purpose
the program will be of simplicity and
execute from the readability.
point of the label
The
name of file for MIPS program structure should end in suffix .asm. There are
two part of MIPS program structures which are:
1.
Data declaration is
placed in section of program identified with assembler directive .data.
-
Variables names used in
the program are declared with storage allocation set in main memory.
-
Revise data
representation sub-chapter to identify which data types to be used.
2.
Code is place in
section of program identified with assembler directive .text.
-
The section contains
program codes
-
Starting point for code
execution is from a certain label at the left column where the programmers
usually use main:
-
Ending point of main
code should use exit system call
7.4 DATA REPRESENTATION
7.4.1
CHARACTER REPRESENTATION
Dec
|
Hex
|
Char
|
Dec
|
Hex
|
Char
|
Dec
|
Hex
|
Char
|
32
|
20
|
SPACE
|
33
|
21
|
!
|
34
|
22
|
“
|
35
|
23
|
#
|
36
|
24
|
$
|
37
|
25
|
%
|
38
|
26
|
&
|
39
|
27
|
‘
|
40
|
28
|
(
|
41
|
29
|
)
|
42
|
2A
|
*
|
43
|
2B
|
+
|
44
|
2C
|
,
|
45
|
2D
|
-
|
46
|
2E
|
.
|
47
|
2F
|
/
|
48
|
30
|
0
|
49
|
31
|
1
|
50
|
32
|
2
|
51
|
33
|
3
|
52
|
34
|
4
|
53
|
35
|
5
|
554
|
36
|
6
|
55
|
37
|
7
|
56
|
38
|
8
|
57
|
39
|
9
|
58
|
3A
|
:
|
59
|
3B
|
;
|
60
|
3C
|
<
|
61
|
3D
|
=
|
62
|
3E
|
>
|
63
|
3F
|
?
|
64
|
40
|
@
|
65
|
41
|
A
|
66
|
42
|
B
|
67
|
43
|
C
|
68
|
44
|
D
|
69
|
45
|
E
|
70
|
46
|
F
|
71
|
47
|
G
|
72
|
48
|
H
|
73
|
49
|
I
|
74
|
4A
|
J
|
75
|
4B
|
K
|
76
|
4C
|
L
|
77
|
4D
|
M
|
78
|
4E
|
N
|
79
|
4F
|
O
|
80
|
50
|
P
|
81
|
51
|
Q
|
82
|
52
|
R
|
83
|
53
|
S
|
84
|
54
|
T
|
85
|
55
|
U
|
86
|
56
|
V
|
87
|
57
|
W
|
88
|
58
|
X
|
89
|
59
|
Y
|
90
|
5A
|
Z
|
91
|
5B
|
[
|
92
|
5C
|
\
|
93
|
5D
|
]
|
94
|
5E
|
^
|
95
|
5F
|
_
|
96
|
60
|
`
|
97
|
61
|
a
|
98
|
62
|
b
|
99
|
63
|
c
|
100
|
64
|
d
|
101
|
65
|
e
|
102
|
66
|
f
|
103
|
67
|
g
|
104
|
68
|
h
|
105
|
69
|
i
|
106
|
6A
|
j
|
107
|
6B
|
k
|
108
|
6C
|
l
|
109
|
6D
|
m
|
110
|
6E
|
n
|
111
|
6F
|
o
|
112
|
70
|
p
|
113
|
71
|
q
|
114
|
72
|
r
|
115
|
73
|
s
|
116
|
74
|
t
|
117
|
75
|
u
|
118
|
76
|
v
|
119
|
77
|
w
|
120
|
78
|
x
|
121
|
79
|
y
|
122
|
7A
|
z
|
123
|
7B
|
{
|
124
|
7C
|
|
|
125
|
7D
|
}
|
126
|
7E
|
~
|
127
|
7F
|
DEL
|
Here
is a section of an assembly language program:
.asciiz “XYZ xyz”
Here
are the bit pattern that the assembler will produce in object module:
58
59 5A 20 78 79 7A 00
7.4.2
NUMBER REPRESENTATION
Although
computers operate on binary numbers, in MIPS number is represented in decimal
or hexadecimal system. When you need to insert number into a register, you have
to remember what kind of number system that you want to write in the program.
For example, to load number 16 into register $15, we have two ways to
represented decimal 16 in MIPS:
1.
Ori $5, $0, 16 #load number 16 into
register $5
2. Ori
$5, $0, 0x10 #load number 16 into register $5
by : MUHAMMAD HAFIZIN ZARIF BIN MOHD ZAHID ( B031410218 )
No comments:
Post a Comment