e451693cd561c6bea2c10e0dd8822637.ppt
- Количество слайдов: 11
ENGR 330: Today’s Class • • More “Clarifications” ? Interrupts – integrating hardware & software C – getting a compiler C – doing it March 2005 R. Smith - University of St Thomas - Minnesota 1
Interrupts • The ‘ask a question’ analogy – Prioritizing • First come first served • Favorites first • Integrating hardware and software – What does the hardware do? – What does the software do? March 2005 R. Smith - University of St Thomas - Minnesota 2
Examples • Where do interrupts get involved? • • • Start “keyboard read” Start “printer output” Start “disk read” Start “disk write” Page interrupt March 2005 R. Smith - University of St Thomas - Minnesota 3
Programming Languages • Compilers vs Interpreters – Perl, Lisp, Basic are usually interpreters – C, Fortran, “classic” languages are compiled • The 3 step process – Code – compile – run • C generates “machine code” – Java produces ‘machine independent bytecodes’ • C is “just a little” above assembly language – You get to play with RAM addresses March 2005 R. Smith - University of St Thomas - Minnesota 4
The C Compiler • Preprocessor – Handles operations with # in column 1 • Compiler – Two phases build and use a symbol table, like assemblers – Phase 1 reads the code and analyzes its structure • Finds syntax errors – Phase 2 generates the actual executable code • Linker – For ‘linking together’ binaries that were compiled separately – Combine a ‘main’ program with library procedures • getchar(), putchar(), println() March 2005 R. Smith - University of St Thomas - Minnesota 5
Getting a C Compiler • They’re all “pretty” standard • We are doing “standard I/O” – No graphics, windows, ad nauseum • If you have one, keep with it • I’ll be using Watcom (University of Waterloo) • Monday’s Assignment: get a compiler and write ‘Hello World’ with it. Hand in a ‘reflection’ on it. March 2005 R. Smith - University of St Thomas - Minnesota 6
Using C • We’ve all taken Java or something, right? • C is Java without objects – Or, with address calculations substituted for objects – Some would say it’s a good trade • Others would compare it with trading a safety razor for a straight razor (or a sharp knife) • The safety razor requires more “infrastructure” • the straight razor is more versatile and more dangerous • Hello World? March 2005 R. Smith - University of St Thomas - Minnesota 7
C weirdnesses • Actual code starts with: int main() { – Like public static int main(String[] args) in java • EVERYTHING Returns a Value – Assignment statements, many procedures, conditionals, etc. • Avoid weird, stupid, and/or dangerous things – – – Increment operators except in selected places Using the result of an assignment statement I won’t use the “assignment operators” • Can’t avoid all such things – Address arithmetic is unavoidable March 2005 R. Smith - University of St Thomas - Minnesota 8
I/O makes a program ‘interesting’ • #include
Inbound Number Conversion • A good exercise – Gets us thinking about the difference between numbers and their representations – We can generalize this to all bases • Num = (Num * Base) + (Next. Char – ‘ 0’) • Just loop till Next. Char isn’t a digit. March 2005 R. Smith - University of St Thomas - Minnesota 10
That’s it. • Questions? Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3. 0 United States License. To view a copy of this license, visit http: //creativecommons. org/licenses/by-sa/3. 0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. March 2005 R. Smith - University of St Thomas - Minnesota 11


