Book
Collection
Click for Table of Contents
© 2025 by Rance D. Necaise
C Primer for Python Programmers
Copyright © 2025
Rance D. Necaise

1.3 Computer Programs

The hardware of a computer is essentially useless without software to provide instructions to tell the processor what to do. Software consists of a program and the data processed by the program. A computer program (or program) is a sequence of instructions to be performed by a computer. A program is written in a particular programming language, which is a formal notation for constructing the sequence of instructions.

Terminology
Terminology
computer programming

The process of planning a sequence of steps for a computer to follow or execute.

A programming language is comprised of special words and symbols and a set of rules that specifies how the words and symbols are combined to form instructions or statements. A programming language is defined by its syntax and semantics. The syntax of a language is the set of strict rules that dictate exactly how the symbols and special words of the language can be combined to form instructions. The rules must be strictly adhered to in order to create a valid program. The semantics specifies what will happen or what is the result when a valid statement is executed. Programming languages are generally unambiguous in their semantics. That is, there is one, and only one, interpretation of a valid statement.

Terminology
Terminology
program statement

An instruction or group of instructions in a programming language.

There are many different programming languages available for use today. All programming languages can be categorized into one of the three main groups: machine language, assembly language, and high-level languages. These groups mirror the historical development of computer languages over the years.

Machine Language

Even though most processors perform the same types of operations, they are each designed to work with a specific set of instructions or computer architecture. For that reason, a program specifically written to be executed by the Intel processor as used on many desktop computers can not be executed by the ARM processor commonly found in mobile devices.

As an electronic device, a processor can only interpret electrical signals represented by two values, on and off, which humans normally notate as the values 1 and 0. Thus, the instructions performed by a processor, known as machine code, are specified as a sequence of binary digits. This means the processor understands a unique binary language, and no other. The machine code instructions are executed by the digital circuits in the processor.

An individual machine language instruction can perform only a simple task. For example, an instruction may load a value from memory and store it into a register or add two values stored in registers and store the result back into a register. Consider the simple arithmetic expression below

y = x × a + x × b

Assuming the values of the variables have already been loaded into memory and stored into registers, the machine language instructions for performing the actual arithmetic may be represented as

1010011000111011
1010101000011011
1000110010100000

An executable program is a file that contains machine code instructions in binary form that can be executed directly by the processor. When the program is executed, it's loaded into memory where the processor reads the binary instructions, one at a time, interprets them and then carries out the task using its digital circuits.

Assembly Language

Early in the evolution of the modern computer, programmers used machine language to write their programs. The machine code instructions had to be entered by hand for the specific processor on which the program was to be used. Originally, the instructions were entered into the computer using a bank of switches that represented the ones and zeros of an individual instruction. This soon gave way to the use of punch cards and magnetic tape for storing and loading the programs. Either way, this was a very tedious process that was prone to error and resulted in programs that were difficult to read and modify.

In time, assembly languages were developed. An assembly language is a rudimentary programming language that is machine dependent or specific to a particular type of architecture. It provides a symbolic representation for the machine code of the processor. For example, the statement evaluating the mathematical expression from above may be represented in assembly language instructions as

MUL S, X, A
MUL T, X, B
ADD Y, S, T

The assembly language instructions consists of a one-to-one correlation between machine language instructions and assembly language instructions. Most assembly languages also provide pseudo instructions, which allows the assembly language to be expanded to incorporate groups of machine instructions in one assembly language command. The assembly language instructions must be translated into machine code using an assembler.

As with machine language, assembly language instructions can only perform a simple operation. Both assembly language and machine language are considered low-level languages and both are machine dependent.

High-Level Languages

The introduction of assembly language was a huge improvement over the use of machine code, at least from a programmer's perspective. But designing and writing programs was still a tedious and time consuming task. In the late 1950's, computer scientists designed and introduced the first high-level languages, which were far easier to use than assembly language and machine code. A high-level language provides instructions that are expressed in English-like phrases, hide complex hardware details, and allow for structured program designs.

As computer scientists and computer programmers, we prefer to use high-level languages due to their ease of use and portability across processors. For example, suppose we want to evaluate the mathematical expression from above

y = x × a + x × b

Instead of having to remember the machine specific instructions for loading values from memory and storing them in registers and for adding and multiplying the values in the registers, we can write this simple expression using familiar notation. In Python or C, we might implement this expression as follows:

y = x * z + x * b;

Programs written in a high-level language are machine independent. That is, they can be designed and created without knowledge or direct dependence on the instructions of a specific processor. A high-level language program, however, can not be executed directly by a processor. While high-level languages are specified independent of a specific processor, the high-level language instructions, known as the source code, must first be translated into machine code or executed indirectly by another program. In either case, a single high-level language instruction typically translates into multiple machine code instructions, sometimes even hundreds.

Terminology
Terminology
source code

The human readable instructions of a program written in a high-level language.

The instructions that form a high-level language program is called the source code and the text file containing the source code is called a source file.

can be used on different architectures without having to rewrite the program. A programmer can create the program without having to know or depend on the instructions of the given processor.

A program written in a high-level programming language can not be executed directly by a processor. The high-level language instructions

While high-level languages are specified independent of a specific processor, a program written in a high-level language must be translated into machine code or executed indirectly by another program. In either case, a single high-level language instruction typically translates into multiple machine code instructions, sometimes even hundreds.

The human readable instructions of a high-level language is known as the source code. The source code is stored in a regular text file known as the source file or source program. A source file, unlike an executable file, can not be executed directly by a processor. While high-level languages are specified independent of a specific processor, a program written in a high-level language must be translated into machine code or executed indirectly by another program. In either case, a single high-level language instruction typically translates into multiple machine code instructions, sometimes even hundreds.

A program written in a high-level programming language, however, can not be executed directly by a processor. While high-level languages are specified independent of a specific processor, a program written in a high-level language must be translated into machine code or executed indirectly by another program. In either case, a single high-level language instruction typically translates into multiple machine code instructions, sometimes even hundreds.

High-level programming languages an be divided into one of two types, compiled or interpreted. A compiled language is one that must be converted or translated into machine code in order to be executed by a processor.

The instructions of a program written in a high-level language is called source code (or the source program). Source code is stored in a simple text file which becomes the input of the compiler program. The compiler verifies that the instructions adhere to the syntax of the language and produces an executable program that contains machine code specific to a given processor. If the syntax is violated, the source program can not be translated into an executable program. Instead, the compiler will report the violations as syntax errors.

Example

Below is a complete example of a function written in the C programming language that is compiled into MIPS assembly language and then assembled into machine code for a MIPS processor.