← Assembly Cookbook for the Apple II/IIe

Assembly Cookbook for the Apple II/IIe

From the originals

13 scans

Machine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.

These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.

PDF page 12

Why You Cotta Learn Assembly Language

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