Welcome to Computer Organization and Assembly! · 2020-04-07 · Classes of computers: Servers and...
Transcript of Welcome to Computer Organization and Assembly! · 2020-04-07 · Classes of computers: Servers and...
Welcome!
CS/COE 0447
Luís Oliveira
Original slides by: Jarrett BillingsleyModified with bits from: Bruce Childers, David Wilkinson
Welcome!
● My name is Luis (pronounced Loo-eesh, but I don’t really care ☺ )
● I’m not from these parts as you can tell from my accent
o I come from Portugal
● course site: cs.pitt.edu/~loliveira orluisfnqoliveira.github.io/CS447o all the stuff I talk about today is on the course site
● email: [email protected]● office: 5421 SENSQ (check site)
● office Hours: TBD (check the site)
2
i before e except after c…
and this guy’s name!
Textbook
● Computer Organization & Design
(Patterson & Hennessy)
● Not mandatory!
o Get it if you really want
o No readings, no exercises
o May reference it once in a while
● gets into a lot of detail
o fun read if you pick this stuff up easily
3
Grading
● There will be no attendance
o But you should come to classes!
o Sometimes the slides alone may not be clear enough
▪ Even from seasoned professors! (I know, I’ve been there!)
● labs: 20%
o there'll be around 12? (~one a week)
o lowest 2 lab grades are dropped
● 3 projects: 40%
o two in MIPS assembly language, one in Logisim
o 15% two highest grades, 10% lowest grade
● 2 exams: 40%
o 1 midterms, 1 (semi-cumulative) final
o Lowest grade 15%; highest is 25%
4
Expectations● Religious absences are excused: contact me ASAP
● Students with disabilities should contact the Office of Disability Resources and Services (DRS) if you haven’t alreadyo 216 William Pitt Union; 412-648-7890; TTY:412-383-7355
● Please, no comments about sex, gender, race, ethnicity, religion, etc..o Anywhere!o Just be nice!
● Cheating: Don’t!o 0 on assignment first time, o fail the course second time.o Do not publish your work in public palaces (no github!)o you can also talk about labs, but still no sharing stuff
5
DO NOT CHEAT!
● If you're confused, don't cheat, ask me for help?
o Hot tips for not cheating:
1. Don’t!
2. Do not!
o You have LOTS of resources
▪ Me! and the TAs
▪ Undergraduate Helpdesk (CRC)
● People can tell when you cheat
o It is usually quite obvious!
o So don’t do it, it’s not worth it!
o The university is quite strict about it.
6
Teaching
● No questions are dumb!
o NEVER BE AFRAID TO ASK THEM!
o DON’T STRUGGLE IN SILENCE ON YOUR PROJECTS/LABS!!!!!!!
● Yes, you can probably learn all this stuff on your own
o But in lectures you have access to me
o You can ask questions, and get the answers promptly!
o Please… be interactive ☺
7
Introduction and Context
8
Goals of this course● How does a CPU work?o Looking under the hoodo How are programs executed?o CS 449 looks at the programs
● Topics coveredo Data representationo Assembly languageo Program execution
● Learning important fundamental skills:o Representing numbers in different bases (binary, hexadecimal, …)o Logical operations (Boole?)o Understanding logic diagrams o Programming an assembly language
9
Computational Theory
Algorithm Design
Applications
Operating Systems
ISA
Logic Design
Electrical Design
Physics
mo
re a
bstra
ct mo
re co
ncre
teWhere does this material fit in with CS and EE?
● the “hardware-software interface”
● where CS and EE overlap
● each layer affects/is affected by layers
above and below
● ISA: Instruction Set Architecture
o Programmer's interface to the
computer hardware
● logic design
o how we make 0’s and 1’s do stuff
o Rocks doing Lots of Stuff (aka a CPU)
10
More goals
● Let’s learn Assembly!
● Let’s unlearn High-level languages (Java, C)
o Datatypes/structures? Nope!
o Infinite number of variables? Nope!
● “Learning assembly is like a car mechanic learning how an engine
runs”
o Normal people don’t want to, but it’s fun to take things apart!!!
▪ Also putting them back together and (hopefully) see them work!
o And we are not normal people!
11
Computers
12
The pre-history of computers
● Charles Babbage (1792-1871) designed the analytical engine
o It already included the essential ideas of modern computers
▪ Inputs and outputs
▪ Execution of operations
▪ Automatic control of operation
o However, due to its complexity (lack of funding) it was never built
● From that point onwards many other advances were made
o George Boole developed Boolean Algebra
o The Hollerith Machine – Electro-mechanical machine used to
process census data in the US (reading perforated cards)
13
The pre-history of computers
● Leading to the first use of relays (electrical switches) in the 1930-40’s
o George Stibitz (Bell Labs)
▪ Model K – binary addition with relays (Boolean algebra)
▪ Complex Number Computer – used remotely via telegraph lines
▪ Art with Amiga (1990s) - http://stibitz.denison.edu/art.html
o Konrad Zuse (Germany)
▪ World's first programmable computer
▪ Several relay-based computers
– Used for military calculations
14
The first “modern” computers
● 1946 – ENIAC (Electronic Numerical Integrator and Computer),
University of Pennsylvania
o Developed during WWII to calculate balistic missile trajectories
▪ 18000 valves (tubes)
▪ 1500 relays
▪ 30 tons
▪ 175 kW
▪ 5000 additions / s
▪ 357 multiplications / s
▪ 40 divisions / s
▪ Programs "hardwired"
15
U. S. Army Photo
The first “modern” computers
● 1947 – EDVAC (Electronic Discrete Variable Automatic Computer),
University of Pennsylvania
o The ENIAC team (joined by John Von Neumann) created a
computer with a new concept:
▪ "Memory Stored Program" – same as data
o Became operational in 1951
● 1949 – EDSAC (Electronic Delay Storage Automatic Calculator),
Cambridge University, Maurice Wilkes
o Based on the first EDVAC draft
16https://en.wikipedia.org/wiki/EDSAC
The first “modern” computers
● 1951 – UNIVAC
o First commercial computer!
▪ Sold 46! Units
▪ Used to predict the 1952 presidential election
o Bi-quinary
o Used a MERCURY!! memory module (as did the EDSAC)
17
https://en.wikipedia.org/wiki/Delay_line_memory
Delay
Storage
The transistor and integrated circuits● 1971 – Intel 4004o 4-bit microprocessoro with 2300! Transistors
● 1993 – MIPS R4000o RISC 32-bito 1.3 Million transistors
● 2004 – Pentium 4o x86 32-bit o 125 Million transistors
● 2017 – Kaby Lakeo x86_64 64-bito >1000 Million! (undisclosed?)
18
Moore’s Law
19
82944 processors
from a supercomputer
Where used to simulate
1s of human brain activity
In 40m
Illustration:
https://www.wired.com/2013/05/neurologi
st-markam-human-brain/
All different but all
(mostly) the same
20
Classes of computers: Embedded (Microcontrollers)
● 8/16-bit architectures are still common
● as little as 32 BYTES of memory!
● almost always run one, built-in program
● focus on ultra-low power, cost, and size
● becoming more common every day
● “Internet of Things” (IoT)
o now your fridge can crash, your TV can crash,
your dishwasher can crash, everything can crash!
o Even your lightbulbs
can be hacked!
21
Classes of computers: Consumer-grade (PC/Mobile)
● 1-8 cores, 32/64-bit architectures, MB-GB of
memory, GB-TB of persistent storage
● multitasking operating systems
● similar capabilities, different design goals
● focus is real-time user interaction:
productivity, media, browsing, games
● Energy consumption is still relevant
o Mobile
● But, are we in a post-PC world?
22
Classes of computers: Servers and Mainframes
● from high end desktops to much more
powerful machines or groups of machines
● dozens of cores, 32GB+ of RAM, massive
storage systems, very high-speed networking
● focus on real-time data delivery - either from
storage or after processing
● redundancy and hot-swappability
● goal is 100% uptime
● power and cooling become huge concerns
23
Classes of computers: Supercomputers
● cluster of hundreds to thousands of CPUs
● focus on crunching ENORMOUS datasets non-interactively
● science, research, design, and simulation
o and now, stock trading and "cryptocurrencies"…
24
General computer organization
25
Control
Registers
Datapath
Processor
Memory
Persistent
Storage
Other
Peripherals
Other
Computers
Input/Output
Devices
Network
Assembly
26
So what exactly is assembly?
● Assembly: Human-readable representation of machine code
● Machine code: Machine code is what a CPU actually runs
27
00000001000000000010000000100000
add a0, t0, zero
So what exactly is assembly?
● Assembly: Human-readable representation of machine code
● Machine code: Machine code is what a CPU actually runs
● Essentially it's the "atoms" that make up a program
o CPUs are actually pretty simple in concept
▪ (oh wait, we still have a whole semester about it… huh)
● Each CPU has its own machine language and therefore its own
assembly language
● We’ll be using MIPS:
o Not that common
o Yet, often found in surprising places. (Nintendo 64, PS1/2, FPGAs)
o Very influential, and most common assembly looks like it.
▪ ARM and RISC-V are similar-ish ISA seeing much more usage
28
is assembly language useful today?
● Short answer: YES
● Assembly is “fast”, so we should use it for everything!
--- NO!!! ---
● No type-checking, no control structures, very few abstractions
o Probably you can be fairly fast using compiler optimizations
--- Fairly impractical for large things ---
● Tied to a particular CPU.
o So, large programs have to be rewritten (usually) to work on new
things.
● Yet: good for specialized stuff.
o Critical paths and “boot” code in Kernels / Operating Systems
o HPC (simulators, supercomputer stuff)
o Real-time programs (video games; tho increasingly less / abstracted away)
o And…
29
Embedded systems
● You’d be amazed at how many consumer devices have CPUs.
● Many are programmed largely/entirely in assembly (or C)
30
So where does assembly fit?
● Programs written in C, etc are generally translated into assembly.
o And then into machine code.
31
int main(void)
{
printf(“Hello world\n”);
return 0;
}
hello.c
.data
str: .asciiz “Hello world\n”
.text
.globl main
main:
li v0, 4
la a0, str
syscall
j ra
hello.s
Compile → by a compiler
Assemble → by an assembler
10010001001010001010100…
hello.o
Libraries
00101001010100101001001…
crt0.o
hello.exeLink
is assembly language useful today?
● Programs written in C, etc are generally translated into assembly.
o And then into machine code.
● Or you can look at the machine code of programs and get an
assembly code listing.
o And step through the program one instruction at a time.
● When programs crash (sometimes programs you don’t have the code
for) you can look at the assembly code and assess.
● Programs exist to help you (gdb, IDA Pro, radare, etc)
● In CS 449 you will apply this knowledge (using gdb).
32
and next time we'll start
● Data representations
● How does a CPU look at numbers, letters, etc.
● Learn about number bases:
o Decimal (that’s what we use!)
o Binary
o Octal
o Hexadecimal
33