Beyond the Basics

Why Machine Language?

Jim Butterfield

Here is an overview of several important aspects of machine language.

BASIC programmers soon discover that their machines have an "inner code." Somewhere inside, there seems to be another language that is very fast, powerful, and compact. Yet there seems to be no easy way to gain access to this feature; it's not easy to learn, and seems to be bound up with a special kind of machine jargon.

BASIC people often stand in awe of the machine language "gurus." They might be surprised to find that many machine language programmers find BASIC an intimidating language. Such people often find BASIC to be complex, poorly defined, and riddled with obscure syntax rules. Many KIM, SYM and AIM owners are quite nervous when they first meet BASIC - it's such a departure from the precise and (to them) simple machine language that they have learned.

Each language has its own advantages and disadvantages; neither is "better." BASIC is particularly good for scientific and business calculations, especially where a program is changed frequently. Machine language is used where speed is vital; it tends to be used in mechanical environments, especially for hardware interfaces. BASIC programmers tend to be data-oriented, and concentrate their efforts on getting information in and out. Machine language programmers like to work with the innards of the machine, and spend much of their time tinkering with the mechanics. There's room for both types of activity.

Let's compare BASIC and Machine Language to get an idea where each has advantages. Nothing in the following list is absolute: sometimes BASIC can be as fast as machine language; sometimes machine language can be as fast to code as BASIC. But the comparisons are generally valid.

So what do these comparisons tell us?

First, if BASIC can do a job, and can do it fast enough, always use the BASIC. You'll write the program faster, and it will be easier to change in the future.

But if you have a speed problem, or if there's something you need to do that's beyond the capability of BASIC, then use machine language. Remember that with machine language you will lose flexibility and portability. But if that's what you need to do the job, use it.

There are other reasons why it's good to know machine language. It gives you a glimpse of the inner secrets of your computer. Even BASIC itself is just a huge machine language program stored in ROM. Each BASIC statement is executed by dozens of tiny machine language instructions which decide what is wanted and then perform the task. If you wanted to know precisely how a BASIC statement worked, you would ultimately have to trace through the machine language that did the job.

It's probably best to think of BASIC and machine language as complementary tools. You can and should use them together. BASIC can call in a machine language program when it needs it by using a SYS command or a USR function. The machine language code can return to BASIC when it's finished the job by using the RTS code. Data can be passed back and forth between the two languages.

The result: you can have the best of both worlds. The main part of your program will be in BASIC so that you can code it quickly and easily. The tricky bits, where you need speed or special functions, will be in relatively short machine language programs.

Machine language is picky and exacting. It doesn't allow you many mistakes. If you're an impetuous programmer, you might be happier to stay with BASIC, which is very lenient towards your mistakes. But if you're ready to take the time, and plot, scheme, plan, code, check, test and review - you can do some remarkable things with machine language.

It takes precision and patience. But there's nothing to compare with the rush you get when your machine language program finally works the way you planned it.

Return to Table of Contents | Previous Section | Next Section