Topics
This page collects class material by topic.
Contents
Videos
Topic videos starting with x86 coming soon.
Textbooks
At least one copy of each text is available in the SCI L037 CS Systems Lab for use within the CS department area. Please do not remove them from the lab areas. Return them to the shelf when you are done.
We use one primary textbook extensively. You should acquire a copy if possible:
-
CSAPP 3e: SCI L037 CS Systems Lab lab has 2 copies
Computer Systems: A Programmer’s Perspective, 3/E. (3rd edition, significant changes since 2nd)
Bryant and O’Hallaron, Pearson, 2016. ISBN-13: 9780134092669.
You need the 3rd edition. See the errata.
“Global” 3rd editions mostly work, but have some additional errors (not listed on that page).An online version of the CSAPP3e textbook is now available for free through May 25 on VitalSource. After creating an account with your Wellesley email address, search for “Computer Systems: A Programmer’s Perspective”, then choose to “borrow” the book.
We provide other textbooks used briefly during the first 1/3 of the course:
- DDCA: SCI L037 CS Systems Lab lab has 3 copies; ebooks through the library linked below
Digital Design and Computer Architecture. (alt. ebook)
Harris and Harris, Morgan Kaufmann, 2007. - SCO: SCI L037 CS Systems Lab lab has 8 copies
Structured Computer Organization, any edition.
Tanenbaum, Prentice Hall, various. - Additional material on the course website.
We recommend a good reference on the C programming language. There are many online resources of various quality. One classic book is:
- K&R: the SCI L037 CS Systems Lab lab has 1 copy; more in library
The C Programming Language, 2nd edition.
Kernighan and Ritchie, Prentice Hall, 1988. ISBN-13: 978-0131103627, ISBN-10: 0131103628.
How to read for CS 240
CS 240 moves quickly and covers a lot of ground. To make class time effective, students should be ready to hit the ground running. Class meetings and group exercises will assume cursory familiarity with basic ideas from assigned readings posted on the course schedule. Reading before class to learn basic mechanics frees up more time in class to apply or debug your understanding of these mechanics and to consider their deeper implications.
Bonus benefits of reading:
- Class is more fun if come with a rough idea of where we’re going and what to watch out for along the way.
- Spending x minutes on reading now often saves multiples times x minutes of puzzlement or debugging later while working on assignments.
- We get to spend more time in class doing and less time listening to lectures.
Most topics on the course schedule have associated reading. Effective reading for computer science courses demands a staged approach. Aim for two types of reading:
- Do an initial reading in preparation for the class when the topic is scheduled.
- Revisit the reading later for deeper details or reference.
Before class, do an initial reading of the assigned reading material in preparation for class. (No need to look over the slides before class.)
Do not worry about understanding every last detail.
Do aim to acquire:
- A big-picture view of the pieces we will consider about this topic.
- Some familiarity with basic mechanics of the ideas introduced.
To help distinguish core points from secondary concerns during initial reading, each reading is listed with one of two style directives:
- Read means read for enough detail to do indicated reading exercises. If you do get stuck or confused by some details, do not worry. Make a note and move on. If we do not clear up your confusion in class, ask a question or come to office hours.
- Skim means read for high-level ideas. Perhaps pick out a couple details that look interesting and accessible. Do not spend much time trying to understand all the details before moving on.
Learning how to identify essential vs. inessential details during a first reading is an important skill that takes time to develop. As the semester progresses, we will leave more of this to you.
Readings assignments may indicate specific exercises to try as you read before class. These are typically practice problems from the reading.
- Try means work through enough of the exercise to see how the basics work. Do not feel obligated to finish every example. Do what is useful to you. (Do not submit anything.)
We typically highlight exercises that practice mechanics. Feel free to try other practice problems as well. They may require more time and critical thinking. We will explore such interesting examples in class.
After class, revisit readings in more depth and try more practice problems to work out details as needed.
More advice
Our main text (CSAPP) sometimes goes into more detail than we will cover, so learning to “read around” extra detail is a useful skill, especially in your pre-class reading.
When reading from CSAPP:
- “Asides” are optional. If you read them, skim them.
- “New to C?” blocks can be useful, but usually only if they are short.
- Some sections (e.g., 2.2 - 2.4 on integer and floating point representations) can be too dense for our purposes. We try steer you around them, but if you find other things getting dense, flip to another reading or just make a note and jump ahead.
- This book really shines with later material about machine/assembly language, caching, memory management, and other topics. We use it intermittently in the first section of the course, then extensively for the latter two.
Tia Newhall (Swarthmore College) has more good advice on reading computer science textbooks.
Material by Topic
topic The Plan
Lecture
Slides: ➊ plan.pdf ➍ plan-4up.pdf
Reading
- Read: Syllabus
- Skim: CSAPP 1.0 - 1.7, 1.9.2 - 1.10
Computer Hardware Implementation
topic Digital Logic
← Tuesday, 28 January - Friday, 31 January
Lecture
Slides: ➊ gates.pdf ➍ gates-4up.pdf
Reading
By our first full class day on this topic, you should be familiar with at least the basics of logic gates, notation for Boolean expressions, and a little Boolean algebra.
- Read: Syllabus
- Read: How to Read for CS 240
- Read: DDCA 1.5, 2.1-2.4 (pages 51-65), alt. ebook, or on Google Books
Optional alternatives/extras for before or after class:
Try these if you want alternatives to the DDCA reading above or if you want some practice or you just can’t wait until class.
- SCO 3.1. Skip physical technologies: MOS, TTL, ECL, etc.
- Web pages covering roughly the same material with inline examples and exercises.
- Digital logic gates: - Bucknell EE: An Introduction to Digital Logic - Signals and Gates. Stop at “Wiring a Quad NAND Gate.” - Surrey EE: Basic Gates and Functions - Digital Circuits and Boolean Logic. Stop at “Implementing Gates.”
- Boolean algebra - Bucknell EE: Boolean Algebra. - Surrey EE: Boolean Algebra
- Some more exercises
- Gates quiz (EXOR = XOR)
- Boolean algebra example, problem, and quiz
topic Data as Bits
← Friday, 31 January - Tuesday, 4 February
Lecture
Slides: ➊ bits.pdf ➍ bits-4up.pdf
Reading
Binary and hexadecimal number systems
Information as bits + context
- Read: CSAPP 2 - 2.1.2
- Exercises: CSAPP practice problems 2.1 - 2.4. (Solutions at end of chapter.)
- Skim: CSAPP 2.1.4 - 2.1.5.
Bitwise Boolean algebra and bit manipulation
- Read: CSAPP 2.1.6 - 2.1.9 (including the Asides.)
- Exercises: CSAPP practice problems 2.8, 2.9, 2.14, 2.16
- Optional: K&R 2.7, 2.9 for C reference
topic Integer Representation
Lecture
Slides: ➊ integers.pdf ➍ integers-4up.pdf
Reading
For reference after the class on integer representation:
Use this after class for reference. We’d like to introduce signed integer representations before you read about them.
As you read, focus on the positional representation of signed integers more than the mechanics of how to convert from integer representation to the representation you know well.
Read one of:
- “Twos Complement” section of these notes. Stop at “Floating Point.”
- Fundamental of Data Representation: Two’s Complement
- SCO A.4 - A.5
- CSAPP’s treatment of number representation is more thorough, but
some students find it too dense and prefer to skip some parts.
- Read: CSAPP 2.2 - 2.2.3.
Integer multiplication and division, relation to bitwise operations, sign extension
- Skim: CSAPP 2.2.4 - 2.2.8.
- Read: CSAPP 2.3.4-2.3.8
topic Combinational Logic
Lecture
Slides: ➊ mux.pdf ➍ mux-4up.pdf
Reading
Karnaugh Maps
- DDCA 2.7 (pages 71-79), alt. ebook, or on Google Books (missing pages 75-76)
Multiplexers and decoders
- Read: DDCA 2.8 (pages 79-84), alt. ebook, or on Google Books (missing pages 82-83)
- Read: SCO 3.2.2 (Combinational Circuits)
topic Logic for Arithmetic
Lecture
Slides: ➊ alu.pdf ➍ alu-4up.pdf
Reading
Adders
- Read one of:
- DDCA 5.1 - 5.2.1 (pages 233-234) up through Ripple Carry Adders (feel free to skim beyond if you are curious), alt. ebook (ignore Verilog and VHDL)
- SCO 3.2.3 (Arithmetic Circuits)
- Digital Circuits: Adders up until Carry Lookahead Adder (feel free to skim beyond if you are curious)
Arithmetic Logic Unit
- Read one of these to understand the high-level organization of an ALU. We will look at details of a specific ALU design in class.
- DDCA 5.2.2 - 5.2.4 (pages 23-234) up through Ripple Carry Adders (feel free to skim beyond if you are curious), alt. ebook
- SCO 3.2.3 section on Arithmetic Logic Units
- Arithmetic Logic Unit sections “Signals” and “Circuit Operation”
topic Sequential Logic and State
Lecture
Slides: ➊ registers.pdf ➍ registers-4up.pdf
Reading
- Read one of:
- DDCA 3.0 - 3.2.4 (pages 103-109), alt. ebook, or on Google Books (missing 103-104)
- SCO 3.3 - 3.3.2 (3rd ed.) / 3.3.3 (4th ed.), Latches, Flip-Flops, Registers
- Read DDCA 5.5 - 5.5.1 (pages 257-262), alt. ebook (ignore Verilog and VHDL). We will cover RAM only briefly in class.
topic A Simple Processor
← Tuesday, 25 February - Friday, 28 February
Lecture
Slides: ➊ arch.pdf ➍ arch-4up.pdf
Reading
Read for general organization and design points about instruction set architecture and microarchitecture. We will build our own toy architecture in class and lab.
- Read: Central Processing Unit (Operation section)
- Read: SCO 2.1 - 2.1.2, 2.2.2, 5.1 - 5.1.2 (stop at “Note that having separate address spaces for instructions and data”), skim 5.1.3 - 5.1.4
- Alternatives:
- Read: CSAPP 1.4.1, 2.1.0
- DDCA 7.3-7.3.3 (alt. ebook) describes a similar microarchitecture for a similar 32-bit ISA, but relies on some detail from an extensive discussion of instruction set architecture in Chappter 6. Our coverage will be more cursory.
topic Floating Point
Lecture
Slides: ➊ floats.pdf ➍ floats-4up.pdf
Reading
- Skim one of:
- DDCA 5.3 (pages 249-253), alt. ebook
- SCO Appendix B
- If you want more detail (e.g., on denormalization as discussed in class, or many in-depth examples), read CSAPP 2.4.
Hardware-Software Interface
topic Programming with Memory
← Friday, 6 March - Tuesday, 10 March
Lecture
Slides: ➊ memory.pdf ➍ memory-4up.pdf
Reading
General memory model:
- Read: SCO 2.2.2 - 2.2.3, 5.1.2 (stop at “Note that having separate address spaces for instructions and data”)
- Read: CSAPP 2.1.0, 2.1.3 - 2.1.4
Mix and match to start learning about addresses and pointers in C:
- Read: CSAPP 3.10.1
- Read Pointer Basics and watch the silly video too.
- K&R 5 - 5.5
- The Descent to C
- The 5-minute Guide to C Pointers
topic Reasoning about Programs
Lecture
Slides: ➊ assertions.pdf ➍ assertions-4up.pdf
Reading
In most semesters, we do not have time to cover this topic in lecture, but we ask you to skim these resources.
- How to use assertions in C, John Reekie.
- The benefits of programming with assertions (a.k.a. assert statements), Philip Guo.
For later:
- C Programming Tips, Philip Guo.
topic x86 Basics
← Tuesday, 31 March - Friday, 3 April
Lecture
Slides: ➊ x86-basics.pdf ➍ x86-basics-4up.pdf
Videos: ☰ yt playlist
- ▸ mp4 yt x86 Basics: Intro and History
- ▸ mp4 yt x86 Basics: Registers, Data Movement Instructions, and Memory Addressing Modes
- ▸ mp4 yt x86 Basics: Memory Examples
- ▸ mp4 yt x86 Basics: Memory Addressing Review
- ▸ mp4 yt x86 Basics: Load Effective Address (lea)
- ▸ mp4 yt x86 Basics: Procedure Call Stack Basics
-
▸ mp4
yt
x86 Basics: Arithmetic and Logic Instructions,
arith
Exercise Setup -
▸ mp4
yt
x86 Basics:
arith
Exercise Review,logical
Exercise Setup -
▸ mp4
yt
x86 Basics:
logical
Exercise Review
Reading
Background
- Skim: CSAPP 3 - 3.2
Data Movement
- Read: CSAPP 3.3 - 3.4 (including “New to C?” to help remember those pointers…)
- Exercises: try CSAPP practice problems 3.1, 3.2. Take a look at practice problem 3.5, but don’t spend too long on it. We’ll try more like this in class.
Arithmetic
- Read: CSAPP 3.5 - 3.5.4
- Exercises: try CSAPP practice problems 3.8, 3.9. (Note
x <<= 4;
is the same asx = x << 4;
.) - Skim: CSAPP 3.5.5
topic x86 Control Flow
← Friday, 3 April - Tuesday, 7 April
Lecture
Slides: ➊ x86-control.pdf ➍ x86-control-4up.pdf
Videos: ☰ yt playlist
- ▸ mp4 yt x86 Control Flow: Condition Codes, Comparisons, and Tests
-
▸ mp4
yt
x86 Control Flow: Jumps, Translating If-Else, and
absdiff
Exercise Setup -
▸ mp4
yt
x86 Control Flow:
absdiff
Exercise Review, goto, and If Compilation Exercise Setup - ▸ mp4 yt x86 Control Flow: If Compilation Exercise Review and PC-Relative Addressing
- ▸ mp4 yt x86 Control Flow: Translating Loops
- ▸ mp4 yt x86 Control Flow: Conditional Moves
- ▸ mp4 yt x86 Control Flow: Translating Switch Statements with Jump Tables
- ▸ mp4 yt x86 Control Flow: Translating Switch Statement Cases, Reverse Engineering Switches
Reading
Comparisons, Tests, and Jumps
- Read: CSAPP 3.6 - 3.6.4
- Exercises: Try CSAPP practice problems 3.13 - 3.14. Just consider what operator you’d put in place of
COMP
orTEST
to match the assembly code. (Don’t worry about#define
etc. if you don’t remember how macros work.)
Translating if
s and loops
- Read: CSAPP 3.6.5, 3.6.7
- Exercises: CSAPP practice problems 3.16, 3.23, 3.24
Translating switch
statements
- Skim: CSAPP 3.6.8, 3.6.6
topic x86 Procedures and the Call Stack
← Friday, 10 April - Tuesday, 14 April
Lecture
Slides: ➊ x86-procedures.pdf ➍ x86-procedures-4up.pdf
Videos: ☰ yt playlist
- ▸ mp4 yt x86 Procedures and the Call Stack: The Call Stack Stores Procedure Context
-
▸ mp4
yt
x86 Procedures and the Call Stack: Procedure Control Flow Instructions (
call
/ret
), Data Flow Conventions, Puzzle Setup - ▸ mp4 yt x86 Procedures and the Call Stack: Procedure Puzzle Review
- ▸ mp4 yt x86 Procedures and the Call Stack: Procedure and Stack Frame Example
- ▸ mp4 yt x86 Procedures and the Call Stack: Register Saving Conventions, Callee-Save Example
- ▸ mp4 yt x86 Procedures and the Call Stack: Recursion Example
- ▸ mp4 yt x86 Procedures and the Call Stack: Stack Storage Example, Procedure Summary
Reading
- Read: CSAPP 3.7
- Exercises:
- Follow the examples in detail.
-
Consider this code:
call next next: popq %rax
Describe the (meaning of the) value that gets stored into
%rax
. Why is there noret
instruction matching thecall
? Is this code useful? For what? This not howcall
is typically used, but it is a good test to check if you understand exactly what thecall
instruction does.
topic Representing Data Structures
Lecture
Slides: ➊ data-structures.pdf ➍ data-structures-4up.pdf
Videos: ☰ yt playlist
- ▸ mp4 yt Representing Data Structures: Simple Arrays
- ▸ mp4 yt Representing Data Structures: Multi-Level Arrays (Arrays of Pointers to Arrays of...)
- ▸ mp4 yt Representing Data Structures: Row-Major Multidimensional Arrays
- ▸ mp4 yt Representing Data Structures: Row-Major Array Review
- ▸ mp4 yt Representing Data Structures: Structs
- ▸ mp4 yt Representing Data Structures: Struct Alignment
- ▸ mp4 yt Representing Data Structures: Linked List Representation
Reading
- Read: CSAPP 3.8 - 3.10.1
Abstractions for Practical Systems
topic Dynamic Memory Allocation
← Tuesday, 21 April - Friday, 24 April
Lecture
Slides: ➊ malloc.pdf ➍ malloc-4up.pdf
Videos: ☰ yt playlist
- ▸ mp4 yt Dynamic Memory Allocation: Allocator Basics
- ▸ mp4 yt Dynamic Memory Allocation: Determining Block Size
- ▸ mp4 yt Dynamic Memory Allocation: Block Format and Heap Layout
- ▸ mp4 yt Dynamic Memory Allocation: Implicit Free List Search
- ▸ mp4 yt Dynamic Memory Allocation: Implicit Free List Allocation and Splitting
- ▸ mp4 yt Dynamic Memory Allocation: Implicit Free List Freeing and Coalescing
- ▸ mp4 yt Dynamic Memory Allocation: Explicit Free Lists
- ▸ mp4 yt Dynamic Memory Allocation: Explicit Free List Search, Allocation, and Splitting
- ▸ mp4 yt Dynamic Memory Allocation: Explicit Free List Freeing and Coalescing
- ▸ mp4 yt Dynamic Memory Allocation: Seglists and Allocation Summary
- ▸ mp4 yt Dynamic Memory Allocation: Remembrallocator Assignment - Block Format
Reading
- Read: CSAPP 9.9
- Skim: CSAPP 9.10 - 9.12
topic Memory Hierarchy and Cache
Lecture
Slides: ➊ cache.pdf ➍ cache-4up.pdf
Reading
For First Class Day of Cache Material:
- Skim: CSAPP 1.5-1.6, 6.1
- Read 6.2-6.4.3
For Second Class Day of Cache Material:
- Read 6.4-6.5
- Preview 1a and 1b in the upcoming lab assignment. We’ll see similar examples in class.
topic Virtual Memory
Lecture
Slides: ➊ virtual-memory.pdf ➍ virtual-memory-4up.pdf
Reading
- Read: CSAPP 9.0 - 9.7
topic Beyond 240
Lecture
Slides: ➊ beyond240.pdf ➍ beyond240-4up.pdf
What we missed in Spring 2020
Due to mid-semester changes in response to the COVID-19 pandemic, we missed the following topics and some assignments usually included in CS 240:
topic Buffer Overrun Exploits
Lecture
Slides: ➊ buffer.pdf ➍ buffer-4up.pdf
Reading:
- Read: CSAPP 3.10.3
- Exercises: CSAPP practice problem 3.46.
topic Exceptional Control Flow
Lecture
Slides: ➊ ecf.pdf ➍ ecf-4up.pdf
Reading:
- Read: CSAPP 8.1
topic Operating Systems, Process Model
Lecture
Slides: ➊ process.pdf ➍ process-4up.pdf
Reading:
- Read: CSAPP 1.7, 8.2 - 8.4