Fall 2018

# assignments

## 1. getting started due Tue Sep 4

• Read chapter 1 in the text, "A tour of computer systems"
• Browse the links on the resources page.
• Browse Norm Matloff's unix and C tutorials (if you need them)

Installing

Writing (submit this through the website, showing what you did.)

• Compile, write, and run the classic "hello world" program in C, as described in the text and at wikipedia: Hello_world_program. You can do this on our remote server, shannon.marlboro.college or on your own machine. Be clear about what you did, how you compiled and ran it, and what ersions of what software you used.
• Write a C program to solve project euler's problem 9 : find a pythagorean triple whose sum is 1000.
• Tell me how all of the stuff above hit you: review? way over the top? somewhere between?

## 2. chap 2 and C practice due Tue Sep 11

• Finish reading through chapter 2, at least the topics we discussed. (The CMU lecture slides may also be helpful.)
• Study the C programs that I showed in class on Thursday.
• Write at least one of these in C:
• Something similar to the the word_list example I showed in class which stores instead a list of (x,y) points in a linked list. It should read the list of points (from user input or a file) and then print it out in reverse order. It should also be made of multiple files (a library and a something that calls it) which compile to one executable, and use struct, malloc, and pointers to allocate the (x,y) points as structs on the heap, along with a pointer to the next in the list.
• Or a program which outputs cyclic variations of a given list. For example if the list is [1,2,3,4], the output would be [1,2,3,4], [2,3,4,1], [3,4,1,2], ...
• Do the following exercises from the text.
• practice problem 2.11 (swap using bit operations) . Explain what's going on.
• practice problem 2.14 (bit and logical operations)
• practice problem 2.23 (byte extraction idioms)
• homework problem 2.60 : implement the "unsigned replace_byte(unsigned x, int i, unsigned char b) function.
• homework problem 2.61 & 2.64 : bit tests without "if" . (And/or do several ways.)
• homework problem 2.76 : implement a robust calloc
• practice problem 2.47 (if we don't do it in class), 5-bit float
• Let me know how easy or hard this material is - should we spend more time on it?

## 3. starting machine code due Tue Sep 18

• Start reading chapter 3 in the text, "Machine Code", at least through 3.4.
• Also check out the 2015 cmu slides "Machine Prog" which summarizes that stuff.
• Also start looking through the x86, gdb, and assembler links (including my old notes) on the resources page.
• Use gdb and objdump to work through some of the examples in the text and/or in my old notes.
• Work through any of the practice problems 3.1 through 3.5 - solutions are in the text.
• Post a summary of your explorations and come to class on Tuesday ready to show, tell, and discuss.

## 4. continue machine code due Tue Sep 25

• Read in the text or other sources the material covered in the "Machine Programming: basics, control, procedures, data" slides.
• Practice working through short C programs using objdump and gdb or similar tools - your choice as to what.

## 5. Bomb Lab ! due Thu Oct 4

Do the CMU bomb lab. The "README" and "Self Study Handout" describe what's to be done.

# On shannon
$wget http://csapp.cs.cmu.edu/3e/bomb.tar$ tar xf bomb.tar
$cd bomb$ ./bomb
Welcome to my fiendish little bomb. You have 6 phases with
which to blow yourself up. Have a nice day!
... you type here ...
BOOM!!!
The bomb has blown up.

• Submit your solution and an explanation of what you did, including references, sources, sample sessions - whatever you think is needed for another student to understand your work.
• For full credit, do this on your own. If you get stuck or need a hint, you may ask me or another student ... but if so you must say so and explicitly cite that as a reference.
• Come to class ready to discuss.
• This one is for a grade based on technical merit and clarity of explanation.
• Submissions past this date will be accepted but for reduced credit since we'll be discussing it in class.

## 6. stack attacks due Thu Oct 11

• Read 3.10 in the textbook.
• Do practice problems 3.46 and 3.48
• Read the "Attack Lab Writeup" from the cmu lab assignments and describe in your own words what you would need to do. (I'm not asking you to do the lab - just to explain what it's all about.

## 7. optimization & memory due Tue Oct 23

• Read chapters 5 (optimization) and 6 (memory).
• Choose at least one practice problem from each chapter to write-up and share in class : one on Thu Oct 17, one on Tue Oct 23.
• Write a C program that does a numerical computation on collections of numbers. Some reasonable choices include
• Multiply two N x N matrices. (See the cache-meories slide for some ideas).
• Find the determinant of an N x N matrix.
• Find the mean and standard deviation of a list of numbers.
• Measure its run time and explore ways to make it run faster as described in the text and discuss. For example,
• compiler optimization flags (i.e. -O1 or -O2 or ...)
• explicitly unrolling loops by doing chunks of the calculation at a time
• breaking the problem into smaller functions
• use gprof to look for bottlenecks (probably after breaking the task into smaller functions)
• "localizing" the data access

## 8. linking & exceptions due Tue Oct 30

• Read chapters 7 (linking) and 8 (exceptions). We won't do much in this class with the material in 7, so you don't need to dive into all the details there. The material in 8, though, is important - do study it. Make sure you understand interrupts, signals, forks, context shifts, and system calls.
• Try one of the three "interpositioning" schemes described in chapter 6 to replace calls to malloc() and free() with your own wrappers in a C program of your choice that allocates and deallocates memory. The word list examples I showed at the begnning of the term would be one choice. Use your wrappers to see if calls to malloc() have matching calls to free() or not.
• Do practice problems 8.3 and 8.7.

## 9. processess, signals, I/O due Tue Nov 6

• Finish reading chapter 8, processes & signals
• Browse chapter 10, I/O
• Do exercises 8.18, 8.20, and practice problem 10.2.
• Look over the writeup & code for the shell lab. Explain what it is asking you to do.
• Start thinking about which one of the labs you'd like to do for a final project ...
• attack lab
• shell lab
• malloc lab

## 10. virtual memory due Tue Nov 13

• Read chapter 9 on virtual memory.
• Do any two of the practice problems, and be ready to share in class.
• Look over the malloc lab and explain how you would implement one of the allocation schemes described in the text. (You don't need to code this, but the more specific you can be the better.)
• Start in on one of the labs for your final project, and give a progress report.

## 11. networks due Tue Nov 20

• Read chapter 11, Network Programming.
• Using the text examples or other sources, write two C programs server.c and client.c which send and receive a message from one to the other using a network connection. Have each of them print to the terminal what they're doing as they do it. You should be able to run the server in the background, then run the client, so that the client and server process both print to the terminal, something like :
 $gcc server.c -o server$ gcc client.c -o client
$./server & Server: listening on port 7890 ...$ ./client
Server: connection established. Sending "Hello!".
Server: exiting.
Client: exiting.


## 12. second lab - presentation due Tue Dec 4

• Present your second lab in class.

## 13. second lab - writeup due Fri Dec 7

• Submit your writeup for a second lab.
• Include a bibliography and an explanation of what you did as well as working code that satisfies the lab's requirements.