Documents

Bits and Bytes

Description
lessons on bits and byte conversion
Categories
Published
of 11
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Related Documents
Share
Transcript
  1 Computer Architecture and Systems Programming (252-0061-00) Timothy Roscoe Herbstsemester 2012 © Systems Group | Department of Computer Science | ETH Zürich 2 You will have seen… ã Courses:  –  Programming & software engineering  –  Parallel programming  –  Data structures and algorithms ã Languages: Eiffel, Java, C#, … ã Constructs and techniques:  –  Object-orientation  –  Design-by-contract  –  Locks, atomicity, OpenMP, etc. 3 This course covers in depth … ã Programming in C  –  Still   the systems programming language of choice ã Programming in Assembly Language  –  What the machine understands ã What really   happens at the bit-level  –  Machine instructions  –  Memory systems  –  I/O devices ã Basic elements of processor design ã What makes things go fast (and slow) Hold on tight! 4 Course Components ã Lectures  –  Higher level concepts and ideas ã Recitations  –  Applied concepts, important tools and skills for labs, clarification of lectures, exam coverage, C tutorial ã Lab exercises  –  The heart of the course  –  1 week each (sometimes 2 weeks)  –  Provide in-depth understanding of aspects of systems  –  Programming and measurement ã Exam (100% of grade)  –  Test your understanding of concepts 5 Language ã I’ll teach in English (and C…)  –  If I speak too fast, or say something unclear, raise your hand!  –  Please ask questions! ã Assistants’ groups are 5 x German, 2 x English  –  So far… ã Examination:  –  Paper will be in English  –  Answers may be in German or English 6 Logistics ã Lectures here in CAB G.61  –  Tuesday, Wednesday 10:00 – 12:00 ã Recitations – very important!  –  Thursday 13:00 – 15:00, IFW various rooms  –  Learn C, simulator, tools  –  Briefings for Lab exercises  –  Knowledge needed for exams, but not in the lectures! ã There will  be a session this Thursday  –  Sign up sheets at the front of the room today  –  Check the course web page on Wednesday    7 More logistics ã Web site: http://www.systems.ethz.ch/courses/fall2012/SPCA   –  Lecture notes should appear in advance on web site  –  The notes are not intended to be understood without lectures… ã Procedure for answering additional questions: 1.Ask your friends 2.Check the web 3.Ask your teaching assistant 4.Ask another   teaching assistant 5.Email me (troscoe@inf.ethz.ch) 8 Acknowledgements ã Course based on CS 15-213 at Carnegie Mellon University  –  Lots of material gratefully borrowed from CMU ã New material: multicore, devices, etc.  –  All my fault    9 Textbooks ã Randal E. Bryant and David R. O’Hallaron,  –  “Computer Systems: A Programmer’s Perspective”, 2 nd  edition, Prentice Hall 2010.  –  http://csapp.cs.cmu.edu ã Brian Kernighan and Dennis Ritchie,  –  “The C Programming Language, Second Edition”, Prentice Hall, 1988 Key book for the course! 10 Motivation ã Most CS courses emphasize abstraction  –  Abstract data types (objects, contracts, etc.)  –  Asymptotic analysis (worst-case, complexity) ã These abstractions have limitations  –  Often don’t survive contact with reality  –  Especially in the presence of bugs  –  Need to understand details of underlying implementations 11 Goals ã Become more effective programmers  –  Find and eliminate bugs efficiently  –  Understand and tune for program performance ã Prepare for later systems classes at ETHZ  –  Compilers, Operating Systems, Networks, Computer Architecture, Embedded Systems 12 “Systems” as a field ã Encompasses:  –  Operating systems  –  Database systems  –  Networking protocols and routing  –  Compiler design and implementation  –  Distributed systems  –  Cloud computing & online services ã On and above hardware/software  boundary  13 You are here: Software Hardware Processor design Digital design, electrical engineering Systems Programming and Computer Architecture Computational Science Visual Computing Computer Security Etc. Systems topics 14 Lecture 1: Introduction, Bits and Bytes Computer Architecture and Systems Programming (252-0061-00) Timothy Roscoe Herbstsemester 2012 © Systems Group | Department of Computer Science | ETH Zürich 15 Motivation: 5 realities 16 Reality #1: int’ s are not integers. float’ s are not real numbers. 17 int s are not integers, float s are not reals ã Is x 2        –  floats: Yes!  –  ints: ã  40000 * 40000     ã  50000 * 50000     ã                 –  unsigned & signed ints: Yes!  –  floats: ã  (1e20 + -        ã  1e20 + (-        http://xkcd.com/571 18 /* Kernel memory region holding user-accessible data */#define KSIZE 1024charkbuf[KSIZE];/* Copy at most maxlenbytes from kernel region to user buffer */intcopy_from_kernel(void *user_dest,intmaxlen) {/* Byte count lenis minimum of buffer size and maxlen*/intlen= KSIZE < maxlen? KSIZE : maxlen; memcpy(user_dest,kbuf,len);return len;} Code security example ã Similar to code found in a version of FreeBSD’s implementation of getpeername ã There are legions of smart people trying to find vulnerabilities in programs  19 Typical usage /* Kernel memory region holding user-accessible data */#define KSIZE 1024char kbuf[KSIZE];/* Copy at most maxlen bytes from kernel region to user buffer */int copy_from_kernel(void *user_dest, int maxlen) {/* Byte count len is minimum of buffer size and maxlen */int len = KSIZE < maxlen ? KSIZE : maxlen; memcpy(user_dest, kbuf, len);return len;}#define MSIZE 528voidgetstuff() {char mybuf[MSIZE];copy_from_kernel(mybuf, MSIZE); printf(“%s\n”,mybuf);} 20 Malicious usage /* Kernel memory region holding user-accessible data */#define KSIZE 1024charkbuf[KSIZE];/* Copy at most maxlenbytes from kernel region to user buffer */intcopy_from_kernel(void *user_dest,intmaxlen) {/* Byte count lenis minimum of buffer size and maxlen*/intlen= KSIZE < maxlen? KSIZE : maxlen; memcpy(user_dest,kbuf,len);return len;}#define MSIZE 528voidgetstuff() {char mybuf[MSIZE];copy_from_kernel(mybuf,-MSIZE);. . .} 21 Computer arithmetic ã Does not generate random values  –  Arithmetic operations have important mathematical properties ã Cannot assume all “usual” mathematical properties  –  Due to finiteness of representations  –  Integer operations satisfy “ring” properties ã Commutativity, associativity, distributivity  –  Floating point operations satisfy “ordering” properties ã Monotonicity, values of signs ã Observation  –  Need to understand which abstractions apply in which contexts  –  Important issues for compiler writers and serious application programmers 22 Reality #2: You’ve Got to Know Assembly 23 You’ve got to know assembly ã Chances are, you’ll never write program in assembly  –  Compilers are much better & more patient than you are ã But: understanding assembly is key  to machine-level execution model  –  Behavior of programs in presence of bugs ã High-level language model breaks down  –  Tuning program performance ã Understand optimizations done/not done by the compiler ã Understanding sources of program inefficiency  –  Implementing system software ã Compiler has machine code as target ã Operating systems must manage process state  –  Creating / fighting malware ã x86 assembly is the language of choice! 24 Assembly code example ã Time Stamp Counter  –  Special 64-bit register in Intel-compatible machines  –  Incremented every clock cycle  –  Read with rdtsc  instruction ã Application  –  Measure time (in clock cycles) required by procedure double t;start_counter();P();t = get_counter(); printf( P required %f clock cycles\n , t);
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x