Download Programming from the Ground Up

Transcript
Table of Contents
1. Introduction............................................................................................................................................1
Welcome to Programming..................................................................................................................1
Your Tools ..........................................................................................................................................1
2. Computer Memory Organization ........................................................................................................5
Post-Office Boxes...............................................................................................................................5
Some Terms........................................................................................................................................5
Interpretting Memory .........................................................................................................................6
Data Accessing Methods....................................................................................................................7
3. Your First Programs..............................................................................................................................9
Entering in the Program .....................................................................................................................9
Outline of an Assembly Language Program ....................................................................................11
A Program that Does Something .....................................................................................................13
Projects.............................................................................................................................................19
4. All About Functions.............................................................................................................................21
Dealing with Complexity .................................................................................................................21
How Functions Work .......................................................................................................................21
Assembly-Language Functions using the C Calling Convention ....................................................23
A Function Example ........................................................................................................................25
Recursive Functions .........................................................................................................................29
Projects.............................................................................................................................................34
5. Dealing with Files.................................................................................................................................35
The UNIX File Concept ...................................................................................................................35
Buffers and .bss .............................................................................................................................35
Standard and Special Files ...............................................................................................................36
Using Files in a Program..................................................................................................................37
Reading Simple Records ..................................................................................................................43
6. Developing Robust Programs .............................................................................................................45
Where Does the Time Go? ...............................................................................................................45
Some Tips for Developing Robust Programs...................................................................................45
Testing ....................................................................................................................................45
Handling Errors Effectively....................................................................................................46
Making Our Program More Robust .................................................................................................46
7. Sharing Functions with Code Libraries ............................................................................................55
Using a Shared Library ....................................................................................................................55
How Shared Libraries Work.............................................................................................................57
Finding Information about Libraries................................................................................................57
Building a Shared Library................................................................................................................61
Advanced Dynamic Linking Techniques .........................................................................................62
8. Intermediate Memory Topics .............................................................................................................63
How a Computer Views Memory.....................................................................................................63
The Instruction Pointer.....................................................................................................................64
The Memory Layout of a Linux Program ........................................................................................64
Every Memory Address is a Lie.......................................................................................................66
iii