[comp.sys.apple2] assembly-language programming

gwyn@smoke.brl.mil (Doug Gwyn) (04/01/91)

In article <Mar.31.04.08.26.1991.23270@remus.rutgers.edu> declan@remus.rutgers.edu (Declan McCullagh/LZ) writes:
>This is rapidly outgrowing comp.sys.apple2; perhaps followups should
>be redirected to a more appropriate newsgroup...

Probably, although there are still some Apple II-specific points to be made.

One of them is that the 65xxx architecture does not very well support code
generation by high-level language compilers, which is one significant
reason for a dramatic difference in SOME applications between a hand-coded
assembly-language routine and a corresponding high-level language routine,
ON THE APPLE II (as opposed to on better processors).  The compiler of
necessity has to assume that it might be called upon to generate code for
a wide range of applications, so (unless it goes through an unreasonable
amount of detailed case analysis) it must use CONVENTIONS that will work
in all cases, for example for management of call frames and function
linkage.  The assembly-language hand coder, on the other hand, often can
take advantage of the SPECIFIC nature of his routine, which will NOT need
to be linked into an arbitrary general environment the way that generic
high-level language object modules could be.  Therefore all sorts of short
cuts can be exploited to shave cycles off execution time.  This is worth
recommending for "bottleneck" code such as animation functions, even when
the bulk of an application is better coded in a high-level language.
However, when there is no need for maximal speed (or, occasionally, code
size reduction), coding in assembler has nothing to recommend it and many
significant practical drawbacks.

It is also perhaps worth remarking that one has to be insane to prefer
coding in assembly language on a RISC architecture, particularly one of
the better ones using wide instruction words to achieve many concurrent
operations per instruction.  Such architectures were designed deliberately
on the premise that their programs would be written in high-level
languages, and that the compiler would be relied upon to perform all the
tedious resource scheduling that is required of programs on such machines.