CS 201 HM COMPUTER SYSTEMS PROGRAMMING HO 1 Handout 1 PSU (11/27/2013) Course Title: Computer Systems Programming, CS 201 CRN: 14481, section 003 Time: Mondays, Wednesdays 10:00 – 11:45 Class Room: UTS 206, Unitus Building 4th Avenue Date first, last class: first class Monday 9/30/2013, last class Wednesday 12/4/2013 Makeup class: Saturday 11/2/2013 10:00 AM building FAB, room 150 Office hours: Mondays and Wednesdays Noon – 1 PM, in classroom or 2nd floor UTS. Also: By phone, via email, and by special appointment face-to-face during term Homework: to be emailed to the grader, cc herb, by the due date before start of class Grader: Sen Zheng, email: zhengsen@pdx.edu TA: Le Tien, email: letien@cs.pdx.edu; Office hour Fridays 1-2 PM Fishbowl Additional TA office hours Wednesdays 2-3 PM and Fridays 2-3 PM Fishbowl Instructor: Dr. Herbert G. Mayer, 503 750-5038 herb@cs.pdx.edu also: herbert.g.mayer@gmail.com Class material: http://web.cecs.pdx.edu/~herb/ → Class Information → CS 201 … Prerequisites: CS 162, good programming skills in some machine-independent language, preferably C, some assembly language knowledge. Recommended texts and required reading: 1. Computer Systems: A Programmer's Perspective, 2nd edition, Bryant and O'Hallaron, B&O, Prentice Hall, ISBN-13: 978-0-13-610804-7, © 2011. Text is not required, but recommended. You are advised to follow the scheduled reading assignments below, labeled RD xx. 2. Also recommended: The C Programming Language, 2nd edition, Kernighan and Ritchie, Prentice Hall, ISBN 0-13-110362-8, © 1988 or newer. 3. Read on-line lecture notes named LN xx, xx standing for the number and title; see Table 3. 4. Read the Unix man pages, also scheduled in Table 3 below. 5. Read: http://www.stroustrup.com/bs_faq2.html#evaluation-order Goals: Introduce computer systems from a software developer’s perspective. Solidify your C language comprehension, and teach some assembly language programming. Show how to measure and improve program performance based on machine architecture. Upon successful completion of this course students can: Describe basic computer system organization including the operating system (processes, files, virtual memory) and underlying hardware (CPU, registers, memory hierarchy). Describe the compilation process and SW components (preprocessing, assembling, compiling, and linking) and the function of object/executable files and shared libraries, as well as basic system utilities such as debuggers. Write C programs to illustrate basic systems programming concepts, including file I/O, system calls, memory management, exception handling and process management. Perform arithmetic in hexadecimal, decimal, octal, and binary notation. Explain internal representation of integer, characters, floating point data types, and of arrays, pointers, and structures. Describe the instruction set architecture for the x86 family, including the arithmetic/logic instructions, registers, memory model and addressing, and control instructions. Explain how high-level programming constructs such as loops and stack-based function calls are implemented in underlying machine code. Explain exceptions, traps, and context switches. Explain the performance impact of hardware features such as pipelining, and architecture principles such as memory locality. Use profiling and timing facilities to identify performance bottlenecks in C programs. 1 HO 1 CS 201 HM COMPUTER SYSTEMS PROGRAMMING HO 1 PSU Course Description: Introduction to computer systems from a software developer’s view. Topics include machine organization and architecture, system programming using C and assembly language; introduction to system programming tools; data representation (bits, bytes, characters, integers, floating point numbers); understanding the flow of control, procedures, and complex data types at machine level; linking and loading; exceptions and interrupts; process control and signals; system calls; file I/O; timing and improving program performance; introduction to memory hierarchy, dynamic memory allocation techniques. Grading and Homework (HW): You can accumulate a total of 1000 points by writing 5 homeworks, each worth 120 points, and writing an in-class Midterm in about week 6 and a Final Exam. Each is worth 200 points. Students who leave a self-addressed, stamped envelope on the day of the Final receive their graded Final paper via US mail. Microsoft assembler: http://msdn.microsoft.com/en-us/library/hb5z4sxd(v=vs.100).aspx is available in the CS computer Lab as part of Visual Studio. Walk up to an available computer and study carefully C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC> ml /? Extra Credit: is a way to improve your grade by up to a half level. Extra Credit is granted for good ideas emailed or expressed in class, for constructive questions and contributions in class, identification of errors in lectures, lecture notes, hand-outs, homework assignment; anything, even the slightest typo –but only pointed out for the first time– is worth some extra credit. As a purely voluntary effort, starting about week 3, students may present extra credit topics in class. Possible topics: Table 1: Suggested Extra Credit Projects; for more detail and topics, see Handout 2 Sample Topics Present “hello world” assembler source, show assembly, linking and execution steps Present Unix “profiling”, use prof or gprof Do system() and fork() work in MS C like they do on Unix? Describe diffs and similarities Present Unix “core” file information Present summary of “Turbo-Boost versus Overclocking” Present summary of “Simultaneous Multi-Threading” Present Unix gdb tool, with sample programs; http://www.gnu.org/software/gdb/ Turning in Homework: Homework must be emailed on time by the due date. Include source files, output files, and if applicable input files, all in raw ASCII text form. Send all in original text form, not processed; i.e. do not send ZIP files, no tar files, do not use any other file processing. Late work will be accepted up to 5 calendar days, but for each day late you lose 10% of the total points for that work. Homework handed in more than 5 days late will not be accepted. Saturdays, Sundays, and holidays count as calendar days. Silver Bullet: each student is allowed to hand in one homework up to 3 calendar days late without deduction; but one single time only! This exception is called the Silver Bullet; it cannot be split and cannot be traded. Students must express pro-actively, if they wish to consume their silver bullet. Scenario 1: Handing in two homeworks late, one a day late, a second two days late, will still result in a late deduction, even though together the delays add up to only 3 days. The silver bullet works on one single late homework only. Scenario 2: If you hand in one homework 4 days late, it is possible to cash-in your silver bullet for 3 days of the 4, and get points deducted only for 1 late day; but this works only one single time. Scenario 3: Consumption of the silver bullet is tracked; so manage it wisely! If at the end of the term you did not consume your silver bullet, you will not get extra credit for non-consumption. 2 HO 1 CS 201 HM COMPUTER SYSTEMS PROGRAMMING HO 1 PSU Table 2: Grade schedule A 90-100% B >= 80% C >=70% D >=60% F <60% The top and bottom 15% in each of the above rubrics create + and – variations of the gardes. Table 3: Order of topics may change during course, based on student preferences Week #, date Deadlines, Reading Material, Key Dates 1. Mon 9/30 Introduction; scope and storage attributes; argc argv envp 1. Wed 10/2 C highlights; read K&R chapter 5.10 argc argv envp; LN 2; RD 3.6; MAN strings 2. Mon 10/7 HW1 Args due; computer organization, registers, memory, CPU; LN 3; RD 5.1–5.5; MAN setenv; MAN system 2. Wed 10/9 parameter passing; LN 18; MAN ulimit 3. Mon 10/14 compiling, linking, external names; C preprocessor; computer taxonomy; LN 4; LN 5; RD 6.1-6.4; MAN shell builtins 3. Wed 10/16 HW2 Parameters due; data formats: int, float, char; integer bases 8 10, hex; LN 6; LN 7; MAN stdlib 4. Mon 10/21 recursion; introducing Microsoft assembler masm; Intel x86 architecture intro; LN 8; RD 8.1-8.4; MAN malloc; MAN time 4. Wed 10/23 data cache design; LN 9; RD 9.1-9.4; MAN getpid(); MAN getppid() 5. Mon 10/28 HW3 Performance due; in-depth Intel x86 architecture; RD 10.6-10.7; LN 10; LN 11; MAN sys/types 5. Wed 10/30 fork() and execve(); LN 12; RD 10.8-10.9; MAN unistd 6. Mon 11/4 LN 13; RD 11.1-11.3; MAN ps 6. Wed 11/6 Midterm in class; RD 11.4-11.6 7. Mon 11/11 No class: School closed for Veterans Day 7. Wed 11/13 No class: Instructor o.o.town; we shall make up time; LN 14; RD 12.112.2 8. Mon 11/18 HW4 Track Cycles via Assembly due; discuss heap space, graph implementation; LN 15 8. Wed 11/20 abort, exceptions; LN 16 9. Mon 11/25 VMM; call, return, nested calls, recursion in asm; LN 17 9. Wed 11/27 LN 19; VMM conclusion 10. Mon 12/2 HW5 Graph due; Cache coherence in MP systems, detail: MESI protocol 10. Wed 12/4 Final in class LN xx means: MAN xx means: RD xx means: you must read the lecture note xx ... from the CS 201 website you must read the Unix man-page for subject xx it is recommended that you read section xx of Bryant and O'Hallaron 3 HO 1