# Assembly Cookbook for the Apple II/IIe — source transcripts, page 2

[Canonical transcript page](https://www.vintageapple.net/transcripts/media/va-assembly-cookbook-foor-the-apple-ii-iie-1984-986489/2)

## Transcribed source material

Machine transcriptions and image descriptions; uncertain copy may be marked [illegible]. Verify against the linked originals. Historical rights remain with the original owners.

These are transcribed excerpts, not the full publications. Open the originals for remaining pages.

### PDF page 12

[Cite this scan](https://www.vintageapple.net/transcripts/media/va-assembly-cookbook-foor-the-apple-ii-iie-1984-986489/2#scan-8135d7490de7c14a88f8dc47ccf894746e4aa80fc8693252ca116f1f09ac9790)

Why You Cotta Learn Assembly Language

Transcribed text:

12   Why   You   Cotta Learn Assembly Language
Golly   gee, Mr. Science.
Actually,   most   compi lers   available   today   will   in fact speed up inter-
preted programs by a factor of two to five. This is   certain ly   a notice-
able   difference and is certainly a very   useful   speedup. But it is nothing
compared   to what experienced   machine language authors can   do
when they attack the same task.
A   compiler   program has to make certain assumptions so that it can
work with   all   possible types of program   input.   Machine   language
authors, on the other hand, are free to optimize their one program to
do w hatever has to be done, as fast, as conveniently, and   as com-
pactly as   possible.   This is the reason w hy you can   always   beat com-
piled   code if you are at   all   into mac hine   language.
Another severe   limitation   of Applesoft   compi lers   is that they   still   end
up using   Applesoft   subroutines. These subroutines may be just plain
wrong   (such as RND), o r   else   may be exc ruciatingly slow   (such as
HPLOT).   Hassles   like   these are   easily   gotten aroun d by programming
directly   in machine   language.
Some   machine   language   programs   are   faster   than   others.   Most
often, you end up trading off speed against code length, programming
time, and performance features.
One   way to maximize speed of a machine language program is to
use brute-force   coding,   in which every instruction does its thing in the
minimum possible time, using the fastest possible addressing modes.
Another speed   trick   is   ca lled   table lookup,   w here you   look   up an
answer in a   table,   rather than   calcu lating   it.   One   place where table
lookup   dramatically   speeds things up is in the Apple   II   HIRES   graphics
routines w here you are trying to find the address of a   display   line.   Sim-
ilar table lookups very much quicken trig calculations, multiplications,
and stuff li ke this.
So, our first big adva ntage of machine language is that it is rid icu-
lous ly   faste r than an interpreted high   level   language, and much faster
than a compiled high   level   language.
Size
A   controller   program   for a dumb traffic   light   can   be w ritten   in
machine   language   using   only   a few dozen bytes of code. The same
thing done with   BASIC   statements takes a few hundred bytes of code,
not counting the few thousand bytes of code needed for the   BASIC
interpreter. So, machine language programs often can take up far   less
memory space than   BASIC   programs do.
Now, saving a few bytes of code out of a 64K or 128K address space
may seem like no big   deal.   And, it is often very poor practice to spend
lots of time to save a few bytes of code, particularly if the code gets
sneaky or hard to understand in the process.
But, save a few dozen bytes, and you ca n add fancy sound to your
program . Save a few thousand bytes more, and you can add   HIRES
graphics or even speech. Any time you can shorten code, you can
make room for more performance and more featu res, by using up the
new space you created. Save bunches of code, and you can now do
stuff on a micro that the di no   people   wou ld swear was   impossible.
Three of the ways machine language programs can shorten code
incl ude   using   loops   that use the same code over and over again, using
subroutines   that let the same code be reached from different places in

Reading notes: Several words are split by hyphenation or spacing (e.g., 'compi lers', 'mac hine'); normalized reading may differ from printed form. Source text is truncated mid-sentence at the end.

Printed product names: Applesoft · BASIC · Apple II · HIRES · RND · HPLOT

Languages: English

[Original PDF page 12](https://www.vintageapple.net/files/9d01a190feef4de8f3155bb19972d041cefd95336506c2b403245097a1aad46d/Assembly_Cookbook_foor_the_Apple_II_IIE_1984.pdf#page=12)

[Previous transcribed scans](https://www.vintageapple.net/transcripts/media/va-assembly-cookbook-foor-the-apple-ii-iie-1984-986489/1.md)
