CSE 2021: Computer Organization
Transcript of CSE 2021: Computer Organization
5/10/2012
1
CSE 2021: Computer Organization
Lecture-1(a): Introduction
Shakil M. Khan (adapted from Profs. Roumani & Asif)
The Computer Revolution
• Progress in computer technology – underpinned by Moore’s Law
• Makes novel applications feasible – cell phones
– World Wide Web, search engines
– computers in automobiles
– computers in surgeries
– human genome project
• Computers are pervasive, ubiquitous
CSE-2021 May-10-2012 2
©Intel Corporation
Future Applications of Computer (1)
CSE-2021 May-10-2012 3
© A
ssocia
tion f
or
the A
dvancem
ent
of
AI
(AAAI)
Future Applications of Computer (2)
• Virtual Reality: design virtual immersive environments to simulate reality
CSE-2021 May-10-2012 4
Future Applications of Computer (3)
• Autonomous driverless cars
– knows speed limits, maps, traffic patterns
– safer: can react more quickly than humans
– travelled 1600 KMs on major CA roads w/o a human touching the controls at all!
CSE-2021 May-10-2012 5
Future Applications of Computer (4)
• Analyze large biological (genetic) data sets to understand and control human evolution
CSE-2021 May-10-2012 6
5/10/2012
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
CSE-2021 May-10-2012 7
Server Room in CERN
The Processor Market
CSE-2021 May-10-2012 8
Technology Trends
• Electronics technology continues to evolve
– increased capacity and performance
– reduced cost
CSE-2021 May-10-2012 9
Year Technology Relative performance/cost
1951 Vacuum tube 1
1965 Transistor 35
1975 Integrated circuit (IC) 900
1995 Very large scale IC (VLSI) 2,400,000
2005 Ultra large scale IC 6,200,000,000
DRAM capacity
Moore’s Law
CSE-2021 May-10-2012 10
DRAM capacity
© Robert Holmgren
…and the Revolution Continues
• (Patterson & Hennessy, 1998)
“Had the transportation industry kept pace with the computer
industry, today we could travel New York to London in a second
for about 50 cents !”
CSE-2021 May-10-2012 11
So, what is CSE 2021 about?
• …explains what’s inside a computer, describing its hardware (HW), and introducing the assembly language representation of a program compiled from a high level language
• You will learn:
– how computers work?
– how to analyze their performance?
– what are the issues affecting modern processors (e.g. caches, pipelines)?
CSE-2021 May-10-2012 12
5/10/2012
3
Expected Learning Outcomes
• After completing this course, can:
– translate given high-level OOP to assembly/machine language
– build an ALU out of basic building blocks such as gates and flip-flops
– assess end-to-end performance of a given computer system, from statements to gates
• Why do I learn this stuff?
– to build better software people use (improved performance)
– to offer expert advice in applications, purchasing, etc.
CSE-2021 May-10-2012 13
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
CSE-2021 May-10-2012 14
• Communication takes place in terms of on and off signals
• Symbols used to represent these: 1 and 0 (binary digits)
– 1 corresponding to high voltage
– 0 corresponding to low voltage
• All operations and data inside a computer are expressed in terms of the binary digits or bits
Binary Digits (Bits)
CSE-2021 May-10-2012 15
1 0 1 0 1 1 0 0 1
Communication Signal
The Software Story…
CSE-2021 May-10-2012 16
The SW Trail (1)
editor saves it to disk
CSE-2021 May-10-2012 17
Requirements
Design
Implementation
High-Level Program
3311, 3101
1020, 1030 2011, 2031
2041, 3421 4413, 3461 ...
The SW Trail (2)
save .exe to disk
CSE-2021 May-10-2012 18
High-Level Program
Data Translation
Assembly Lang (obj)
Machine Lang (exe)
load from disk
Code Translation
5/10/2012
4
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
19 CSE-2021 May-10-2012 CSE-2021 May-10-2012 20
Search for the account xx upon a card swipe
for (int i = 0; i < n & !found; i++)
{
found = (list[i] == xx);
}
la $a0, true
addi $s0, $0, xx
add $t0, $0, $0
add $t1, $0, $0
lbl: lb $t2, list($t1)
beq $t2, $s0, ok
addi $t1, $t1, 1
slti $t2, $t1, n
bne $t2, $0, lbl
la $a0, false
ok:
0x3c011001
0x34240028
0x20100226
0x00004020
0x00004820
0x3c011001
0x00290821
0x8c2a0000
...
Requirement
Hi Level
Assem
bly
Mach
ine
The SW Trail (3)
CSE-2021 May-10-2012 21
Executable File on disk
Loader
launce
in DRAM
text
data
heap
stack
The Hardware Story…
CSE-2021 May-10-2012 22
(to understand execution better, we’ll go bottom-up)
The HW Trail (1)
CSE-2021 May-10-2012 23
silicon
ingot wafers being sliced
polished wafer
©http
://ww
w.b
it-tech.n
et
CSE-2021 May-10-2012 24
But can intelligence be built out of conducting or not conducting electricity?
5/10/2012
5
The HW Trail (2)
CSE-2021 May-10-2012 25
The HW Trail (3)
CSE-2021 May-10-2012 26
The HW Trail (4)
CSE-2021 May-10-2012 27
The HW Trail (5)
CSE-2021 May-10-2012 28
Select between two alternatives A and B
mux
0
1 A
B
C
S
The HW Trail (6)
CSE-2021 May-10-2012 29
Inside the Processor (CPU)
• Datapath: performs operations on data
• Control: sequences datapath, memory, ...
• Cache memory
– small fast SRAM memory for immediate access to data
CSE-2021 May-10-2012 30
5/10/2012
6
Inside the Processor (e.g.)
• AMD Barcelona: 4 processor cores
CSE-2021 May-10-2012 31
The HW Trail (7)
CSE-2021 May-10-2012 32
CPU
DRAM
I/O
The HW Trail (8)
CSE-2021 May-10-2012 33
CPU
DRAM
KEYBOARD
PRINTER
DISK
SCREEN
Expansion Slot
Additional Readings
• What’s inside a desktop computer
• Input devices (mouse)
• Output devices (CRT, LCD, …)
• Memory – volatile main memory (DRAM)
– non-volatile secondary memory (magnetic disk, flash, optical disk)
• Networks – LAN (Ethernet)
– WAN (the Internet)
– wireless (WiFi, bluetooth)
CSE-2021 May-10-2012 34
...and the two trails meet!
CSE-2021 May-10-2012 35
The Two Trails Meet
CSE-2021 May-10-2012 36 EXECUTE!
I/O
000
001
…
100 instruction #1
101 instruction #2
102
…
Address Content
DR
AM
Sends address
Receives content
CPU
100 PC
Loader sets PC
to entry point
5/10/2012
7
Components of a Computer
• Same components for all kinds of computer
– desktop, server, embedded
• Input/output includes
– user-interface devices
• display, keyboard, mouse
– storage devices
• hard disk, CD/DVD, flash
– network adapters
• for communicating with other computers
CSE-2021 May-10-2012 37
The BIG Picture
Abstractions (1)
The BIG Picture
• Abstraction helps us deal with complexity
– both h/w and s/w utilizes hierarchical layers
– hides lower-level details
• Machine organization
– ways in which different computer components are interconnected
CSE-2021 May-10-2012 38
Abstractions (2)
The BIG Picture
• Instruction set architecture (ISA)
– the hardware/lowest level software interface
– library of instructions that computer can execute
– encompasses all info required to write a machine language program that will run correctly
• including instructions, registers, memory access, I/O…
– allows computer designers to talk about functions independently of the h/w that performs them (as in the case for a digital clock)
CSE-2021 May-10-2012 39
Abstractions (3)
The BIG Picture
• Application binary interface
– the ISA plus system software interface
• Implementation (w.r.t. an ISA)
– the details underlying and interface
– h/w that obeys the ISA abstraction
• Computer architecture
– ISA + Machine Organization
CSE-2021 May-10-2012 40
Course Info
• Course webpage: http://www.cse.yorku.ca/course/2021
• Text: Computer Organization and Design, Revised Fourth
Edition, 4th Edition: The Hardware/Soft- ware Interface, 2011
• Assessment:
– Lab Exercises (8x): 40% − Labs start on May 14th
– Mid-term Exam: 20%
– Final Exam: 40%
41 CSE-2021 May-10-2012
Course Webpage
• Please subscribe to Latest News – bottom right: Login using your red@cse id/password
– left menu: go to Latest News
– top right: click on Subscribe Page Changes
• Forum for CSE-2021
– share your course content related questions with others
– email for private questions only
CSE-2021 May-10-2012 42
5/10/2012
8
Labs
• Labs start next week
– preLab + exercise
• PreLab (LabTest mode – 6:55 to 8:20 pm)
– can submit from home until 6:40 pm Monday
– submitted files will be available in unsubmit folder (read only mode)
• Exercise (LabTest mode – 8:20 to 9:50 pm)
– submit as many times as you want
– marked manually
• Makeup Labs
– A-D
– K-N
CSE-2021 May-10-2012 43
CSE 2021: Computer Organization
Lecture-1(b) Data Translation Binary patterns, signed and unsigned integers
Shakil M. Khan (adapted from Prof. Roumani)
Recap from Last Time…
save .exe to disk
CSE-2021 May-10-2012 45
High-Level Program
Data Translation
Assembly Lang (obj)
Machine Lang (exe)
load from disk
Code Translation
com
piler
Today’s topic
Data Translation
• It’s all about numbers!
– mapping text, pictures, sound, … to numbers
• The binary world
– binary patterns, bits and bytes, hex, the 2n rule
• Unsigned Integers
– the binary system, shift/mod, converting to/from
• Signed Integers
– sign and magnitude, one’s/two’s complement, converting, add/sub, sign extension
• Real Numbers
– IEEE-754, single and double precisions
CSE-2021 May-10-2012 46
It’s All about Numbers!
• Text
• Pictures
• Video clips
• Audio
CSE-2021 May-10-2012 47
The Binary World
• Binary digits (bits)
– 0 or 1
– ON or OFF
– high or low (voltage)
• Binary patterns
– strings of bits
– e.g.: …10 0100 0101 0000 0001 1111 1101 0101
• Representation size
– 1 byte = 8 bits
– 1 word = 4 bytes = 32 bits
CSE-2021 May-10-2012 48
5/10/2012
9
Bit Numbering
CSE-2021 May-10-2012 49
0 1 1 1 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1
0 1 2 3 29 30 31 … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … …
• Least Significant bit (LSb) = bit #0
• Most Significant bit (MSb) = bit #31
• Least Significant Byte (LSB)
• Most Significant Byte (MSB)
The 2n Rule (1)
• n bits can represent 2n distinct numbers
• Examples: – 21 => {0,1}
– 22 => {00,01,10,11}
– 23 => {000,001,010,011,100,101,110,111}
– 24 => {0000,0001,0010,0011,0100,0101,0110,0111, 1000,1001,1010,1011,1100,1101,1110,1111}
– …
CSE-2021 May-10-2012 50
The 2n Rule (2)
• The largest natural number that can be represented by n bits = 2n-1
• Examples: – 1 bit => 1
– 2 bits => 3
– 3 bits => 7
– 4 bits => 15
– …
CSE-2021 May-10-2012 51
Binary Patterns (Exercise)
• Prove that a binary pattern of size n can represent any one of 2n different things (hint: use induction)
• We want to represent a signal that has 41 possible values. How many bits do we need?
• How many bytes are needed to store a 640 x 320 coloured picture using 16 colour shade for each of Red, Green, and Blue?
CSE-2021 May-10-2012 52
Unsigned Integers (1)
• The binary system
– the value of ith digit d = d x 2i
• Converting to decimal
= 0x231+0x230+0x229+1x228+…+0x22+1x21+1x20
= 0 + 0 + 0 + 268435456 + … + 0 + 2 + 1 = 26843545910
CSE-2021 May-10-2012 53
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 1 2 3 29 30 31 … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … …
Unsigned Integers (2)
• Range/word:
– 0 to +4,294,967,295 (in binary: 00...000 to 11...111)
• Given an n-bit number
• Range: 0 to +2n – 1
CSE-2021 May-10-2012 54
0
0
1
1
2n
2n
1n
1n 2x2x2x2xx
5/10/2012
10
Unsigned Integers (3)
• Converting from decimal
– the mod
– e.g.
• convert 610 to binary
• convert 10110 to binary
CSE-2021 May-10-2012 55
Logical Shifts
• Logical shifts
• Left shift Z by n bits
– =Z x 2n
• Right shift Z by n bits
– =Z / 2n
CSE-2021 May-10-2012 56
1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
000000 Shift Left Logical
Other Bitwise Operations
• X
• Y
• and
• or
• xor
• not (X)
• nand, nor, ... CSE-2021 May-10-2012 57
1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1
1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
• Read/write long binary strings: tedious
• Solution
– use higher base
– data size of all computers today = multiples of 4
• Use hexadecimal numbers
– why not decimal?
– 16 = 24, so convert 4 bits at a time using lookup table
– often written with prefix `0x’
• Examples?
The Hex Notation
CSE-2021 May-10-2012 58
bits hex bits hex
0000 0 1000 8
0001 1 1001 9
0010 2 1010 A
0011 3 1011 B
0100 4 1100 C
0101 5 1101 D
0110 6 1110 E
0111 7 1111 F
Unsigned Integers (Exercises)
• Represent the unsigned integer 75
• Determine the decimal value of the unsigned integer 0x4A
• Given an unsigned integer k, how many bits are needed to represent it?
• Compute largest unsigned integer that can fit in one, two, four, and eight bytes
– are your answers consistent with the 2n rule?
• Consider the bit pattern 0xAFC7 and imagine shifting all its bits left by one position. Show that it becomes 0x5F8E
CSE-2021 May-10-2012 59
More Exercises
• How many bytes are needed to store a 640 x 320 coloured picture using 16 colour shades for each of Red, Green, and Blue?
• As above but for a one-min silent video clip with 24 fps and the same specs as above?
• As above but add 16-bit sound sampled at 40 kHz?
CSE-2021 May-10-2012 60
5/10/2012
11
Signed Integers
• Signed integers
– sign and magnitude
– the 1’s complement
– the 2’s complement
• Converting
– to decimal
– from decimal
• Arithmetic right shifts
• Sign vs. zero extension
CSE-2021 May-10-2012 61
Sign and Magnitude
• Range/word:
– -2,147,483,647 to +2,147,483,647 (in binary: 11...111 to 01...111)
• Format
– reserve 1 bit for sign
– rest for magnitude
• Issues
– where to put the sign bit?
– both positive and negative zeros 00...000 and 10...000
– complex h/w: needs extra step to set sign bit
CSE-2021 May-10-2012 62
The 1’s Complement
• Range/word:
– -2,147,483,647 to +2,147,483,647 (in binary: 10...000 to 01...111)
• Format
– positive as unsigned (but MSb not used: why?)
– invert all bits for negative
• Issues
– again, positive and negative zeros 00...000 and 11...111
– complex h/w: needs extra step to subtract
CSE-2021 May-10-2012 63
The 2’s Complement (1)
• Used universally since 1965
• Range/word:
– -2,147,483,648 to +2,147,483,647 (in binary: 10...000 to 01...111)
• Advantages
– non-negative numbers have the same unsigned and 2s-complement representation
– all negative numbers have 1 in MSb, so h/w needs to check sign bit only for polarity
CSE-2021 May-10-2012 64
The 2’s Complement (2)
• Issues
– positive and negative numbers not balanced
• Some specific numbers
– 0: 0000 0000 … 0000
– –1: 1111 1111 … 1111
– Most-negative: 1000 0000 … 0000
– Most-positive: 0111 1111 … 1111
CSE-2021 May-10-2012 65
The 2’s Complement (3)
• Given an n-bit number
x = -xn-12n-1 + xn-22
n-2 + ... + x121 + x02
0
• Range: –2n – 1 to +2n – 1 – 1
• Example
– 1111 1111 1111 1111 1111 1111 1111 11002 = –1×231 + 1×230 + … + 1×22 +0×21 +0×20 = –2,147,483,648 + 2,147,483,644 = –410
CSE-2021 May-10-2012 66
5/10/2012
12
Signed Negation
• Complement and add 1
• Example: negate +2
– +2 = 0000 0000 … 00102
– –2 = 1111 1111 … 11012 + 1 = 1111 1111 … 11102
• More examples
CSE-2021 May-10-2012 67
0x4E = 0 1 0 0 1 1 1 0 78 +78
0xA3 = 1 0 1 0 0 0 1 1 163 -93
0xF1 = 1 1 1 1 0 0 0 1 241 -15
Signed integers : add or sub?
• Compute 0x4E + 0xA3
CSE-2021 May-10-2012 68
Arithmetic Right Shift
• Try right shifting a signed negative number
– 0xFFFF FFFE >> 1 = 0x7FFF FFFF
– -1 shifted right once = large positive number!!
• Solution
– arithmetic right shift
• What about left shifting signed numbers?
CSE-2021 May-10-2012 69
Sign Extension
• Representing a number using more bits – preserve the numeric value
• Many instructions have 16-bit operands – need to extend to 32 bits
• Replicate the sign bit to the left – contrast with zero extension (for unsigned ints)
• Examples: 8-bit to 16-bit – +2: 0000 0010 => 0000 0000 0000 0010
– –2: 1111 1110 => 1111 1111 1111 1110
CSE-2021 May-10-2012 70
Signed Integers (Exercises)
• Represent the signed integer -75
• Determine the decimal value of the signed integer 0x4A
• Why does sign extension work?
• Compute smallest and largest signed integer that can fit in one, two, four, and eight bytes.
– are your answers consistent with 2n ?
CSE-2021 May-10-2012 71