TAILIEUCHUNG - Lecture Introduction to computing systems (2/e): Chapter 11 - Yale N. Patt, Sanjay J. Patel
Chapter 11 - Introduction to programming in C. This chapter presents the following content: Our objective, bridging the gap, translating high-level language programs, interpretation, compilation, pros and cons, the c programming language, a simple example A. | Chapter 11 Introduction to Programming in C C: A High-Level Language Gives symbolic names to values don’t need to know which register or memory location Provides abstraction of underlying hardware operations do not depend on instruction set example: can write “a = b * c”, even though LC-2 doesn’t have a multiply instruction Provides expressiveness use meaningful symbols that convey meaning simple expressions for common control patterns (if-then-else) Enhances code readability Safeguards against bugs can enforce rules or conditions at compile-time or run-time 11- Compilation vs. Interpretation Different ways of translating high-level language Interpretation interpreter = program that executes program statements generally one line/command at a time limited processing easy to debug, make changes, view intermediate results languages: BASIC, LISP, Perl, Java, C-shell Compilation translates statements into machine language does not execute, but creates executable program performs optimization over multiple statements change requires recompilation can be harder to debug, since executed code may be different languages: C, C++, Fortran, Pascal 11- Compilation vs. Interpretation Consider the following algorithm: Get W from the keyboard. X = W + W Y = X + X Z = Y + Y Print Z to screen. If interpreting, how many arithmetic operations occur? If compiling, we can analyze the entire program and possibly reduce the number of operations. Can we simplify the above algorithm to use a single arithmetic operation? 11- Compiling a C Program Entire mechanism is usually called the “compiler” Preprocessor macro substitution conditional compilation “source-level” transformations output is still C Compiler generates object file machine instructions Linker combine object files (including libraries) into executable image 11- Compiler Source Code Analysis “front end” parses programs to identify its pieces variables, expressions, statements, functions, etc. depends on language
đang nạp các trang xem trước