Classic Computer Magazine Archive HI-RES VOL. 1, NO. 4 / MAY/JUNE 1984 / PAGE 47

Painless Computing

by T. Lee Kidwell

After purchasing a home computer and beginning to learn its intricacies, the onslaught of new information can be perplexing. New words: RAM, ROM, CPU, operating system. New ways of thinking about numbers: binary, hexadecimal, octal.

This series will show how the computer "thinks" and how to control its "thoughts." By understanding the computer's inner workings, we humans can put this electronic brain to work to serve our purposes.

HI-RES will examine the uses for the myriad of user-friendly, flexible software such as data bases and spread sheets, and explore a program that writes programs.

At the forefront of this series is a look at Beginner's All-purpose Symbolic Instruction Code -- BASIC.

Then there will be side trips to explore such subjects as how to use a disk drive (a matter of considerable interest to Commodore 1541 owners), how to interface a printer to your computer, using a modem, and any other excursions readers of HI-RES may request.

A Computer Is a Tool

An understanding of the uses for a computer and how to control its actions must be taken in the proper perspective -- it is a tool!

A computer is not a magic box that, with one night's work, will organize one's life into an Utopian existence. Nor will a short course at a local college be sufficient to provide the knowledge to write complicated programs.

A computer is simply a tool that will aid in reaching a predetermined end.


Just a Bunch of Switches

To better understand how a computer thinks, one must gain knowledge of the computer's brain and its internal workings.

A computer is merely a series of switches in groups of eight called "bytes." These bytes are arranged in a very logical sequence, each serving some specific purpose. The off/on sequence controls the computer's performance.

The most important group of switches is a series of bytes (a chip) called the central processing unit (CPU). This is the control center of the computer. Any action which takes place in the computer is coordinated by the CPU.

To illustrate, think of the CPU as the control tower of a busy airport. No planes (data) can take off or land (be processed by the computer and put into the bytes) without clearance from CPU tower.

When a pilot requests landing instructions (the computer user presses a key), CPU tower communicates with the pilot and designates a specific runway and landing pattern (a unique pattern of switches is turned on and placed in the proper area of the computer.) CPU tower follows up on these runway assignments to ensure all air traffic is sent to the proper hangar. In the computer, the CPU interprets the pattern of the switches set by the depressed keys and effects the appropriate action (changing of switches in the proper area).

Two Types of Memory

Many of the switches in the computer are commonly known as "memory," of which there are two types -- Random Access Memory(RAM) and Read Only Memory(ROM).

RAM is comprised of switches that are off when the computer is first turned on (initialized). Switches in RAM are turned on by the CPU as necessary when information, such as a BASIC program, is input. As long as power remains on, the unique pattern of off/on switches in RAM will be maintained or remembered. When the power is turned off, all switches in RAM are turned off and any information stored in RAM is sent to never-never land.

For this reason, RAM is known as "volatile" memory. Thus, to store a program or other data, a storage device such as a disk drive or tape drive is needed. When a program is SAVEd, the information in RAM is converted to digital signals and stored on a device much the same as music is recorded on a record or tape. When the information is later LOADed, these signals convert RAM back to the same on/off state, recreating your program or data.

ROM is different from RAM in that it maintains its pattern of off/on switches. ROM switches are preset to come on or remain off when power is applied. ROM cannot be changed. Therefore, the data stored in this type of memory always will remain unchanged. ROM generally is used to permanently store some very important programs in the computer.

Operating System

Switches do not a working computer make! The computer is just a complicated piece of electrical hardware. To perform a meaningful function, this hardware must be programmed by a mere human. In a special part of ROM is just such a program -- the "operating system."

This system is a series of bytes, set to logical patterns, which form a program that controls the operation of the computer. This interprets user input and works in cooperation with the CPU to prompt the computer to perform the proper tasks, such as PRINTing a word on the screen.

A program of this type, which is permanently stored in ROM, is called "firmware," as opposed to "software." Both are programs, but software is normally SAVEd on magnetic storage media (tape or disk) and is INPUT into the computer's RAM as needed.

To understand how RAM, ROM, CPU and the operating system interact, let's investigate how the computer reacts when the user turns it on and types: PRINT "Hello" RETURN.

When power is turned on, the CPU immediately goes to work. The CPU starts by sending control of the action to the operating system. The operating system then performs the initialization procedures, which include such steps as setting the switches in the correct bytes in RAM to determine screen, border, and character colors.

Once all the necessary housekeeping procedures are complete, the operating system routine finishes by printing a prompt on the screen -- usually "READY." This is an indication to the user that the computer is awaiting instructions.

Next, the user types in the command: PRINT "Hello." As this statement is typed, each key is evaluated by the CPU. If the depressed key is a special command key, such as the key to clear the screen, the CPU will send control of the computer to the part of the operating system which contains the "subroutine" (a program within a program) to clear the screen. If the key is a character, such as those in the line being evaluated, the computer will store the keys in RAM as a series of bytes. When the RETURN key is depressed, the CPU evaluates the group of bytes in RAM that have been changed since the last RETURN to determine the keys and take the appropriate action -- in this case, PRINTing the word "Hello" on the video screen.

Yes or No

Before going to the first excursion into BASIC programming, there is one theoretical area still to explore: computer logic. This could be an exceptionally. long trip if sidetracked along all of the side streets such as Binary Boulevard and Boolean Logic Drive. However, for sake of sanity and brevity, take a stroll down Easy to Understand Street.

BASICally speaking, this "bundle of switches" can do one thing: compare one series of switches to another. The programmer must tell it what to do based on whether all switches are set to the same or different patterns, in other words, whether the comparison. is true or false.

That's it, it is simply yes or no. It is amazing how simple the logic is in programming the computer. The excursions into BASIC will reveal statements such as IF THEN. The logic of this statement is simply IF a situation is true, THEN perform a defined function.

There's also the ON GOTO statement. This command allows testing of multiple true/false conditions, simultaneously: ON the results of the test of several conditions, GOTO a designated subroutine and perform the programmed task.

Even statements such as PRINT are evaluated using this logic. The computer is constantly comparing the input from the keyboard to a known factor. In this case the "P" is tested first. Since "P" could be the beginning of the word PRINT, a command the computer has been programmed to respond to, it will test to see if the remainder of the word is "RINT." If yes, the PRINT routine in the operating system will be called by the CPU. If false (such as the word PAINT) another action would be taken.

When designing a program, this true/false logic must be followed.

Organizing Logic

Since the computer is a tool of logic, it is very unforgiving of disorganized logic. Before writing a program, a plan of action should be worked out. These planning steps are sometimes tedious, but will save a great deal of frustration and prove to be well worth the up-front time, taking some of the pain out of computing.

There are five steps which should be taken in the development of a program:

  • Define the task to be accomplished.
  • Outline the solution to the problem (algorithm).
  • Diagram the solution.
  • Enter the program into the computer.
  • Test and debug the program.

Following these steps will force the user to determine an objective before sitting down at the computer to type a disorganized program. The logic will be organized and easy to follow -- an essential element for the test and debug steps.

Workable Task

In defining the task to be accomplished, the user must consider the true/false logic of the computer. A task requiring decisions about numerous gray areas will not be workable. The computer cannot think!

The electronic brain is very good at solving problems that involve manipulating data. For example, organizing a mailing list, tracking and recording financial transactions, and solving complicated mathematical problems would all be feasible tasks. But a task such as deciding where to spend a vacation would be difficult for the computer.

With this in mind, consider some of the tasks you would like to accomplish and the feasibility of performing the tasks on a computer.

Next issue will further explore BASIC and work toward writing a useful program.

Editor's Note: Send correspondence to Painless Computing, HI-RES Magazine, 280 W. Canton Ave., Suite 310, Winter Park, Fla. 32 789.