lecture_13_revised

lecture_13_revised - 1 lecture_13_revised 08:27 David Nicol...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 · lecture_13_revised.txt · 2010-10-05 08:27 · David Nicol Topics -------- - Introduction to C - variables and operators Example- count occurences of a character in a file Ways to do this - Flowchart - machine language - tedious, difficult to read, difficult to write - assembly language - easier than binary - have to manage memory lay-out, register use - remember all those save-restores! - each instruction maps to 1 ISA instruction - C language - uses an abstraction of underlaying hardware - is independent of ISA - very expressive, a little code goes a long ways - uses symbolic names for memory locations, "variables" - is much more readable than assembly code History of C - invented in 1972 by Dennis Ritchie (Bell Labs) to simplify programming a DEC mini-computer - standardized in 1988, ANSI C (American National Standards Institute) - introduces some operators taken directly from the assembly langauge, e.g., x++; // value returned is 'x', then 'x' has 1 added to it --x; // value returned is obtained by subtracting 1 from // x, that subtraction stored in 'x' as well introduces ways of referring to values in locations whose address is stored in a variable - like a LDI instruction y = *x; // variable 'x' holds a memory location, *x is the value // stored at that location, here copied to a variable 'y' More on this later. Much much more. ... Big picture of how things work -- multiple C files can be brought together into one program, including pre-compiled libraries of useful routines Step 1 -- a "Preprocessor" scans the file for preprocessing directives, (prefaced by #) examples -- bring in a file from an "understood" directory #include <stdio.h> -- bring in a file from the same directory as the program is in #include "defs.h" -- selectively include text in the file based on whether -- a symbol was defined #ifdef DEBUG ... #endif -- define a "macro" , sort of like an in-line subroutine #define min(a,b) (a<b?a:b)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 · lecture_13_revised.txt · 2010-10-05 08:27 · David Nicol THE OUTPUT of the preprocessor is C language with no pre-processing
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 11

lecture_13_revised - 1 lecture_13_revised 08:27 David Nicol...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online