Lecture 06 - Slides - Computer Technology and Instructions
Lecture 06 - Slides - Computer Technology and Instructions
Lecture 06 - Slides - Computer Technology and Instructions
and Instructions
Sam Amiri
The Computer Revolution
2
Classes of Computers
Desktop computers
General purpose, variety of software
Subject to cost/performance tradeoff
Server computers
Network based
High capacity, performance, reliability
Range from small servers to building sized
Embedded computers
Hidden as components of systems
Stringent power/performance/cost constraints
3
The Processor Market
4
Understanding Performance
Algorithm
Determines number of operations executed
5
Below Your Program
Application software
Written in high-level language
System software
Compiler: translates HLL code to machine code
Operating System: service code
Handling input/output
Managing memory and storage
Scheduling tasks & sharing resources
Hardware
Processor, memory, I/O controllers
6
Levels of Program Code
High-level language
Level of abstraction closer to problem domain
Provides for productivity and portability
Assembly language
Textual representation of instructions
Hardware representation
Binary digits (bits)
Encoded instructions and data
7
Components of a Computer
Input/output includes
User-interface devices
Display, keyboard, mouse
Storage devices
Hard disk, CD/DVD, flash
Network adapters
For communicating with other computers
8
Inside the Processor (CPU)
Cache memory
Small fast SRAM memory for immediate access to data
9
Abstractions
Implementation
The details underlying and interface
10
Defining Performance
Response time
How long it takes to do a task
Throughput
Total work done per unit time
e.g., tasks/transactions/… per hour
Elapsed time
Total response time, including all aspects
Processing, I/O, OS overhead, idle time
Determines system performance
CPU time
Time spent processing a given job
Discounts I/O time, other jobs’ shares
Comprises user CPU time and system CPU time
Different programs are affected differently by CPU and system performance
12
CPU Clocking
Performance improved by
Reducing number of clock cycles
Increasing clock rate
Hardware designer must often trade off clock rate against cycle count
14
Instruction Count and CPI
n
Clock Cycles = ∑ (CPIi × Instruction Count i )
i=1
Clock Cycles n
Instruction Count i
CPI = = ∑ CPIi ×
Instruction Count i=1 Instruction Count
Relative frequency
16
CPI Example
Sequence 1: IC = 5 Sequence 2: IC = 6
Clock Cycles Clock Cycles
= 2×1 + 1×2 + 2×3 = 4×1 + 1×2 + 1×3
= 10 =9
Avg. CPI = 10/5 = 2.0 Avg. CPI = 9/6 = 1.5
17
Performance Summary
Performance depends on
Algorithm: affects IC, possibly CPI
Programming language: affects IC, CPI
Compiler: affects IC, CPI
Instruction set architecture: affects IC, CPI, Tc
18
Power Trends
Multicore microprocessors
More than one processor per chip
21
Instruction Set
22
The MIPS Instruction Set
23
Arithmetic Operations
add a, b, c # a gets b + c
24
Arithmetic Example
C code:
f = (g + h) - (i + j);
25
Register Operands
26
Register Operand Example
C code:
f = (g + h) - (i + j);
f, …, j in $s0, …, $s4
27
Memory Operands
28
Memory Operand Example 1
C code:
g = h + A[8];
g in $s1, h in $s2, base address of A in $s3
C code:
A[12] = h + A[8];
h in $s2, base address of A in $s3
31
Immediate Operands
32
The Constant Zero
33
MIPS R-format Instructions
op rs rt rd shamt funct
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
Instruction fields
op: operation code (opcode)
rs: first source register number
rt: second source register number
rd: destination register number
shamt: shift amount (00000 for now)
funct: function code (extends opcode)
34
R-format Example
op rs rt rd shamt funct
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
0 17 18 8 0 32
000000100011001001000000001000002 = 0232402016 35
MIPS I-format Instructions
op rs rt constant or address
6 bits 5 bits 5 bits 16 bits
36
Logical Operations
37
Shift Operations
op rs rt rd shamt funct
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
38
NOT Operations
39
Conditional Operations
40
Compiling If Statements
C code:
if (i==j) f = g+h;
else f = g-h;
f, g, … in $s0, $s1, …
Compiled MIPS code:
bne $s3, $s4, Else
add $s0, $s1, $s2
j Exit
Else: sub $s0, $s1, $s2
Exit: …
Assembler calculates addresses
41
More Conditional Operations
op rs rt constant or address
6 bits 5 bits 5 bits 16 bits
PC-relative addressing
Target address = PC + offset × 4
PC already incremented by 4 by this time
43
Jump Addressing
op address
6 bits 26 bits
44
Addressing Mode Summary
45
Thank You!
46