PREFACE

Since Ron Cain introduced the original Small C compiler in 1980, interest has grown steadily. Even with today's full featured C compilers, the popularity of Small C remains strong. The reasons are evident. Small C is a self-compiler, it comes complete with source code, it generates readable assembly code, and its single-pass algorithm lets users compile individual statements from the keyboard to the screen as a means of studying the compiler's behavior. Yet, despite its student orientation, it has the feel of a quality compiler and is easily capable of supporting serious development efforts in areas that do not require floating point numbers. Finally, it is perhaps the most thoroughly documented compiler available to the public.

My first book on Small C, The Small C Handbook, was written for the CP/M version of the compiler. Small C made the switch to DOS in 1985 and since then I have refined it repeatedly--especially the code generating and optimizing sections which were rewritten twice--so that the current version is neater, far easier to understand, and generates much better code. The result is that the compiler described here is vastly improved.

This book is more comprehensive than its predecessor in that it treats the internal operation of the compiler; whereas, the Handbook was just that--a handbook for using the compiler. There is even a chapter of suggestions for further development of the compiler that can be used for student assignments.

The general plan of this book comprises three parts. Part 1 is an introduction to the Small C language--an integer/character subset of the C language set forth by Kernighan and Ritchie in The C Programming Language[10]. Since Small C is a subset of C, this material serves as an introduction to the full language. The concepts and syntax are the same, so moving to full C is only a matter of learning additional features. You may begin learning C here without having to face the more advanced features of the language.

Part 2 describes the use of the compiler. The library of standard functions is documented, efficiency considerations are discussed and compatibility with full C is detailed. Finally, the reader is taught how to invoke the compiler and how to compile new versions of the compiler.

Part 3 is a play by play description of the compiler's operation. Both top down and bottom up approaches are taken, with everything coming together in the middle where parsing is done. The run-time library's internal operation is not explained; however, a complete listing is contained in Appendix D.

Appendices are provided that survey the 8086 processor, list the compiler and library, summarize Small C syntax, explain error messages and document differences between this version of the compiler and its predecessor. In addition, there are appendices that index the functions of the compiler and the library; they give each function's source file, its page in the text, and its page in the source listings.

I wish to express sincere appreciation to those who encouraged and assisted me in this work. That necessarily begins with Ron Cain who wrote the original Small C compiler. For his encouragement in writing The Small C Handbook I remain grateful to Marlin Ouverson. For reviewing that manuscript, I am indebted to George Boswell, Hal Fulton, and Jim Wahlman. For his invaluable assistance in reviewing the present manuscript, I wish to thank Tobin Maginnis. To all of those who, over the years, have shared with me their fixes, enhancements, and suggestions I would like to say thanks for sharing in the evolution of Small C. Special thanks goes to Ellen Ablow, Sally Brenton, Michelle Hudun, David Rosenthal, Ann Roskey, Mike Welch and others at M&T for their hard work and cooperation in this project. Finally, to my wife Glenda, who has patiently seen me through yet another Small C book, I express my sincerest appreciation.

James E. Hendrix

Oxford, Mississippi

Go to Introduction