This commit is contained in:
left_adjoint 2024-04-28 13:14:14 -07:00
parent 9af88d50e8
commit 2d9b15a45e
1 changed files with 178 additions and 1 deletions

View File

@ -19,6 +19,37 @@ A really cool example of a patch that massively sped-up TCP because it played wi
+ 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
+ *Practice problem weirdness* okay I literally don't know where a number of the practice problems come from. They're listed as coming from the book with numbers *but* I've checked both the 2nd and 3rd editions of the text and they don't match up with either.
* Discussion prompts
These should all be some kind of small pair programming prompts with the requirement that to get full 4/4 credit you need to
** Module 1
*** Concept: Exercise with bit flags
Consider the program for turning on and off bit flags in Lesson 7 of this module. With your partner write your own program in this style that defines several flags and, from the console, allows you to turn the flags on or off. Get creative with it! Maybe include a flag that prints the menu backwards or in capslock!
** Module 2
*** Concept: Two's complement tutorial
Using what you've learned from writing a program that reads and sets bit flags, write a program that lets someone type in an =int= and then uses a for-loop to print out the two's complement representation of the number *and* to print out what number that bit sequence corresponds to as an unsigned int.
** Module 3
*** Concept: Exploring the limits of floating points
Write a program with your partner that will demonstrate some of the limitations of floating point. An easy idea would be to demonstrate the fact that two =float=-s together doesn't always follow the laws of arithmetic (0.1 + 0.1 might not be 0.2!)
** Module 4
*** Concept: Playing with gcc -S
With your partner write a C program that lets you read in two numbers and then add them together. Compile this code and check to make sure it works. Then generate assembly code from this using the -S option, find the instructions where the numbers are added together, and instead change it to a multiplication *in the assembly*. Check this program compiles and then turn it in! Try also changing your prompt in assembly as well.
** Module 5
*** Concept:
** Module 6
*** Concept: Structs in C and assembly
With your partner write a program that uses both a union and a struct. Generate the corresponding assembly and look at it. Upload the files and explain what you observe about the layout of the data in the corresponding assembly.
** Module 7
With your partner, write a program that
+ reads in an integer, n, from the user
+ and runs a function that recursively forks "left" and "right" processes to a depth of n
+ printing out a message every time a process ends
** Module 8
With your partner write a program that writes a signal handler for SIGALARM and the alarm function to make an alarm clock program that reads from the user and, when the alarm goes off, gives the option to cancel the alarm or "snooze" it. Until the alarm goes off it should print something to signify "sleeping" once a second
** Module 9
** Module 10
Write a program that is intentionally slow and badly written, upload it, and comment on another team's code to figure out how to fix it.
* Quiz writing
Need to write 10 questions on the signal handling section:
@ -145,11 +176,14 @@ Week 10.
8. 8.8 (L7)
** Module 8
There are no practice problems
1. (proposed) 8.5
2. (proposed) 8.7 -- these are going to require massaging to put into the format for the online h5p system
** Module 9
1. 6.2 (L6)
2. 6.3 (L6)
3. 6.4 (L6)
4. 6.5 (L6)
5. (proposed) 6.17
** Module 10
1. 5.1 (L4)
2. 5.2 (L4)
@ -168,11 +202,32 @@ Week 10.
*** 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
+ Text:
#+begin_quote
So a lot of people's first introduction to writing numbers in hex isn't decompiling code or low-level system programming, but dealing with color in art programs! Color, for computers, is generally represented as "24-bit color depth" which means that we're using 24 bits to represent the full RGB color. We do this by splitting the 24-bits into 8-bits for red, 8-bits for green, and 8-bits for blue. Now, what numbers can you represent with 8-bits? 0 -- 255! And if you use two digits of hex, what numbers can you represent? Well that's 0x00, which is 0, through 0xFF which is 15*16 + 15 or 255. So in order to represent a 24bit color we can just write a hex number with six digits! Pure black is then 0x000000, pure white is 0xFFFFFF, and something like teal is 0x39a78e. If you've never played with hex representations of colors check out https://www.color-hex.com/.
#+end_quote
+ Practice problems
+ Problem 2.1
+ Problem 2.6
+ Program examples:
+ Show some small programs that actually use hex syntax for arithmetic
#+begin_src c :tangle attachments/cs201/hex.c
#include <stdio.h> // this is how we are able to call printf
int main(){
int hex1 = 0x1A; // 16 + 10 = 26
int hex2 = 0xFF; // 15*16 + 15 = 255
printf("hex1 in decimal is: %d\n", hex1); // the %d directive prints signed integers in decimal
printf("hex2 in decimal is: %d\n", hex2);
printf("The sum in hex is: 0x%x\n", hex1 + hex2); // the hex directive is %x (or %X if you want UPPERCASE LETTERS)
return 0;
}
#+end_src
*** Lesson 4 - Word and Data Sizes
+ Problem 2.7
+ Content: complete
@ -187,11 +242,131 @@ Week 10.
+ 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
+ Okay this is an example that *works* but it's definitely too complex for a first example and I'd need to write an entire thing about cellular automata
#+begin_src c :tangle attachments/cs201/cellular.c
#include <stdio.h>
// Define constants
#define RULE 30 // The rule number for the cellular automata
#define GENERATIONS 16 // The number of generations to simulate
#define WIDTH 64 // The width of the cellular automata
int main() {
// Declare a long long variable to store the current state of the automata
long long current_state = 1LL << (WIDTH / 2); // Set the initial state with a single cell in the center
// Iterate for the specified number of generations
for (int gen = 0; gen < GENERATIONS; gen++) {
// Print the current state of the automata
for (int i = 0; i < WIDTH; i++) {
// Check each bit of the current state using bitwise AND
// If the bit is set (1), print an asterisk; otherwise, print a space
putchar((current_state & (1LL << i)) ? '*' : ' ');
}
// Move to the next line after printing each generation
putchar('\n');
// Calculate the next state of the automata
long long next_state = 0;
for (int i = 0; i < WIDTH; i++) {
// Get the state of the left neighbor
// If it's the leftmost cell, consider the left neighbor as 0
int left = (i == 0) ? 0 : (current_state & (1LL << (i - 1))) != 0;
// Get the state of the current cell
int center = (current_state & (1LL << i)) != 0;
// Get the state of the right neighbor
// If it's the rightmost cell, consider the right neighbor as 0
int right = (i == WIDTH - 1) ? 0 : (current_state & (1LL << (i + 1))) != 0;
// Apply the rule to determine the new state of the current cell
// The rule is defined by the RULE constant, which represents the outcome
// for each possible combination of the left, center, and right cells
int new_bit = (RULE >> (left * 4 + center * 2 + right)) & 1;
// Set the corresponding bit in the next state using bitwise OR and left shift
next_state |= (long long)new_bit << i;
}
// Update the current state with the next state for the next generation
current_state = next_state;
}
return 0;
}
#+end_src
*** 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
#+begin_src c :tangle attachments/cs201/flagexample.c
#include <stdio.h>
#define MOTOR_ON 1 // mask for 1st bit - 2^0
#define SPEED_LOW 2 // mask for 2nd bit - 2^1
#define SPEED_MEDIUM 4 // mask for 3rd bit - 2^2
#define SPEED_HIGH 8 // mask for 4th bit - 2^3
#define REVERSE 16 // mask for 5th bit - 2^4
void print_menu() {
printf("\nBit Flag Menu:\n");
printf("1. Toggle MOTOR_ON\n");
printf("2. Toggle SPEED_LOW\n");
printf("3. Toggle SPEED_MEDIUM\n");
printf("4. Toggle SPEED_HIGH\n");
printf("5. Toggle REVERSE\n");
printf("0. Exit\n");
}
void print_bit_flag(int bit_flag) {
printf("\nCurrent Bit Flag: %d\n", bit_flag);
printf("MOTOR_ON: %s\n", (bit_flag & MOTOR_ON) ? "ON" : "OFF");
printf("SPEED_LOW: %s\n", (bit_flag & SPEED_LOW) ? "ON" : "OFF");
printf("SPEED_MEDIUM: %s\n", (bit_flag & SPEED_MEDIUM) ? "ON" : "OFF");
printf("SPEED_HIGH: %s\n", (bit_flag & SPEED_HIGH) ? "ON" : "OFF");
printf("REVERSE: %s\n", (bit_flag & REVERSE) ? "ON" : "OFF");
}
int main() {
int bit_flag = 0;
int choice;
do {
print_bit_flag(bit_flag);
print_menu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
bit_flag ^= MOTOR_ON;
break;
case 2:
bit_flag ^= SPEED_LOW;
break;
case 3:
bit_flag ^= SPEED_MEDIUM;
break;
case 4:
bit_flag ^= SPEED_HIGH;
break;
case 5:
bit_flag ^= REVERSE;
break;
case 0:
printf("Exiting...\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 0);
return 0;
}
#+end_src
** Module 2: Integer representation
*** Lesson 1: Integer Data Types
+ Content: complete
@ -392,11 +567,13 @@ Week 10.
+ I think this section needs to be redistributed into lessons 2 and 3
+ Explain what =volatile= and =sig_atomic_flag= mean
+ Recall this later when dealing with *caching* in Module 9
+ (NEW) Proposed practice problem 8.7 (section 8.5) from textbook
*** Lesson 5: Signal Handler Examples
+ Content: needs expansion
+ These are not full examples
+ Need more examples that actually match to the kinds of parent/child relations like in the shoot-out assignment
+ (NEW) Proposed practice problem 8.8 (section 8.5)
** Module 9: Memory systems
Okay I'll be honest I think this entire module is basically just one lesson stretched out. It's a very superficial look at what memory is, the kind of thing that you can explain in 10-15 minutes at a time. We can collapse lessons 1/2/4 into one, 3/5 into one, and then lesson 6 should perhaps get expanded significantly with some actual diagrams and examples.