CS61C Machine Structures Lecture 2 September 1 2000 Dave Patterson http cs berkeley edu patterson http www inst eecs berkeley edu cs61c cs 61C L2 C intro 1 Patterson Fall00 UCB Review 1 2 15 weeks to learn big ideas in CS E Principle of abstraction used to build systems as layers Pliable Data a program determines what it is Stored program concept instructions are just data Principle of Locality exploited via a memory hierarchy cache Greater performance by exploiting parallelism pipeline Compilation v interpretation to move down layers of system Principles Pitfalls of Performance Measurement cs 61C L2 C intro 2 Patterson Fall00 UCB Review 2 2 Continued rapid improvement in Computing 2X every 1 5 years in processor speed every 2 0 years in memory size every 1 0 year in disk capacity Moore s Law enables processor memory 2X transistors chip 1 5 yrs 5 classic components of all computers Control Datapath Memory Input Output Processor cs 61C L2 C intro 3 Patterson Fall00 UCB Overvie w Review 2 minutes C Pointers 10 min Parameter Passing 8 min Administrivia Break 5 min Computers in the News 3 min C structures 10 Memory Allocation 10 min Conclusion 2 min cs 61C L2 C intro 4 Patterson Fall00 UCB C vs Java Differences C has no objects no classes no superclasses Java method C procedure function Variable Array initialization C sometimes zero sometimes random Java zero Output C printf Java system out print Memory management pointers cs 61C L2 C intro 5 Patterson Fall00 UCB C Pointers Pointer represents a raw memory address more details later in course C variables can have pointer types int x type pointer to an int int x type pointer to a pointer to an int int x y z type pointers to ints int x y z type How create a pointer to store in a variable operator get address of a variable int x type pointer to an int cs 61C L2 C intro 6 Patterson Fall00 UCB C Pointers How create a pointer to store in a variable operator get address of a variable x y y 3 x y 3 y x x y 3 int x y How get a value pointed to dereference operator get value pointed to printf x points to d n x cs 61C L2 C intro 7 Patterson Fall00 UCB C Pointers How change variable pointed to Use dereference operator to left of x 5 x y 5 How get a address of the pointer Why do you want to do this printf x pointer is p n x Closest thing in C to object type in Java void is a type that can point to anything Example linked list in C with pointer to next node and a pointer to the value but not sure what type it is cs 61C L2 C intro 8 Patterson Fall00 UCB C Pointers and Parameter Passing Java and C pass a parameter by value procedure function gets a copy of the parameter so changing the copy cannot change the original 3 x void addOne int x x x 1 4 x int y 3 y 3 addOne y y cs 61C L2 C intro 9 Patterson Fall00 UCB C Pointers and Parameter Passing How get a function to change a value void addOne int x x x x 1 x 3 y int y 3 addOne y y cs 61C L2 C intro 10 4 Patterson Fall00 UCB Administrivia 1 4 Change in TAs new people shuffle sections you asked for it Students who have not taken 61B Will be dropped from class if enrolled or not promoted from wait list If you have taken 61B or the equivalent and you are on the list Petition Michael David Sasson 379 Soda 643 6002 msasson cs to petition today 61B Fall Semester meets in the same room so it can easily add 100 people more sections will be added as needed cs 61C L2 C intro 11 Patterson Fall00 UCB Administrivia 2 4 Instructor David A Patterson patterson cs 635 Soda Hall Hours Wed 1 2 Office Sally Mack smack cs 626 Soda x3 4034 Materials http www inst eecs cs61c Lectures projects labs homeworks on www inst eecs cs61c schedule html Newsgroup ucb class cs61c Text Computer Organization and Design The Hardware Software Interface 2 e cs 61C L2 C intro 12 Patterson Fall00 UCB Administrivia 3 4 Must turn in survey login and attend lab discussion sections to be considered enrolled Go to old and new sections to ask TA s to switch sections Lab exercises are to be done every week in lab section and checked off by your lab TA or turned in at beginning of lab Homework exercises are to be handed in either online or to homework boxes in 283 Soda due on Mondays at noon Projects are larger programming assignments individual and team cs 61C L2 C intro 13 Patterson Fall00 UCB Administrivia 4 4 Course Exams Midterm Wednesday October 25 5 8 PM 1 Pimentel Final Tuesday December 12 5 8 PM 1 Pimentel Class agreed upon punishment for Cheating on Exercises Labs Projects 0 for assignment Cheating on Exams 0 for exam cs 61C L2 C intro 14 Patterson Fall00 UCB Computers in the News Artificial Life Milestone Robots Building Robots For the first time computer scientists have created a robot that designs and builds other robots almost entirely without human help In the short run this advance could lead to a new industry of inexpensive robots customized for specific tasks Mimicking biological evolution the computer added subtracted and changed pieces in the designs At the same time the computer similarly mutated the programming instructions for controlling the robot s movements After each step the computer ran simulations to test the designs keeping the ones that moved well and discarding the failures Some thing we probably can do we www wired com wired archive 8 04 joy html shouldn t do Bill Joy We re on the road to somewhere where there s big golem03 cs i brandeis edu download AutomaticDesign pdf cs 61C L2 C intro 15 issues Patterson Fall00 UCB C Structures vs Java Classes Structure Agglomerations of data like a Java class but no methods attached struct DlistNode struct DlistNode next struct DlistNode prev void item need semicolon in C Now create DlistNode variables struct DlistNode theNode struct DlistNode otherNode next theNode prev item cs 61C L2 C intro 16 next otherNode prev item Patterson Fall00 UCB C Structures vs Java Classes Create pointer to structure as before struct DlistNode nodePtr nodePtr Now can assign to fields theNode next otherNode otherNode prev theNode theNode next prev item cs 61C L2 C intro 17 otherNode next prev item Patterson Fall00 UCB C Memory Management C requires knowing where objects are in memory otherwise don t work as expect Java hides location of objects C has 3 pools of memory Static storage global variable storage basically permanent entire program run not in Java easier to combine no side effects re entry easier The Stack local variable storage debugging info parameters return address location of
View Full Document
Unlocking...