You are on page 1of 36

GS 102 – Computer

Literacy / Fundamentals of
Information Technology
MOD 4 - COMPUTER
LANGUAGES
Learning Objectives
• Introduction to Computer Languages
• Generations of Programming languages
Introduction to Computer Languages
• A programming language allows a programmer to develop the sets of
instructions that constitute a computer program.
• Many different programming languages have been developed, each
with its own unique vocabulary; grammar, and use.
• A programming language is any set of rules that converts strings,
or graphical program elements in the case of visual programming
languages, to various kinds of machine code output.
• Programming languages are one kind of computer language, and are
used in computer programming to implement algorithms.
• Most programming languages consist of instructions for computers.
• There are programmable machines that use a set of specific instructions,
rather than general programming languages.
• Since the early 1800s, programs have been used to direct the behavior of
machines such as Jacquard looms, music boxes and player pianos.
• Thousands of different programming languages have been created, and
more are being created every year.
• Many programming languages are written in an imperative form (i.e., as a
sequence of operations to perform) while other languages use
the declarative form (i.e. the desired result is specified, not how to achieve
it).
Generations of Programming languages
• There are five generations of programming languges:
i. First Generation Languages: These are low-level languages like
machine language.
ii. Second Generation Languages: These are low-level assembly
languages used in kernels and hardware drives.
iii. Third Generation Languages
iv. Fourth Generation Languages
v. Fifth Generation Languages
1. First Generation - Machine Language
• The computers can execute a program written using binary digits only.
• This type of programs is called machine language programs and the
programming language is called machine code.
• Since these programs use only '0's and '1's it will be very difficult for
developing programs for complex problem solving.
• Also it will be very difficult for a person to understand a machine language
program written by another person.
• At present, computer users do not write programs using machine language.
• Also these programs written for execution in one computer cannot be used
on another type of computer. i.e., the programs were machine dependent.
2. Second generation - Assembly Language
• In assembly language mnemonic codes are used to develop program
for problem solving.
• The program given below shows assembly language program to add
two numbers A & B.
• Program Code Description
i. READ A It reads the value of A
ii. ADD B The value of B is added with
A
iii. STORE C The result is stored in C
iv. PRINT C The result in ‘C’ is printed
v. HALT Stop Execution
• Assembly language is designed mainly to replace each machine code
with and understandable mnemonic code.
• To execute an assembly language program it should first be translates
into an equivalent machine language program.
• Writing and understanding programs in assembly language is easier
than that of machine language.
• The programs written in assembly language are also machine
dependent.
• Assembly language is translated into machine code using an
assembler before they can be executed.
What is Assembly Language?
• Each personal computer has a microprocessor that manages the
computer's arithmetical, logical and control activities.
• Each family of processors has its own set of instructions for handling
various operations like getting input from keyboard, displaying
information on screen and performing various other jobs.
• These set of instructions are called 'machine language instruction'.
• Processor understands only machine language instructions which are
strings of 1s and 0s.
• However machine language is too obscure and complex for using in
software development.
• So the low level assembly language is designed for a specific family of
processors that represents various instructions in symbolic code and a
more understandable form.
Advantages of Assembly Language
i. An understanding of assembly language provides knowledge of:
ii. Interface of programs with OS, processor and BIOS;
iii. Representation of data in memory and other external devices;
iv. How processor accesses and executes instruction;
v. How instructions accesses and process data;
vi. How a program access external devices.
Other advantages of using assembly language are:
i. It requires less memory and execution time;
ii. It allows hardware-specific complex jobs in an easier way;
iii. It is suitable for time-critical jobs;
Example of Assembly
• Source code format
• A typical line in assembly language programme might be as follows:
• LOOP: MOV.B r0, #80 ;initialise counter
• This line will be assembled into a single instruction (in this case 11 0000
1000 0000 in binary, or 3080); the assembly language and the machine code
correspond to each other.
• It has four parts;
i. label,
ii. mnemonic,
iii. operand,
iv. comment;
• Not all are present in every line.
1st Part
• The first part (LOOP in this example) is a label ; this is a word, invented by the
programmer, which identifies this point in the program.
• It will be set equal to the value of the address where this instruction is
stored.
• So, for example, if later in the programme there is a statement JMP LOOP, the
assembler programme will replace the label LOOP with the actual value of
LOOP, which is the address at which this instruction is stored.
• (For the assembler to recognise this as a label, the label must begin at the
first character in the line., in some assemblers a colon ":" follows the label) So
if the address at which the instruction is stored is 4F, LOOP takes on the value
4F.
• If LOOP is used later in the programme, the assembler will give it the value
4F.
2nd Part
• The second part is the mnemonic.
• This corresponds to a particular kind of instruction (opcode sent by
the Dispatch Unit).
• The intention is that the word chosen (by the manufacturers) for the
mnemonic is easy to remember, and indicates what the instruction does.
• In this case, the instruction moves a literal value (one byte) into the
register 0, hence MOV.B r0,#80
3rd Part
• The third part of the line is an operand (there may be two); in this
case the operand is the value 80 (in Hex) and the register r0.
4th Part
• The last part of the line is a comment.
• This does not affect the actual instruction at all;
i. it is not part of the instruction, and
ii. is not assembled;
iii. instead it helps the programmer to remember what this part of the
program does.
• The comment is preceded by a semi-colon.
3. Third Generation - High Level
Languages
• In the 1950’s computer manufacturers and user groups started to develop
the high level languages in order to allow application programs, which are
machine independent.
• High level language permits the user to use understandable codes using the
language structure.
• In order to execute a high-level language program, it should be translated
into a machine language either using a compiler or interpreter.
• A third generation (programming) language (3GL) is a grouping of
programming languages that introduced significant enhancements to
second generation languages, primarily intended to make the programming
language more programmer-friendly.
• English words are used to denote variables, programming structures
and commands, and Structured Programming is supported by most
3GLs.

• The high level languages commonly used are:


i. FORTRAN (FORmula TRANslation),
ii. BASIC (Beginner's All-purpose Symbolic Instruction Code),
iii. COBOL (COmmon Business Oriented Language).
iv. The C-family (C, C+, C++, C#, Objective-C) of languages.
• The following program written in BASIC language is to add two given
numbers.
• Program Code Description
10 INPUT A,B To read the value of A&B
20 LET C=A+B A&B are added and the result is stored in C
30 PRINT C Print the value of C
40 END Stop the Execution
Program to display two numbers
Printf ("Enter two integers: ");
scanf("%d %d", &number1, &number2);
• Then, these two numbers are added using the + operator, and the
result is stored in the sum variable.
• Finally, the printf() function is used to display the sum of numbers.
printf("%d + %d = %d", number1, number2, sum);
4. Fourth Generation
• This is a high-level programming language, which is used by database users to
access the database.
• This is also called non-procedural language because just like other
programming languages
• It does not follow any fixed procedure or sequence for execution.
• Instead, it allows users to just pass on the commands in simple English text
that follow simple syntax which can be easily understood by any user like this:
i. create table,
ii. select data,
iii. insert data, etc.
• A 4GL is an aid which the end user or programmer can use to build an
application without using a third generation programming language.
• Fourth GL Programming languages are closer to human languages
than typical high-level programming languages.
• All 4GLs are designed to reduce programming effort, the time it takes
to develop software, and the cost of software development.
• Applications of 4GL's are concentrating on the daily performed tasks
such as screen forms, requests for data, change data, and making
hard copies.
• In most of these cases one deals with Data Base Management
Systems (DBMS).
• Most 4GLs are used to access databases.
• For example, a typical 4GL command is:
• FIND ALL RECORDS WHERE NAME IS "SMITH"
• A popular 4GL is SQL , which is a database language used to create
queries and build database objects.
Advantages of 4GL
i. Now days databases are used everywhere to manage data so 4GL makes
it very easy to create, manage and operate the databases.
ii. A single line command can perform the task.
iii. On the other hand, in other languages, we need to write a series of
commands (sometimes a huge segment) for the same task, in which
syntax and keywords are not easily understandable.
iv. This type of language just focuses on “what is required”.
v. Users need not worry and define “how it needs to be performed”.
vi. It is very easy and simple to use even for beginners or end users.
vii. It reduces overall cost, time, and effort.
Disadvantages of 4GL
i. This language is only database oriented, which means we can use it
for databases only.
ii. This is easy for users but in backend each query executes a
sequence of commands which makes it time consuming. (Not
create that much delay and effect)
Main Components of 4GL
i. Database Language and Queries
ii. Report Generators
iii. Analysis and reporting
iv. GUI creators
v. Mathematical optimization
vi. Spreadsheets
5. Fifth Generation
• 5GL or fifth-generation language is programming that uses a visual or
graphical development interface to create source language that is
usually compiled with a 3GL or 4GL language compiler.
• Microsoft, Borland, IBM, and other companies make 5GL visual
programming products for developing applications in Java, for
example.
• Visual programming allows you to easily envision object-oriented
programming class hierarchies and drag icons to assemble program
components.
Types of Program Translator
• There are three types of program that can translate programming code into
machine understandable form (machine code).
• These are:
1. Assembler
• An assembler is a program that translates assembly code into machine code.
• Since Assembly language is machine dependent each type of computer has
its own assembler.
• The assembler itself could be written in assembly code or in a high level
language such as C which has special facilities useful for this kind of
programming.
2. Compiler
• A compiler is a program that translates high level language
instructions into machine code.
• In short a COMPILER is: the translator of the source code into
computer language.
• First the source code is read into the computer's memory
• Then is will be translated in to a kind of in between code: OBJECT
CODE A program will have many different objects and libraries that
need to be linked together into one (large) executable
• The object code contains information not only on the instructions
given by the programmer but also instruction for the computer about
memory allocation and references towards external locations and sub
routines (libraries).
• The code written by the programmer is called the source code and the
compiled code is called the object code.
3. Interpreter
• This is a program that translates high level source code into object code.
• The interpreter translates one line a time and then executes it.
• During interpretation no object code is produced, and so the program
has to be interpreted each time it is to be run.
• Relative advantages of Compilers and interpreters
• These are the advantages of a compiler over an interpreter:
i. Object code can be saved on disk and run whenever required without
the need to recompile.
ii. In case an error is discovered the source code has to be recompiled
after correcting an error.
iii. Object code executes faster than interpreted code
Relative advantages of Compilers and
interpreters
• These are the advantages of a compiler over an interpreter:
i. Object code can be saved on disk and run whenever required
without the need to recompile.
ii. In case an error is discovered the source code has to be recompiled
after correcting an error.
iii. Object code executes faster than interpreted code
iv. Object code generated by a compiler can be executed with the
absence of a compiler
v. Object code is more secure, as it cannot be read without a great
deal of ‘reverse engineering’.
Advantages of an interpreter over a compiler
i. There is no need to for recompilation each time an error is
discovered
ii. It is easier to partially test and debug programs.
***END***

You might also like