CSC 230: Computer Architecture and Assembly Language
Dr. Mike Zastre
Department of Computer Science University of Victoria Summer 2020
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 1
Introduction: What this course covers
• The architecture of computer systems and instruction sets
• The organization and interaction of CPU, buses, and memory
• The architecture of RISC and CISC machines
• Input / Output (I/O) and interrupt processing
• Memory organization and management (i.e., cache and virtual memory)
• Performance
• Interface with software: assemblers, linkers, and loaders
• Assembly language programming
• Interface between assembly language programming with high- level language through function call conventions
• The MIPS processor architecture as an in-depth case study
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 2
Material
• No textbook required
• Over the term, links to relevant material will be posted on conneX (at the Wiki section of the site)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 3
Course and lab notes
• CSC courseware site:
– https://connex.csc.uvic.ca
• Lecture slides will be posted on conneX…
– … although normally draft slides will appear at the start of a section …
– … but final slides will appear once section coverage is completed
– My thanks to Professors Bird, Corless, Ganti and Jackson for use of their course material
• Also on conneX: assignments, labs, discussion forums, etc.
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 4
Evaluation
• Official course outline: after approval, link will be posted on conneX
• Five assignments:
– First is worth 2%
– Remaining four are worth 10%
• Four exams (online):
– First is worth 10%
– Remaining three are worth 14%
– Exams are cumulative
– No final exam
• Labs: worth 6%
• From July 3 to August 7: Each student will be asked to
participate in an individual online & oral assessment – Details to be provided later in the term
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 5
Labs != Assignments
• First lab begins the week of May 11th, 2020
– You must be registered for a lab section
– First lab session will describe the coding environment you must create for yourself
– Note: This environment will be OS agnostic (Windows 10, macOS, Linux will all work)
• Please: no switching of lab sections
– Attend the section in which you are registered
– Enrollment numbers are high this semester, and we cannot accommodate informal lab switching
• Some in-lab evaluation is required (may be in the form of quizzes, coding, etc.)
• Larger assignments meant to be completed outside of lab time.
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 6
Introduction to computers
• But haven’t you always used a computer?
• Therefore:
– Isn’t it obvious?
– Couldn’t someone at
• Goal of this part of the course:
– Answer the question with more accuracy and more precision
– Technical answer, not marketing answer
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 7
Activity
Log in to rocket.csc.uvic.ca (using your Netlink ID and password). Go to the CSC230_2020051 private group.
Post a short message describing the first computer you remember using (make? model? operating system?) and why that computer was important for you. Do you remember the microprocessor used for that computer?
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 8
Three stories (#1)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language
The need for faster and faster arithmetic calculation has motivated many innovations in computer architecture
Overview: Slide 9
Images: https://bit.ly/3dklZff, https://bit.ly/3fioG2H, https://bit.ly/2W5gfAi, https://bit.ly/2WpQlWT
Three stories (#2)
Placing a CPU onto a singleCSCs2i3l0i:cComnputderiAerchitecture and Assembly Language
University of Victoria
Overview: Slide 10
completely transformed the possibilities for computer architecture
Department of Computer Science
Images: https://bit.ly/3b428zt, https://bit.ly/3c5aTKO, https://bit.ly/2Wo83da, https://bit.ly/2YzHKnc, https://bit.ly/2YwORwr, https://bit.ly/2SD72Nr
Three stories (#3)
Faster, more powerful computer architectures are possible when
University of Victoria
exploitiDnepgartbmeontohf Cormepduteur Sciendce hardware complexity and better compilers
CSC 230: Computer Architecture and Assembly Language
Overview: Slide 11
Images: https://bit.ly/35vcib3, https://bit.ly/2Ywq3EY, https://bit.ly/2Ywqijm, https://bit.ly/2W3gGLt
What is a computer?
“… programmable electronic device that can store,
retrieve, and process data.” [Taken from random intro-to-
programming textbook.]
• A device that:
– Accepts input (e.g., keyboard, mouse, touch screen, network interface, sensor)
– Processes data
– Stores data (usually in some form of memory)
– Retrieves data (ditto)
– Produces output (e.g., printed, display, actuator, network interface)
University of Victoria Department of Computer Science
Image: http://bit.ly/2DYDzn6
CSC 230: Computer Architecture and Assembly Language Overview: Slide 12
Is this a computer?
Parking aid
Climate control
Alarm & immobilizer
Automatic wiper control
Airbag control unit
Electric window & central locking
Anti-lock braking system
Automatic transmission
Electric motor management
Gas motor management
Battery-recharge control
etc.
University of Victoria Department of Computer Science
Image: http://bit.ly/2CydL52
CSC 230: Computer Architecture and Assembly Language Overview: Slide 13
Types of Computers
• Therearesometraditionalcategories…
• …Yetcomputingdevicesarenowsoubiquitousitis
easy for a computer to be “invisible”
• Personalormicrocomputers – Desktops
– Notebooks, Laptops
• Handheld(smartphones,PDAs)
• Mainframes
• Supercomputers
• Cloudcomputingenvironments(AmazonECS, Microsoft Azure, Google Cloud Platform)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 15
Types of Computers
• Personal Computers (PCs)
• Used for general computing tasks
• Fit the needs of most users
University of Victoria Department of Computer Science
Images: https://bhpho.to/2lNPNsi, http://bit.ly/2CNAnLX
CSC 230: Computer Architecture and Assembly Language Overview: Slide 16
Types of Computers
• Hand-heldcomputers
• Fitinthepalmofyour hand and run on batteries
• Perhapstheformof computers used directly by most people today
• (“Tabletcomputers”are a good crossover category crossing PCs and handhelds)
University of Victoria Department of Computer Science
Images: http://bit.ly/2jzlvaG, http://bit.ly/2AgKqGh, http://bit.ly/2CAkUB0
CSC 230: Computer Architecture and Assembly Language Overview: Slide 17
Types of Computers
• Mainframes
• Usedbycompaniesto provide centralized storage, processing, and management for large amounts of data
• Nowadaysmadeupof racks of blades, seen in data centres
• Importantfocus especially placed on fast I/O
University of Victoria Department of Computer Science
Images: http://bit.ly/2CyqfcU, http://bit.ly/2qiD3yv
CSC 230: Computer Architecture and Assembly Language Overview: Slide 18
Types of Computers
• Supercomputers
• Largestandfastestof
• Meanttocombinethe ultimate in processing speed and data throughput
– But focus is mostly on speed
– Massive power consumption!
• http://www.top500.org
University of Victoria Department of Computer Science
computers
Images: http://bit.ly/2ENittc, http://bit.ly/2ClwGvV
CSC 230: Computer Architecture and Assembly Language Overview: Slide 19
Types of Computers
• Cloud Computing
• Not necessarily a different category of computer, but a particular way in which existing mainframes are used
• Location independent computing
• Shared servers provided resources
• Software and data on demand
– (think of computing here as a “utility” like electricity or pay-per-use)
University of Victoria Department of Computer Science
Image: http://bit.ly/2CNQv03
CSC 230: Computer Architecture and Assembly Language Overview: Slide 20
Components of a computer system
Computer
Hardware
(physical devices)
Software
(instructions & data)
Device Drivers
Hardware and software “communicate” through pieces of
specialized code known as “device drivers”.
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 21
What is a “computer”?
• We usually also refer to a computer system
• Hardware: comprehensive term
– Physicalcomponents…
– …plusthewaytheareinterconnected(wired)
– Pre-definedfunctionality(”hard-wiredlogic”)isveryfast but hard to change
• Software:
– Theprogramsorlistsofinstructions
– Thoughtexperiment:whatkindsofinstructionswouldbe needed to control the hardware properly?
– Logicandfunctionalitycanbeeasilychanged
• Peripherals (i.e., “optional”, not the core)
– Additionalcomponents
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 22
Shell model of computer system
hardware
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 23
s
n
o
i
b
r
o
t
w
s
a
i
r
t
c
a
r
i
e
l
p
n
s
e
e
y
p
o
c
s
i
t
w
p
e
v
o
a
g
d
m
r
i
e
r
v
e
d
d
r
s
p
o
w
e
r
p
o
i
n
t
w
i
n
a
m
p
Computer Hardware
• Remember: computer here is a synonym for “computer system”
• CPU: Central Processing Unit
– Also: processor; microprocessor
• Memory: two kinds
– RAM (Random Access Memory)
– ROM (Read Only Memory)
• Storage devices and media:
– Hard disk
– SSD, Flash storage
– DVD, DVD-ROM, DVD-RW, etc.
• Input devices: keyboard, mouse, touchpad, button
• Output devices: screen, printer, network, motors
• Communication devices: network, infrared, Bluetooth, wifi
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 24
Computer Hardware
Video
Controller
Keyboard
Controller
Touchpad
Controller
SSD
Controller
Memory
CPU
Key point: Devices are electrically connected using multiple wires known as a bus
Bus
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 25
Inside a computer (laptop, desktop)
University of Victoria Department of Computer Science
Images: http://bit.ly/2EOMLMf, http://bit.ly/2qjQhuL
CSC 230: Computer Architecture and Assembly Language Overview: Slide 26
Modern PC architecture
• The confusing bit:
– Some of the electrical connections are within chips
– Some of the electronical connections are between chips
• Reminder:
– Input and output are collectively known as I/O
University of Victoria Department of Computer Science
Diagram: http://bit.ly/2lUDFF1
CSC 230: Computer Architecture and Assembly Language Overview: Slide 27
Recent core-i7 board (2017)
University of Victoria Department of Computer Science
Image: http://bit.ly/2Aousu5
CSC 230: Computer Architecture and Assembly Language Overview: Slide 28
The good news…
• We will focus this semester on architectures less complex that current PC architectures
• Because the course is online this semester, you will work with a hardware simulator to explore some ideas
• Note, however:
– Complexity is usually in the service of some design aim chosen by the computer-system architectures
– Knowing the design aims eventually helps us understand why specific decisions were made (that otherwise look complicated)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 29
Homework
Imagine you are in charge of directing a group of five-year-olds to do several loads of laundry.
You are in the laundry room with the kids (and the washer and dryer), but only the kids are allowed to touch the machines.
What kind of instructions would you give them to do three loads?
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 30
Basic Processor Architecture
• The computers in which we are interested are also known as
stored-program processors
• Every general purpose processor is designed on the fetch-
decode-execute-writeback cycle
– A machine instruction is fetched from program memory…
– … the instruction is then decoded to determine its meaning …
– … and then the actions indicated through decoding are executed
– … with those results written back
• This cycle is driven by a series of clock pulses (timing signals)
– Goes on forever (or until power is turned off)
– Each pulse marks the start of a fetch-decode-execute-writeback cycle
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 31
CPU Execution Cycle
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 32
Timing (Clock)
• Nearly all computers depend upon some sort of timing signal or clock
– Clock is a periodic timing signal whose period is called a cycle
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 33
Timing + fetch/decode/execute
• One architectural approach is to fit the fetch/decode/execute cycle in one clock cycle
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 34
Timing (Clock)
• The numbers of cycles in a single second is called the cycle’s frequency
– Units are Hertz (Hz); in older literature may see cps
• Each processor operates at a certain frequency
– Also known as the processor speed
– 1000Hz=1kilohertz=103 Hz=1KHz
– 1,000,000 cycles per second = 1 megahertz
=106 Hz1MHz
– 1,000,000,000 cycles per second = 1 gigahertz =109 Hz=1GHz
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 35
Central Processing Unit (CPU)
• Thisisthecoordinatorofeverycomputersystem
– Sometimes called the “brain”, but that can be very misleading!
• CPU(orprocessor):
– Responsible for controlling most aspects of computer
system
– Processes data in small units
– Performs arithmetic and logical operations
– Stores and retrieves data from memory
– Communicates with and/or controls peripheral devices
• EachfamilyofCPUshasitsownmachinelanguage
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 36
CPU internals
1. Control Unit (CU)
Fetch Next Instruction Fetch Data Store Data Increment Instruction Ptr
Execute Instruction
…
2. Arithmetic/
Logic Unit (ALU)
Add Sub Mult Div AND OR
NOT …
3. Registers
Integer
Floating Point
• CPU consists of three main parts:
– Control unit (CU, the main coordinator)
– Arithmetic Logic Unit (ALU)
– Registers (very fast temporary memory)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 37
MOS Technology 6502 (from 1976)
Outside: https://bit.ly/2Hhgj78
Inside: https://bit.ly/2WDNrwE
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 38
Pentium III (from 2003)
Outside: http://bit.ly/2Cr3dki
Inside (plus meanings of acronyms): http://bit.ly/2lRINd4
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 39
1. Control Unit (CU)
• Decides what CPU components are to be used next
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 40
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 41
https://bit.ly/2zl4tIO
1. Control Unit (CU)
• Responsibleforoverallguidanceonfetching, decoding, and executing instructions
– In reality, it causes data to flow to the CPU components that can complete the operation
– Instructs ALU to perform add, multiply, AND, etc.
– Possibly branch (i.e., choose amongst several possible
flows of control)
• Issueslogicsignalsforroutingdatabetween registers and internal data pathways
– Load data from main memory (RAM) into register – Store data from register into main memory
• Inallofthis,systemclocksynchronizesactivities!
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 42
2. Arithmetic/Logic Unit
• Containscircuitryforinteger,floatingpoint,and logic operations
• NoteCUisresponsibleforgettingthedatatoand from the ALU
– Depending on signals it receives, ALU performs actions
• Arithmeticopexamples:
– Add, subtract, multiply, divine, square root, cosine
• Logicalopexamples:
– Compare two numbers to see which is greater – Check whether a number is equal to zero
– Check whether a number is negative
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 43
3. Registers
• Memory-like locations inside the CPU
• Designed for use with instructions currently being performed
• Hold operands used by current ALU operations – Alsoholdresultsofthoseoperations
• Example:
– CPUisaddingtwonumbers
– Oneoperandisinsomeregister,otheroperandisina different register
– Additionisperformed,withresultstoredin(perhaps!)yet another register
• Registers are expensive (far fewer in number than normal memory, at most a few hundred).
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 44
How registers are used
Register Ri
Register Rj
Register R3
Register R5
Register Rk
some op
MULT
Register R2
• Every arithmetic or logical operation has one or more operands…
• … And one result.
• Functional black-box performs operation
• Result always goes to a register
operand 1
operand 2
5
7
result
University of Victoria Department of Computer Science
35
CSC 230: Computer Architecture and Assembly Language Overview: Slide 45
CPU execution cycle
• Memory normally organized:
– asasequenceofbytes,or…
– …asasequencewords…
– …butineithercase,isaccessedbyanaddress.
• Processor keeps track of next instruction’s address
– Thatis,thenextaddresstobefetched
– Addressnormallystoredintheprogramcounter(PC)or instruction pointer (IP)
• After fetch, PC / IP is updated to address of next instruction
– Normallythisupdateisintheformofanincrementbysome fixed amount
– Thisupdatemaybeoverwrittenwhencontrolflowchanges…
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 46
A bit more about memory
• Memory is used for at least two things:
– contains code of running program
– contains data (i.e., variables, constants) for running program
• Von Neumann architecture
– Same memory is used for code and data – (also called a Princeton architecture)
• Harvard architecture
– Code is in one memory system
– Data is in a separate, different memory system
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 47
Von Neumann architecture
• Named after John von Neumann (1903 – 1957), a Hungarian- American mathematician.
• While doing consulting work for the University of Pennsylvania in the 1940s, Neumann proposed storing program instructions in same physical location as data to be processed.
• He wrote up his ideas in a very influential report.
• von Neumann was actually at the Institute for Advanced Studies at the time.
– Hence “Princeton” Architecture
– More commonly called the
Stored Program Computer
Images: http://bit.ly/2qVkAYX, http://bit.ly/2D0tjii
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 48
Harvard architecture
• Named after Harvard University who collaborated with IBM during World War 2 in order to create an electrical-mechanical computer
– von Neumann worked on the programming team.
• By keep instructions apart from data …
– … different pathways / buses were used for each …
– … potentially increasing performance.
• Fetch and decode of one instruction happens simultaneously with execution of another instruction
University of Victoria Department of Computer Science
Image: http://bit.ly/2D2jLDA
CSC 230: Computer Architecture and Assembly Language Overview: Slide 49
Comparison
processor
main memory
instruction
memory
processor
data memory
von Neumann / Princeton
addresses
data and
instructions
Harvard
instruction
addresses
instruction
University of Victoria Department of Computer Science
data
addresses
read & write
data
CSC 230: Computer Architecture and Assembly Language Overview: Slide 50
System Bus Model
CPU
(ALU,
registers &
control
MEMORY
I/O
(input &
output)
This view is an approximation; we’ll look at code caches and
data caches later in the semester…
University of Victoria Department of Computer Science
data bus
address bus
control bus
CSC 230: Computer Architecture and Assembly Language Overview: Slide 51
System Bus Functionality
• Bus is used as a “travel highway for digital bits”
– Fortransferringdata,address,andcontrolsignalsbetween devices (bus = large # of parallel “wires”)
• Example of use: CPU needs to READ data from another unit.
1. CPU places address of needed data on address bus
2. The requirement for a read is signaled by CPU on the
control lines
3. The correct device (memory? input device?) responds to
what it sees on address bus and control lines
4. Device places data onto data bus
5. CPU has been listening to the data bus and control lines; when it recognizes data is present, it pulls it off the data bus (and perhaps into a register)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 52
Storage / Memory Hierarchy
• Memory hierarchy refers to the levels of fast and slow speed memories use in PC architectures
– System cleverly moves data to and from levels
– This is done to improve both runtime performance and system flexibility
– Two main categories of storage
• Primary (fast memory, but small in size, and expensive)
– registers
– cache
– main memory
• Secondary (slower memory, very large capacity, much less expensive)
– hard disk, SSD, memory keys
– other kinds of removable media (e.g., DVD-ROM)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 53
Red arrows: towards slower memory
CPU
registers
inside processor
CACHE
on motherboard
MAIN MEMORY
DVD-ROM
SSD
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 54
Registers
• These are inside the CPU
• Architecture usually determines:
– the number of general-purpose registers
– how large each register is (i.e., number of bits stored in a register)
– the manner in which a register can be used by an instruction
• Our processor for the course has 32 general- purpose (GP) registers
– each is 8-bits large (i.e., each GP register stores a byte)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 55
Primary Storage
• This is where data and instructions reside when used by a currently-executing program
• Typically volatile
– That is: contents of primary storage disappears
when computer is powered off
• Normally two categories of primary storage.
• In this course will eventually examine:
– cache (L1, L2)
– main memory (random-access memory, or RAM)
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 56
An aside: ROM vs RAM
• ROM: Read-Only Memory
– Non-volatile
– CPU can look at any location, and get the same memory speed, but cannot modify
• RAM:
– CPU can look and change arbitrary values (i.e., data at addresses) and in any sequence without a time penalty
– Quite often RAM, main memory, and memory are used as synonyms
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 57
Secondary storage
• Normally where data and instructions are stored outside of primary memory
• Important: This memory is also non-volatile
• Much, much slower than RAM…
– … but therefore also much cheaper, and with a higher memory capacity
• Other than some SSDs and installed hard drives, this storage is separate from the computer itself, perhaps even portable
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 58
I/O: input/output devices
• WenormallysayI/Oasshorthandfor “input/output”
• Inputdevices:
– transfer data from some device into computer
– keyboard, mouse, scanner, microphone, touchpad, joystick
• Outputdevices:
– transfer data out of computer – monitor, printer, speakers
• Note:
– Although strictly speaking with perform I/O when using
secondary storage, we usually distinguish such devices
from more general I/O.
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 59
Summary
• Weareinterestedhereincomputerarchitectures…
• …andthewaythefitintolargercomputersystems
• CentraltoacomputeristheCPUandwhatit encompasses
– ALU
– Registers
– Control data
• CPU’soperationorganizedaroundthethefetch- decode-execute cycle
– Each clock tick starts a cycle
• Largercomputersystemaccessviathesystembus
University of Victoria Department of Computer Science
CSC 230: Computer Architecture and Assembly Language Overview: Slide 60