COA Module1 MIPS
COA Module1 MIPS
1
7/23/24
Introduction
• Computer Organization:
• Design of the components and functional blocks using which computer
systems are built.
• Analogy: civil engineer’s task during building construction (cement, bricks,
iron rods, and other building materials).
• Computer Architecture:
• How to integrate the components to build a computer system to achieve a
desired level of performance.
• Analogy: architect’s task during the planning of a building (overall layout,
floorplan, etc.).
2
7/23/24
Historical Perspective
PASCALINE (1642)
• Mechanical calculator invented by B.
Pascal.
• Could add and subtract two numbers
directly, and multiply and divide by
repetition.
3
7/23/24
Babbage Engine
• First automatic computing engine
was designed by Charles Babbage
in the 19th century, but he could
not build it.
• The first complete Babbage
engine was built in 2002, 153
years after it was designed.
• 8000 parts.
• Weighed 5 tons.
• 11 feet in length.
ENIAC
(Electrical Numerical
Integrator and
Calculator)
4
7/23/24
Harvard Mark 1
• Built at the University of
Harvard in 1944, with support
from IBM.
• Used mechanical relays
(switches) to represent data.
• It weighed 35 tons, and
required 500 miles of wiring.
IBM System/360
• Very popular mainframe
computer of the 60s and
70s.
• Introduced many advanced
architectural concepts that
appeared in
microprocessors several
decades later.
10
10
5
7/23/24
Intel Core i7
• A modern processor chip, that comes in
dual-core, quad-core and 6-core
variants.
• 64-bit processor that comes with
various microarchitectures like Haswell,
Nehalem, Sandy Bridge, etc.
11
11
Sixth (1990 onwards) ULSI, scalable architecture, post- Massively parallel processors
CMOS technologies Pentium, SUN Ultra workstations
12
12
6
7/23/24
Evolution of the
Types of Computer
Systems
The future?
• Large-scale IoT based
systems.
• Wearable computing.
• Intelligent objects.
13
13
Evolution of
PC form
factors over
the years
14
14
7
7/23/24
Inside a laptop
• Miniaturization in feature sizes of
all parts.
• Hard drive getting replaced by
flash-based memory devices.
• Cooling is a major issue.
15
15
Moore’s Law
16
16
8
7/23/24
17
17
18
18
9
7/23/24
19
19
20
20
10
7/23/24
21
21
22
22
11
7/23/24
23
23
24
24
12
7/23/24
Input Unit
25
25
26
26
13
7/23/24
Output Unit
27
27
28
28
14
7/23/24
29
29
• The MIPS32 ISA has the following CPU registers that are visible to the
machine/assembly language programmer.
a) 32, 32-bit general purpose registers (GPRs), R0 to R31.
b) A special-purpose 32-bit program counter (PC).
• Points to the next instruction in memory to be fetched and executed.
• Not directly visible to the programmer.
• Affected only indirectly by certain instructions (like branch, call, etc.)
c) A pair of 32-bit special-purpose registers HI and LO, which are used to hold
the results of multiply, divide, and multiply-accumulate instructions.
30
30
15
7/23/24
31 0 31 0
R0 HI Two of the GPRs have assigned functions:
R1 LO
a) R0 is hard-wired to a value of zero.
R2 • Can be used as a source when a zero value is
R3 31 0 needed.
R4 PC b) R31 is used to store the return address
..
R5 Special Purpose Registers when a function call is made.
• Used by the jump-and-link and branch-and-
. link instructions like JAL, BLTZAL, BGEZAL, etc.
• Can also be used as a normal register.
R30
R31
General Purpose Registers
31
31
Some Examples
JR R31
32
32
16
7/23/24
33
33
34
34
17
7/23/24
35
35
36
36
18
7/23/24
37
37
38
38
19
7/23/24
39
39
40
40
20
7/23/24
41
41
42
42
21
7/23/24
43
43
44
44
22
7/23/24
45
45
46
46
23
7/23/24
47
47
48
48
24
7/23/24
49
49
50
50
25
7/23/24
51
51
52
52
26
7/23/24
53
53
• The multiply and divide instructions produce twice as many result bits.
• When two 32-bit numbers are multiplied, we get a 64-bit product.
• After division, we get a 32-bit quotient and a 32-bit remainder.
• Results are produced in the HI and LO register pair.
• For multiplication, the low half of the product is loaded into LO, while the higher half
in HI.
• Multiply-Add and Multiply-Subtract produce a 64-bit product, and adds or subtracts
the product from the concatenated value of HI and LO.
• Divide produces a quotient that is loaded into LO and a remainder that is loaded into
HI.
54
54
27
7/23/24
• Only exception is the MUL instruction, which delivers the lower half
of the result directly to a GPR.
• Useful is situations where the product is expected to fit in 32 bits.
55
55
56
56
28
7/23/24
57
57
58
58
29
7/23/24
59
59
60
60
30
7/23/24
61
61
62
62
31
7/23/24
63
63
64
64
32
7/23/24
65
65
66
66
33
7/23/24
67
67
68
68
34
7/23/24
C Code
if (x != y) z = x – y;
else z = x + y;
$s0 loaded with x
$s1 loaded with y
MIPS32 Code z ß $s3
beq $s0, $s1, Lab1
sub $s3, $s0, $s1
j Lab2
Lab1: add $s3, $s0, $s1
Lab2: ….
69
69
70
70
35
7/23/24
71
71
72
72
36
7/23/24
73
73
74
74
37
7/23/24
75
75
A Simple Function
C Function MIPS32 Code
swap (int A[], int k) swap: muli $t0, $s0, 4
{ add $t0, $s1, $t0 $s0 loaded with index k
int temp; lw $t1, 0($t0) $s1 loaded with base address
temp = A[k]; lw $t2, 4($t0) of A
A[k] = A[k+1]; sw $t2, 0($t0)
Address of A[k] = $s1 + 4 * $s0
A[k+1] = temp; sw $t1, 4($t0)
} jr $ra
76
76
38
7/23/24
77
77
.text
main:
la $a0 , num_msg # loads address of entering number msg in $a0
li $v0 , 4 # loads print string syscall command
syscall # makes a system call
loop:
bge $t1 , $t0 , endloop # if k >= num then we are done
rem $t3 , $t0 , $t1 # load the remainder , num % k into $t3
beqz $t3 , adder # branch to adder
78
78
39
7/23/24
loop1:
add $t1 , $t1 , 1 # increment the value of k by 1, i.e k++
b loop # unconditional branching to loop
adder:
add $t2 , $t2 , $t1 # add the value of k to the sum
b loop1 # unconditional branching to lab
endloop:
beq $t2 , $t0 , perfect # after the loop, if the value of sum = number entered, the number is a perfect number
bne $t2 , $t0 , notperfect # if the value of sum is not equal to the number , the number is not a perfect number
perfect:
la $a0 , success_msg # loads address of success msg in $a0
li $v0 , 4 # loads print string syscall command
syscall # makes a system call
b exit # unconditional branching to exit label
notperfect:
la $a0 , failure_msg # loads address of failure msg in $a0
li $v0 , 4 # loads print string syscall command
syscall # makes a system call
b exit # unconditional branching to exit label
79
40