Written by Julie Zelenski
This syllabus PDF gives an overview of our schedule: topics, assignment deadline, and exams schedule for the quarter. Topics may occasionally be shuffled around or assignment deadlines changed (see individual assignment pages for official deadlines). Exam dates are set at quarter start and will not change.
Below will appear more details on each week of the cousre (assigned readings, lab topics, lecture slides, links to various resources). It will be kept current for a few weeks out at a time.
In the readings listed below, B&O is Computer Systems (Bryant and O'Hallaron), K&R is The C Programming Language (Kernighan and Ritchie), and EssentialC is a PDF available at http://cslibrary.stanford.edu/101. A digital copy of K&R is available to Stanford students via Safari Books Online. Code from lecture will be posted to the class directory in /afs/ir/class/cs107/samples/lectN
where N is the lecture number.
SCPD posts lecture recordings a few hours after live capture at myvideosu.stanford.edu.
Topics | Reading/Handouts | |
---|---|---|
Week 1 | ||
Lecture 1 (Mon): Welcome Join us for an overview of what to expect in CS107. We'll go through course logistics, learning goals, a tour of some surprising realities about modern systems Slides |
Course overview handout B&O Ch 1 (skim chapter for quick overview of what is meant by systems and preview of topics to come) Tron video from class Fun read: Systems programmers and zombies (name really says it all) |
|
No lab during first week (office hours available for help with assign0, see calendar) | UNIX quick study guide by CS107 alumna Allison Yuen | |
Lecture 2 (Fri): Transitioning to C A whirlwind tour of C for C++ programmers using the unix environment. Slides |
Brush up on C syntax, data types, operators, control structure, function calls. K&R Ch 1, 2, 3 (skip sections on arrays until next lecture) or EssentialC sections 1, 2, 4 |
|
Week 2 | ||
Lecture 3 (Mon): C pointers & arrays Now it's time for the tricky parts of C, including use of * and &, arrays and pointers, pointer arithmetic. Slides VIDEO |
K&R Ch 1.6, 5.1-5.5 or Essential C section 3 on mechanics of pointers and arrays. Pay special attention to the relationship between arrays and pointers and how pointers/arrays are passed as parameters. | |
Lab 1: C programming under Unix Hands-on practice with C and writing a simple version of a Unix command |
K&R (1.9, 5.5, Appendix B3) or Essential C section 3 for C-strings and string.h library functions. C-strings are primitive compared to Java/C++ strings, take note of the manual efforts required for correct use and pitfalls to avoid. Peruse our Mercurial and gdb tool guides. | |
Lecture 4 (Fri): More on pointers Follow-up on C-strings after this week's lab, trying to tease out the minute differences between arrays/pointers (while reinforcing ways they are the same), introduce dynamic memory with malloc and free, and compare/contrast stack and heap (malloc) allocation. One tricky issue to work through is pointers to pointers (poin[ter]-ception!). Slides |
K&R 5.6-5.9 (skim parts on multi-d arrays) | |
Week 3 | ||
Lecture 5 (Mon): void* , generic functions Pointer typecasts, untyped void* pointers, and how used for generic behavior. Function pointers and use as client callbacks. Writing generic functions, being a client of generic functions.Slides |
K&R 5.11 (function pointers). There isn't much new reading for void* , be prepared for further application of mechanics of pointers, arrays, and pointer arithmetic to manipulating pointers of indeterminate type. |
|
Lab 2: C memory Examining pointers/arrays, using/writing C generics, using tools to understand and debug memory |
Our Valgrind and gdb tool guides | |
Lecture 6 (Fri): Function Pointers and Callbacks Resolve any open issues on void* . Callback functions (function pointers). Slides |
K&R 2.9 | |
Week 4 | ||
Lecture 7 (Mon): Introduce data representation of the Integer family of types char, short, int, long, unsigned binary, hexadecimal, and two's complement integer representation. Slides |
For integers, B&O Ch 2.1-2.3 (skim the formal proofs, but important to take away solid working knowledge of two's complement and behaviors of integer operations). This is important reading to have done before lecture/lab! | |
Lab 3: Bits and bytes Hands-on practice with bits and integers |
||
Lecture 8 (Fri): More bits and bytes Truncation and sign extension. Mixed signed and unsigned comparison operations. Bitwise operators and using bytes as collections of booleans. Slides |
B&O Rest of Ch.2. | |
Week 5 | ||
Lecture 9 (Mon): IEEE Floating Point You've learned how integers are represented (in the C data types char, short, int, long), now we take a look at real numbers (in the C data types float and double). We will use a fictional data type--the "mini-float"--as an example. This is not a C type, but uses the same principles as full float and double IEEE representation within fewer bits so it is easier to practice with. Slides |
B&O Ch 3.4 on data layout and access, 3.5 on ALU ops, 3.6 on control structures. There is a lot of detail in these sections, especially when absorbing the assembly, but resist the temptation to skim. It is key to get a solid foundation on these basics which requires following the assembly closely and working the self-test exercises to be sure you have it down. | |
Lab 4: Floats Hands-on float dissection |
MIDTERM #1 THURSDAY | |
Lecture 10 (Fri): Intro to AMD64, data movement Representation of pointers, structs, instructions. Introduce assembly/machine language and find out what's happening underneath the hood of the C compiler. The AMD64 instruction set architecture and its almighty mov instruction. Addressing modes, data layout, and access to variables of various types. Slides |
B&O 3.1-3.3 for background info on AMD64 and machine code. Very carefully read B&O 3.4 on addressing modes and data transfer. The multitude of addressing modes is one of the things that puts the C in CISC for AMD64. Handy CS107 AMD64 Guide |
|
Week 6 | ||
Lecture 11 (Mon): Data layout and access, ALU ops Relate remaining addressing modes to their use in accessing C variables/pointers/arrays/structs. Then it's on to the arithmetic and logical ops. We'll be tracing through much assembly code in these lectures. By having done the reading before lecture, you'll be in a better position to follow along without getting lost. Slides |
B&O Ch 3.4 on data layout and access, 3.5 on ALU ops. There is a lot of detail in these sections, especially when absorbing the AMD64 assembly, but resist the temptation to skim. It is key to get a solid foundation on these AMD64 basics which requires following the assembly closely and working the self-test exercises to be sure you have it down. | |
Lab 5: AMD64 AMD64 in all its glory |
IMPORTANT REFERENCE: Our AMD64 guide | |
Lecture 12 (Fri): Control Implementing if-else and loops (for/while/do-while) and two implementations for switch statements. Slides |
B&O Ch 3.6 on control structures and switch. | |
Week 7 | ||
Lecture 13 (Mon) Caller/callee protocol for function calls, parameter passing, call/return, and management of stack housekeeping. Use this understanding to explore stack features: why recursion works, locals are cheap, how variable arguments work, and caller/callee-saved registers. Slides VIDEO |
B&O 3.7 | |
Lab 6: Dissecting the runtime stack One of my favorites of all the labs-- lots of fun explorations with the stack! |
||
Lecture 14: Build process Exploring the steps of taking C code to an executable: preprocessor, compiler, assembler, linker. These steps are often collectively referred to as "the compiler" in CS106 and other settings, but we'll drill down on the details. Slides |
B&O Ch 7 (skip 7.12 on PIC) | |
Week 8 | ||
Lecture 15 (Mon): Code optimization What optimizing compilers do and don't do. Explore transformations such as constant folding, common subexpression elimination, strength reduction, code motion, loop unrolling. Timing tools and profilers to measure code performance. Slides |
B&O 5.1-5.6 and 5.13-5.15, skim 5.7-5.11. | |
Lab 8: Build process Compilation steps, tools for examining executables |
MIDTERM #2 THURSDAY | |
Lecture 16 (Fri): Managing the heap How the heap fits into the address space. Design decisions for implementing malloc/realloc/free. Performance tradeoffs (throughput, utilization). Compare/contrast stack versus heap allocation. Slides |
B&O Ch. 9.9-9.11 covers heap allocation implementation, garbage collectors, and memory misuses. There is a lot of very detailed code in 9.9.12 It's ok to skim this code for now (if you are sure to understand the underlying principles) but you will eventually be assigned the job of writing a heap allocator and will want to be intimately familiar with this code at that point, so making the investment now will pay off later. :-) | |
Week 9 | ||
Lecture 17 (Mon): Memory hierarchy, locality, caching Understanding storage hierarchy (registers -> caches -> memory -> files) and how properties change as you move downward (fast/small/expensive => large/slow/cheap). Temporal and spatial locality of reference and its effect on performance. Caches and writing cache-friendly code. Measuring memory performance using callgrind with cache simulation. Slides |
B&O 5.12, 6.1-6.3 and 6.5-6.7, skim 6.4. The reading gets fairly dense, most important to get big picture. | |
Lab 7: Code and memory optimization Experiments in optimization, profiling |
||
(No lecture--instructor out of town) | TAs will hold office hours in Hewlett 200 during class hours. No lecture. (We got ahead in the usual lecture schedule for the quarter by having Monday holiday replacement lectures, so this lecture can safely be canceled without cutting any topics.) | |
Week 10 | ||
Lecture 18 (Mon): Cache design and processor pipelining A quick taste of some hardware design topics that intersect with our CS107 software topics. Slides |
If these topics intrigue you, take EE108 and/or EE180! | |
Lab 8: Cache design, final exam review | ||
Lecture 20 (Fri): Wrap Wrap up course themes, preview courses/opportunities post-107, and try to reach closure on any loose ends. Bring questions if you have them! |
||
Week 11 | ||
FINAL EXAM Wednesday, March 22nd, 3:30pm - 6:30pm |