Programming the Basic Computer
Computer Systems

Introduction to Computer Systems

A complete computer system includes both hardware and software. Hardware consists of the physical components and all associated equipment, whereas software refers to the programs written for the computer. It is possible to be familiar with various aspects of computer software without concerning oneself with the details of how the computer hardware operates. Conversely, one can design parts of the hardware without knowing its software capabilities. However, those concerned with computer architecture should have a comprehensive understanding of both hardware and software since they influence each other.

Writing Programs for Computers

Writing a program for a computer involves specifying, either directly or indirectly, a sequence of machine instructions. Machine instructions inside the computer form a binary pattern that is difficult, if not impossible, for people to work with and understand. Therefore, it is preferable to write programs using more familiar alphanumeric symbols. Consequently, there is a need for translating user-oriented symbolic programs into binary programs recognized by the hardware.

Program Dependency

A program written by a user may be either dependent or independent of the physical computer that runs it. For example, a program written in standard Fortran is machine-independent because most computers provide a translator program that converts the standard Fortran program to the binary code of the specific computer in use. However, the translator program itself is machine-dependent because it must translate the Fortran program to the binary code recognized by the hardware of the particular computer used.

Elementary Programming Concepts

This section introduces some elementary programming concepts and demonstrates their relation to the hardware representation of instructions. The initial part presents the basic operation and structure of a program that translates a user's symbolic program into an equivalent binary program. The discussion emphasizes the key concepts of the translator rather than the details of actually producing the program itself. The usefulness of various machine instructions is then demonstrated through several basic programming examples.

The instruction set of the basic computer, whose hardware organization was explored in a previous chapter, is used in this section to illustrate many of the techniques commonly used to program a computer. This allows us to explore the relationship between a program and the hardware operations that execute the instructions.

Basic Computer Instruction Set

The 25 instructions of the basic computer are divided into memory-reference instructions and register-reference and input-output instructions. A memory-reference instruction has three parts: a mode bit, an operation code of three bits, and a 12-bit address. The first hexadecimal digit of a memory-reference instruction includes the mode bit and the operation code, while the other three digits specify the address. In an indirect address instruction, the mode bit is 1 and the first hexadecimal digit ranges from 8 to E. In a direct mode, the range is from 0 to 6. The other 18 instructions have a 16-bit operation code. The code for each instruction is listed as a four-digit hexadecimal number. The first digit of a register-reference instruction is always 7, and for an input-output instruction, it is always F.

Instruction Set

SymbolHexadecimal CodeDescription
AND0 or 8AND M to AC
ADD1 or 9Add M to AC, carry to E
LDA2 or ALoad AC from M
STA3 or BStore AC in M
BUN4 or CBranch unconditionally to m
BSA5 or DSave return address in m and branch to m + 1
ISZ6 or EIncrement M and skip if zero
CLA7800Clear AC
CLE7400Clear E
CMA7200Complement AC
CME7100Complement E
CIR7080Circulate right E and AC
CIL7040Circulate left E and AC
INC7020Increment AC
SPA7010Skip if AC is positive
SNA7008Skip if AC is negative
SZA7004Skip if AC is zero
SZE7002Skip if E is zero
HLT7001Halt computer
INPF800Input information and clear flag
OUTF400Output information and clear flag
SKIF200Skip if input flag is on
SKOF100Skip if output flag is on
IONF080Turn interrupt on
IOFF040Turn interrupt off

Machine Language

A program is a list of instructions or statements that direct the computer to perform a required data-processing task. There are various types of programming languages that one may write for a computer, but the computer can execute programs only when they are represented internally in binary form. Programs written in any other language must be translated to the binary representation of instructions before they can be executed by the computer. Programs written for a computer may be in one of the following categories:

  1. Binary Code: A sequence of instructions and operands in binary that list the exact representation of instructions as they appear in computer memory.
  2. Octal or Hexadecimal Code: An equivalent translation of the binary code to octal or hexadecimal representation.
  3. Symbolic Code: The user employs symbols (letters, numerals, or special characters) for the operation part, the address part, and other parts of the instruction code. Each symbolic instruction can be translated into one binary-coded instruction by a special program called an assembler. This type of symbolic program is referred to as an assembly language program.
  4. High-level Programming Languages: Special languages developed to reflect the procedures used in problem-solving rather than being concerned with computer hardware behavior. An example is Fortran, which employs problem-oriented symbols and formats. The program is written in a sequence of statements in a form that people prefer when solving a problem. Each statement must be translated into a sequence of binary instructions before execution. The program that translates a high-level language program to binary is called a compiler.

Binary, Octal, and Hexadecimal Programs

Strictly speaking, a machine language program is a binary program. Due to the simple equivalency between binary and octal or hexadecimal representation, it is customary to refer to octal or hexadecimal codes as machine language. Similarly, due to the one-to-one relationship between a symbolic instruction and its binary equivalent, an assembly language is also considered a machine-level language.

Example Programs

Below is an example of a binary program for adding two numbers:

LocationInstruction Code
0000010 0000 0100 (2004)
0010001 0000 0101 (1005)
0100011 0000 0110 (3006)
0110111 0000 0001 (7001)
1000000 0101 0011 (0053)
1011111 1111 1110 (FFE9)
1100000 0000 0000 (0000)

Here is the same program in symbolic code:

LocationInstructionComments
000LDA 004Load first operand into AC
001ADD 005Add second operand to AC
002STA 006Store sum in location 006
003HLTHalt computer
0040053First operand
005FFE9Second operand (negative)
0060000Store sum here

Assembly Language Program

The following is an assembly language program for adding two numbers:

ORG 0
LDA A        / Load operand from location A
ADD B        / Add operand from location B
STA C        / Store sum in location C
HLT          / Halt computer
A, DEC 53    / Decimal operand
B, DEC -23   / Decimal operand
C, DEC 0     / Sum stored in location C
END          / End of symbolic program

The equivalent Fortran program for adding two integer numbers is:

INTEGER A, B, C
DATA A, 53
DATA B, -23
C = A + B
END

In this example, the Fortran program is translated by a compiler into a binary program that the computer can execute. The compiler assigns memory locations for the variables and converts the arithmetic operation into a sequence of binary instructions.