Computer Systems Org I - Prof. Grishman
Lecture 24 - Nov. 29, 2005
Notes on assignment #6 (interpreter project)
As programs get larger, good comments are important. Most of the
cost of a large program is maintenance cost, and programs with poor
structure or comments are very hard to maintain.
Most important are comments at the beginning of each function.
You have divided the problem into subproblems through your choice of
functions; you should explain these to the reader of your code
(me and Andrew, in this case). For example, the GNU
coding standard says
Please put a comment on each function
saying what the function does,
what sorts of arguments it gets, and what the possible values of
arguments mean and are used for. ... Also explain the
significance of the return value, if there is one. ... The comment on a
function is much clearer if you use the argument
names to speak about the argument values.
This general practice is followed in most programming languages, but
has been particularly codified in Java through the javadoc program, which
automatically generates Java documentation pages from block comments
preceding classes, methods, and public variables.
Modularity is also important for code maintenance ... if you see
substantial blocks of code repeated several times in your program, it
is a good candidate for a new function.
x86 Architecture, cont'd
A good example of bit manipulation and shifting is binary
multiplication. To multiply two 8-bit numbers X and Y, yielding
product P, the basic algorithm is
repeat 8 times:
if low bit of Y is
non-zero, P += X
shift Y right one bit
shift X left one bit
Another example: counting the 1 bits
I/O on the x86
The original PCs were organized using an 8-bit bus connecting processor, memory,
and I/O devices. The bus structure was standardized by IBM
(ISA: industry standard architecture) so other manufacturers
could build devices which connected to the bus. This bus operated
Faster machines and peripherals have required faster busses. The
8-bit bus was succeeded by the 16-bit AT bus and the 32-bit EISA
bus. Most machines now have a PCI bus (basic capacity, 32 bits,
33 MHz). Even this is not sufficient for high-performance
graphics, so an AGP (Accelerated Graphics Port -- 64 bits, 66 MHz) is
provided for the graphics card.
Unlike the LC-3, the x86 has separate instructions for input and
output. These are IN (for input) and OUT (for output).
These instructions specify a register (AL or AX) and a port number.
As on the LC-3, most programs do not do I/O drectly, but rather rely on
a standard set of I/O routines. The most basic of these are
incorporated into the BIOS (Basic Input-Output System). These
include basic capabilities for keyboard, display, serial and parallel
ports, floppy, and hard disk. The BIOS also includes start-up
(boot) functionality; together these are stored in a ROM or Flash
As on the LC-3, the BIOS routines are not accessed directly by
subroutine calls. Rather they are accessed by interrupts (INT
instruction), the equivalent of the TRAP on the LC-3. For example,
reads one character from the keyboard and returns it in AL.
MOV AH, 14H
writes one character to the display.