Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

ELEMENTARY PROGRAMMING PRINCIPLES

Definition of terms
Computer Program:
A computer program is a set of coded instructions given to the computer, and represents a logical
solution to a problem. It directs a computer in performing various operations/tasks on the data
supplied to it.
Computer programs may be written by the hardware manufacturers, Software houses, or a
programmer to solve user problems on the computer.
Programming:
Programming is the process of designing a set of instructions (computer programs) which can be
used to perform a particular task or solve a specific problem.
It involves use of special characters, signs and symbols found in a particular programming
language to create computer instructions.
The programming process is quite extensive. It includes analyzing of an application, designing
of a solution, coding for the processor, testing to produce an operating program, and
development of other procedures to make the system function.
The program created must specify in detail the logical steps to be taken & the method of
processing the data input into the computer in order to carry out the specified task.
A computer program performs the following:
1. Accepts data from outside the computer as its input.
2. Carries out a set of processes on the data within the computer memory.
3. Presents the results of this processing as its output, and
4. Stores the data for future use.

Programming Languages:
A programming language is a set of symbols (a language) which a computer programmer uses to
solve a given problem using a computer.
The computer must be able to translate these instructions into machine-readable form when
arranged in a particular sequence or order.

TERMS USED IN COMPUTER PROGRAMMING


Source program (source code)
The term Source program refers to program statements that the programmer enters in the
program editor window, and which have not yet been translated into machine-readable form.
Source code is the code understood by the programmer, and is usually written in high-level
language or Assembly language.

Object code (object program).


The term Object code refers to the program code that is in machine-readable (binary) form.
This is the code/language the computer can understand, and is produced by a Compiler or
Assembler after translating the Source program into a form that can be readily loaded into the
computer.

-1-
LANGUAGE TRANSLATORS
A computer uses & stores information in binary form, and therefore, it cannot understand
programs written in either high-level or low-level languages. This means that, any program code
written in Assembly language or high-level language must be translated into Machine language,
before the computer can recognize & run these programs.
A Translator is special system software used to convert the Source codes (program statements
written in any of the computer programming languages) to their Object codes (computer
language equivalents).
The Translators reside in the main memory of the computer, and use the program code of the
high-level or Assembly language as input data, changes the codes, and gives the output program
in machine-readable code.
In addition, translators check for & identify some types of errors (e.g., Syntax/grammatical
errors) that may be present in the program being translated. They will produce error messages if
there is a mistake in the code.
Each language needs its own translator. Generally, there are 3 types of language translators:
1. Assembler.
2. Interpreter.
3. Compiler.
Note. Interpreters & Compilers translate source programs written in high-level languages to their
machine language equivalents.
Assembler
An assembler translates programs written in Assembly language into machine language that the
computer can understand and execute.
Functions of an Assembler.
1). It checks whether the instructions written are valid, and identifies any errors in the program.
The Assembler will display these errors as well as the complete source and object programs.
If the program has no errors, the job control will let it run immediately, or save the object
program so that it may run it later without translating it again.
2). It assigns memory locations to the names the programmer uses.
E.g., the Assembler keeps a table of these names so that if an instruction refers to it, the
Assembler can easily tell the location to which it was assigned.
3). It generates the machine code equivalent of the Assembly instructions.
Usually, the Assembler generates a machine code only when no errors are detected. Some
of the errors include;
- Typing mistakes.
- Using the wrong format for an instruction.
- Specifying a memory location outside the range 0 – 2047.
Note. The Assembler cannot detect Logic errors. The programmer knows of these errors
only when the program is run & the results produced are incorrect (not what the
programmer expected). The programmer must therefore, go through the program & try to
discover why an incorrect result was being produced.

Interpreter
An interpreter translates a source program word by word or line by line. This allows the CPU to
execute one line at a time.
The Interpreter takes one line of the source program, translates it into a machine instruction, and
then it is immediately executed by the CPU. It then takes the next instruction, translates it into a
machine instruction, and then the CPU executes it, and so on.

-2-
The translated line is not stored in the computer memory. Therefore, every time the program is
needed for execution, it has to be translated.
Compiler
A compiler translates the entire/whole source program into object code at once, and then
executes it in machine language code. These machine code instructions can then be run on the
computer to perform the particular task as specified in the high-level program.
The process of translating a program written in a high-level source language into machine
language using a compiler is called Compilation.
For a given machine, each language requires its own Compiler. E.g., for a computer to be able
translate a program written in FORTRAN into machine language; the program must pass through
the FORTRAN compiler (which must „know‟ FORTRAN as well as the Machine language of the
computer).
The object code file can be made into a fully executable program by carrying out a Linking
process, which joins the object code to all the other files that are needed for the execution of the
program. After the linking process, an executable file with an .EXE extension is generated. This
file is stored on a storage media.
Points to note.
 The job of a Compiler is much more difficult than that of an Assembler in that, a single
statement in a high-level language is equivalent to many machine instructions.
 The format of an Assembly instruction is fairly fixed, while high-level languages give a lot of
freedom in the way the programmer writes statements.
Functions of a compiler.
A Compiler performs the following tasks during the compilation process:
1). It identifies the proper order of processing, so as to execute the process as fast as possible &
minimize the storage space required in memory.
2). It allocates space in memory for the storage locations defined in the program to be
executed.
3). It reads each line of the source program & converts it into machine language.
4). It checks for Syntax errors in a program (i.e., statements which do not conform to the
grammatical rules of the language). If there are no syntax errors, it generates machine code
equivalent to the given program.
5). It combines the program (machine) code generated with the appropriate subroutines from
the library.
6). It produces a listing of the program, indicating errors, if any.
Differences between Compilers and Interpreters
Interpreter Compiler
1. Translates & executes each statement of the 1. Translates all the source code statements at
source code one at a time. once as a unit into their corresponding
object codes, before the computer can
The source code instruction is translated &
execute them.
immediately obeyed by the computer
hardware before the next instruction can be A Compiler translates the entire source
translated. program first to machine code, and then the
(Translation & execution go together). code is executed by the CPU.
(Translation & execution are separate
phases)

-3-
2. Translates the program each time it is 2. Compiled programs (object codes) can be
needed for execution; hence, it is slower saved on a storage media and run when
than compiling. required; hence executes faster than
interpreted programs.
3. Interpreted object codes take less memory 3. Compiled programs require more memory
compared to compiled programs. as their object files are larger.
4. For an Interpreter, the syntax 4. For a Compiler, the syntax errors are
(grammatical) errors are reported & reported & corrected after the source code
corrected before the execution can has been translated to its object code
continue. equivalent.
5. Once the source program has been
5. An Interpreter can relate error messages to translated, it is no longer available to the
the source program, which is always Compiler, so the error messages are usually
available to the Interpreter. This makes less meaningful.
debugging of a program easier when using
an Interpreter than a Compiler.

-4-
Linkers & Loaders
Computer programs are usually developed in Modules or Subroutines (i.e., program
segments meant to carry out the specific relevant tasks). During program translation, these
modules are translated separately into their object (machine) code equivalents.
The Linker is a utility software that accepts the separately translated program modules as its
input, and logically combines them into one logical module, known as the Load Module that
has got all the required bits and pieces for the translated program to be obeyed by the computer
hardware.
The Loader is a utility program that transfers the load module (i.e. the linker output) into
the computer memory, ready for it to be executed by the computer hardware.
Syntax
Each programming language has a special sequence or order of writing characters.
The term Syntax refers to the grammatical rules, which govern how words, symbols,
expressions and statements may be formed & combined.
Semantics
These are rules, which govern the meaning of syntax. They dictate what happens (takes place)
when a program is run or executed.

You might also like