3.9 Conventions for Writing Programs
in their programming styles. A particular individual may use different styles when programming in different languages. The characteristics of a programming style include the following:
the way you structure or
the algorithms you use to solve common problems;
the instructions or language constructs you choose;
the format and overall appearance of your source program; and
the type of commenting that you
in a program.
To be sure, bookshops and libraries contain books on programming style that offer
to structure and format program source, as well as what language constructs to use or avoid. While not repeating such readily available information, we do wish to make a few general comments about assembly language programming.
Few complex programs are written entirely in assembly language. The exceptions are some critical systems programs and—very importantly, we think—those written for the purpose of learning about an architecture's instruction set. We strongly urge attention to the following goals:
The program must solve the problem at hand.
The program must clearly
both the technique of solution and the details of implementation.
The program must be easy to understand and modify.
These goals require that the program contain good internal documentation. Choose common algorithms and instruction sequences, rather than arcane tricks.
Debugging will be facilitated by using quad words, or occasionally double words, to contain integer
. Although efficiency is admirable, computer memory is cheaper than human labor. Packing data into the smallest possible information units could require unreasonably long instruction sequences for unpacking and data manipulation.
Both in a learning context and in real-world program development, the comments become nearly as important to the program as the instructions. While comments are not executable, they are essential for a program to have a long and useful life, because they enable it to be
In assembly language, virtually
should have a
comment. A comment that merely echoes the opcode and specifiers has no value, because a qualified reader already
that information. A comment adds value when it explains why a particular instruction is used in a particular place. Comments on adjacent lines should work together to tell a story. Blocks of comment lines with no instructions can introduce a routine or separate a large effort into smaller units for better
All of the sample programs in this book
a style where comments, while quite
, clearly convey the intent. This "less is more" approach allows the programs to be printed in portrait instead of landscape orientation on the pages of this book and also
the programs to be displayed in a classroom setting from a
computer display or transparency.