The Best of Creative Computing Volume 2 (published 1977)

Page 27 << PREVIOUS >> NEXT Jump to page:
Go to contents Go to thumbnails
This book is also available for the Kindle

Beyond BASIC (Assemblers, Binary Numbers)

graphic of page

vocabulary, or "instruction set," is greatly increased; a
typical mini may have 70 or more functional instructions
which it understands, including the familiar add, subtract,
multiply and divide. New capabilities here include such
things as "shifting" numbers left or right, or "comparing"

two numbers to determine if one is bigger, smaller, or the
same as the other.

Another significant difference is in the amount of
memory available. Our calculator example, above, did not
include memory. Many calculators have one or more
"memory" locations in which a number may be "stored"

and later "recalled" by use of appropriate keys (which
actually add to the instruction set vocabulary of the
calculator.) Computers generally have thousands of such
memory locations which can be used to store not only
numbers (or "data"), but they can also be used to store
instructions so that the entire program can be stored within
the computer.

It is this last fact (program storage) which makes the
computer the powerful instrument it is. With the program
stored inside the computer, the operator need only depress
the "start" or "run" switch and the program can then be
executed at electronic speeds, typically in millions of
instructions per second. Add to this the fact that the
computer can make "decisions" (for example, using a
"compare" instruction, go on to different parts of the program depending on the
results of the comparison) and you
have a good explanation of the power of the computer.

Returning to our previous example, a sequence of minicomputer type instructions
to perform the LET X = A+5
function might be

CLA A
ADD Five
STO X

CLA, ADD and STO are abbreviations (called "mnemonics")
for the full instruction names. For example, CLA could be
"Clear and Add," meaning "clear the working (accumulator) register to zero and
add to it the contents of the
memory location indicated" (in this case, A). ADD would
simply be "add to the accumulator register" without
clearing beforehand, and STO would be "store" the
contents of the working register in the indicated memory
location. Each of the many instructions of the computer has
a similar detailed and precise meaning.

BINARY NUMBERS

In the binary number system, only two symbols
(digits) may be used, 0 (zero) or 1 (one). The decimal
system, on the other hand has ten symbols: O thru 9.

Just as in the decimal system, when counting causes
us to run out of symbols in one column, we carry l into
the next column and start over, the same process
occurs in the binary system. The difference is that a
carry in the decimal system occurs for every count of
ten, while it occurs in the binary system for every
count of two. Therefore, "place values" in the binary
system are powers of 2 (1, 2, 4, 8, 16, etc.) as
compared to place values in the decimal system
which are powers of 10 (1, 10, 100, 1000, etc.).

Conversion from binary to decimal is a simple
process requiring only that the place values corresponding to 1's in the binary
number be added up.

As an example:

64's 0
32's 1
16's 0
8's 1
4's 1
2's 0
1's 1

=

32
8
4
1

45

To complete the picture. we have to now point out that
even the above three instruction program sequence is not
really in machine language. Computers don't normally
understand letters and words such as CLA. In fact,
everything within the machine must ultimately be in the
form of binary numbers, consisting only of combinations of
ones and zeros. This is the fundamental unit of information
within the machine, known as the "bit" (for binary digit).

Memory locations and working registers within a
computer generally contain a fixed number of bits which is
the "word" length of the computer. Minicomputers typically
use 12 or 16 bits per word; alternatively, as few as 8 bits(the
"byte") or as many as 64 bits may be handled at a time. The
significance of word length lies primarily in the magnitude
of the numbers that can be stored in a single word; fewer
bits means smaller numbers or, more important, greater
round off error since, in effect, fewer significant digits can
be saved. Speed is also affected, since a wider word length
usually means that more bits can be processed at one time.

It was mentioned earlier that memory is used to store
both data and the program. Program instructions are stored
in memory words according to precise formats. As an
example, a 16-bit word may be divided into 6 bits for an
"operation code" (specifying the particular instruction to be
performed) and 10 bits for a memory address (the location of
the data to be used). Our CLA A instruction would thus
include a 6-bit code for CLA (it might be 001010) and a 10bit binary address for
the location we chose to call A (this
could be 0000101101 if location 45 were used for A). 3 The
complete machine language instruction would then be:


001010 0000101101
Opcode Address

ASSEMBLERS ...

Once again we are faced with the problem of translating
from the mnemonic (or symbolic) form of instruction into
the numeric machine language form. The computer comes
to the rescue as before with a special translation program
(available from the hardware manufacturer) which
"assembles" machine language programs from the symbolic instructions. An
"assembler" program takes as input
symbolic assembly language source statements and
produces as its output a binary machine language object
program ready for execution. Unlike higher order language
programs which are largely machine independent,
assembly language programs are very machine dependent
since each type computer has its own, generally unique,
machine and assembly language.

In addition to relative machine dependence or independence, there are other
considerations involved in
understanding the differences between compilers and
assemblers. Our example showed that a single BASIC
statement resulted in several assembly language-type
instructions. Each assembly language instruction, on the
other hand, usually causes e single binary machine
language instruction to be generated. It is not uncommon
for a good assembly language programmer to write a program requiring fewer
machine instructions than one
written in a higher order language and compiled into
machine instructions. The assembly language programmer may therefore find that
his program requires less
memory and executes faster. The price paid for this possible
bonus is usually the extra time (and training) required to do
assembly language programming. As compilers become
more efficient, this difference may narrow.

3 See inset box for an explanation of binary numbers.

27

Page 27 << PREVIOUS >> NEXT Jump to page:
Go to contents Go to thumbnails
This book is also available for the Kindle