This commit is contained in:
left_adjoint 2024-03-03 17:13:36 -08:00
parent 4b76aab196
commit a9d0b99d28
1 changed files with 294 additions and 0 deletions

294
revising201.org Normal file
View File

@ -0,0 +1,294 @@
#+title: revising cs201
#+date: [2023-07-01 Sat 19:19]
#+filetags: :assembly:class:cpp:cs:pcc:
#+identifier: 20230701T191915
* resources
https://thefengs.com/wuchang/courses/cs201/
https://docs.google.com/document/d/1GuMczYrPDQ8X0SfKO3VuuTSJf6yAwlFCYZNsXZqSTMc/edit#heading=h.rc090q9jbwe5
https://online.pcc.edu/d2l/home/387733
https://www.pcc.edu/ccog/cs/201/
* Random notes about development
+ It lists figure 8.26 that shows all possible signals but doesn't include them, which I think is kinda bad for these purposes. Should include figure in the site if its referenced.
+ Module 8 needs a section about user defined signals since they're needed for the homework
+ There should be a section explaining what sig_atomic_t is, what atomic is, and what volatile is
+ This class has zero collaborative learning by default. We should add more explicit pair-programming, debugging, and discussion exercises to it
* Quiz writing
Need to write 10 questions on the signal handling section:
1. The =kill= function is only used for sending the SIGKILL signal to end a process (T/F) [F]
2. What does hitting "ctrl-c" at the terminal due?
a. Immediately stop the foreground process
b. Send an interrupt signal to all processes in the foreground's process group
c.
3. To install a signal handler you need to call the function inside =main= (T/F) [F]
4. In the following code, what is the final value of =ourNum= if you hit ctrl-c three times while the program is running
#+begin_src cpp
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
volatile sig_atomic_t ourNum = 0;
void signal_handler(int sig){
ourNum = ourNum + sig;
}
int main(){
signal(SIGINT, signal_handler);
while(ourNum < 5){
sleep(1);
printf("The current number is: %d \n", ourNum);
}
return 0;
}
#+end_src
5. The only type that is allowed to be shared between a signal handler and your main code is =sig_atomic_t= (T/F) [T]
6. A variable declared with the volatile keyword can be cached (T/F) [F]
7. If you run the following code, what happens if---from another terminal---you type =kill= followed by the process ID printed out at the beginning of the program?
a. The program prints "Caught the signal!"
b. The program sleeps until it prints "Yawn! I'm awake now"
c. The program terminates [x]
d. This program is invalid and has undefined behavior
#+begin_src cpp
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
sigset_t mask;
void handler(int sig){
printf("Caught the signal!\n");
}
int main() {
printf("Hi I'm process %d !\n", getpid());
signal(SIGINT, handler);
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
sigprocmask(SIG_BLOCK, &mask, 0);
sleep(10);
printf("Yawn! I'm awake now\n");
return 0;
}
#+end_src
8. What are good uses of writing a handler for SIGUSR1
a. Letting two processes communicate with each other asynchronously
b. When you w
c.
d.
9.
10.
Week 10.
1. The "time" command reports the total clock time a process takes (T/F) [F]
2. The smaller the stride, the less likely you are to have a cache miss (T/F) [T]
3. GCC is capable of eliminating some kinds of recursive call and turning them into loops (T/F) [T]
4. Can program optimization increase the side of the executable? (T/F) [T]
5. Loop unrolling is
a. When you avoid loops in favor of function calls
b. When you restructure the loop to do multiple iterations per round
c. When the compiler eliminates all loops in the program
d. When you inline all function calls that happen in a loop
* Practice problem matching
** Module 1
1. Problem 2.1 (L3)
2. Problem 2.6 (L3)
3. Problem 2.7 (L4)
4. Problem 2.8 (L5)
** Module 2
1. Problem 2.2 (L3)
2. Problem 2.3 (L3)
3. Problem 2.4 (L3)
4. Problem 2.5 (Module 1 L6)
5. Problem 2.9 (L5)
6. Problem 2.10 (L4)
7. Problem 2.11 (L5)
** Module 3
1. Problem 2.12 (L5)
2. Problem 2.13 (L2)
3. Problem 2.14 (L1)
4. Problem 2.15 (L2)
** Module 4
1. 3.1 (L6)
2. 3.2 (L6)
3. 3.3 (L8-ish) [these two don't entirely correspond]
4. 3.4 (L8-ish)
5. 3.5 (L8)
6. 3.13 (L8)
** Module 5
1. 13.12 (L4)
* Section by section summary
** Module 1: C language and numeric representation
*** Lesson 1 - C++ to C Language
+ Content: complete
+ This maybe should be paginated into multiple lessons rather than just one
+ Program examples: Need more whole programs and worked examples showing how to convert one to the other
+ TODO Find an example from CS 162 that would be good for the worked example, something they would have already seen before
*** Lesson 2 - Information Storage
+ Content: complete
+ This section is extremely tiny
+ Get folded into something else?
*** Lesson 3 - Hexadecimal Numbers
+ Content: mostly complete
+ Need an aside connecting hexadecimal to common applications like encoding colors, one of the most common ways you'll see hex
+ Practice problems
+ Problem 2.1
+ Problem 2.6
+ Program examples:
+ Show some small programs that actually use hex syntax for arithmetic
*** Lesson 4 - Word and Data Sizes
+ Problem 2.7
+ Content: complete
*** Lesson 5 - Byte Ordering
+ Problem 2.8
+ Content: complete
+ TODO Remove reference to tutorial point (replace with wikipedia entry for stability: https://en.wikipedia.org/wiki/Endianness#Networking)
+ TODO Inline the =showbytes.c= file, google doc links in the course content are permissions disaster waiting to happen
*** Lesson 6 - Boolean Algebra
+ Problem 2.5
+ Content: complete
+ TODO Rename it because this isn't actually boolean algebra this is pointwise bit operations :-P
+ Program examples:
+ Cellular automata, because they're fun and creative
*** Lesson 7 - Bit Flags and Masking
+ Content: complete
+ Program examples:
+ Need an actual complete example of turning on and off bits in a bit flag
+ Extend the partial code into a full thing with a TUI so that students can see how it works and play with it
** Module 2: Integer representation
*** Lesson 1: Integer Data Types
+ Content: complete
+ Very short, again, just a single table
+ is this something that should get folded into another section?
*** Lesson 2: Unsigned Integer Encoding
+ Content: complete
+ Very very short
*** Lesson 3: Signed Integer Encoding
+ Practice problems
+ Problem 2.2
+ Problem 2.3
+ Problem 2.4
+ Content: complete
+ Programming examples:
+ Access numbers bit by bit to demonstrate 2s complement
*** Lesson 4: Type Casting
+ Problem 2.10
+ Content: complete
+ Programming examples:
+ Need some exampes of good and bad practices with typecasting, base them off the examples that are in the section but as full code you can run and *see* what happens rather than just reading
*** Lesson 5: Integer Arithmetic
+ Problem 2.9
+ Problem 2.11
+ Content: complete
+ Programming examples:
+ Need to build out actual running examples of the problem with detecting overflow
+ Base them off of the examples but fleshed out into something that can run
** module 3: Floating point
*** Lesson 1: Fractional Binary Numbers
+ Problem 2.14
+ Content: complete
*** Lesson 2: IEEE 754 Floating Point Encoding
+ Problem 2.13
+ Problem 2.15
+ Content: mostly complete
+ There need to be a lot more examples in the text itself, worked out in detail
+ This is a notoriously finicky topic
+ Programming examples:
+ Write an actual example of numerical analysis that demonstrates the utility of having a positive and negative zero
+ Show don't tell
*** Lesson 3: Floating Point Examples
+ Content ???
+ This section lists them as "fractional binary numbers" but they're not they're IEE floating point which is, in fact, different
+ Needs more examples worked out
*** Lesson 4: Floating Point Rounding
+ Content: mostly complete
+ Need to explain *why* you can't properly represent the real numbers on a computer (issues of computability)
+ How do you change the rounding mode of the floating point unit?
*** Lesson 5: Floating Point Operations
+ Problem 2.12
+ Content: complete
+ Programming examples:
+ Needs a few examples of what can go wrong in typecasting
** Module 4: Introduction to object code
*** Lesson 1: Build Process
+ Content: complete
*** Lesson 2: Object Code in gcc
+ Content: complete
+ Activity needed: reading hex dumps of object code
+ Need to show how to compile a hello world file to a .o and then read it in a hex editor, spotting the text "hello world" in the compiled file
*** Lesson 3: Getting Assembly and Machine Code
+ Content: complete
*** Lesson 4: Assembly Code
+ Content: needs expansion
+ This section only gives a few sentences of light description of what assembly code is
+ Would be better with more context before jumping into the mess of register names in the next section
*** Lesson 5: Accessing Data
+ Content: complete
*** Lesson 6: Move Instructions
+ Practice problems
+ 3.1
+ 3.2
+ Content: complete
*** Lesson 7: Push and Pop Instructions
+ Content: complete
*** Lesson 8: Arithmetic Operations
+ Practice problems:
+ 3.3 (sorta, this and 3.4 are about mapping C to generated code)
+ 3.4
+ 3.5
+ 3.13
+ 3.11 (from Module 6 practice problems, similar to 3.3 and 3.4)
+ Content: complete
*** (New) Lesson 9: Worked examples of assembly
This section needs worked, explained, examples of assembly code. There are *no* complete examples in the course site as it exists.
** Module 5: Object code: control
*** Lesson 1: Logical and Shift Operators
+ Content: complete
*** Lesson 2: Accessing the Condition Codes
*** Lesson 3: If Statements
*** Lesson 4: Loop Statements
+ 13.12
*** Lesson 5: Switch Statements
** Module 6: Object code: Procedures and Floating Point
*** Lesson 1: Procedures
*** Lesson 2: Heterogenous Data Structures
+ 3.8
+ 3.9
+ 3.10
*** Lesson 3: Buffer Overflows and Security Issues
*** Lesson 4: Floating Point
** Module 7: Processes
*** Lesson 1: Flow Control
*** Lesson 2: Exceptions
*** Lesson 3: Classes of Exceptions
*** Lesson 4: Exceptions in Linux/x86-64
*** Lesson 5: Processes
*** Lesson 6: Process Control
*** Lesson 7: Examples of Fork
** Module 8: Signal handling
*** Lesson 1: Signals in Linux Systems
*** Lesson 2: Signal Management
*** Lesson 3: Blocking and Unblocking Signals
*** Lesson 4: Writing Signal Handlers
*** Lesson 5: Signal Handler Examples
** Module 9: Memory systems
*** Lesson 1: RAM
*** Lesson 2: Other types of Memory
*** Lesson 3: Accessing Main Memory
*** Lesson 4: Disk Storage
*** Lesson 5: Locality
*** Lesson 6: Memory Hierarchies and Caches
** Module 10: Optimzation
*** Lesson 1: Optimization
*** Lesson 2: gcc Optimization levels
*** Lesson 3: How to measure performance?
*** Lesson 4: How to Optimize Code