PROGRAMMING LANGUAGES
Programming languages fall in three broad categories:
1.
Machine Language
2.
Assembly Language
3.
High Level Language
1. Machine Language
The
first-generation programming language, or 1GL, is machine code. It is
sometimes referred to as machine code or object code, machine
language.It is a collection of binary digits or bits that the computer reads and interprets. Machine
language can be directly understood and
obeyed by a machine (computer) without conversion (translation). Hence, Machine languages are the only languages understood by computers.
Each type of
computer has its own machine language which consists of zeros and ones. Program
written in machine language for one computer will not work on another because
of design difference. While easily understood by computers, machine languages
are almost impossible for humans to use because they consist entirely of
numbers. Programmers, therefore, use either a high-level programming language
or an assembly language.
For a machine
language, each unique combination of 1's and 0's in an instruction has a unique
interpretation, including such operations as arithmetical operations,
incrementing a counter, saving data to memory, testing if data has a certain
value, and so on.
2. Assembly Language
The
second-generation programming language, or 2GL, is assembly language. An
assembly language allows the programmer to use all the computer features
through symbolic codes and locations rather than machine codes and binary.
Before an assembly language program can be run on a computer, it must be
converted to machine language using a special program called assembler.
A program
prepared in assembly language will require less storage and less running time
than one prepared in a high level language; an equivalent program in a
high-level language will be more heavyweight. Low-level languages are simple,
but are considered difficult to use, due to the numerous technical details
which must be remembered. Assembly language is much harder to program than high
level languages.
Machine languages are one to one correspondence between language
mnemonics and executable machine instructions. In assembly language, one
symbolic instruction must be written for each machine langue instruction,
however several lines of assembly language are needed to encode one line of a
high-level language program.
3. High Level Language(HLL)
A HLL is much
more powerful programming tool than an assembly language. High level languages
are English oriented language. In assembly language, one symbolic instruction
must be written for each machine langue instruction, but in a high level language,
one statement will produce a multitude of machine language instruction.
A special
program known as compiler is used for translating a high level language program
in to its machine language equivalent program.
Another difference between assembly language
and high level language is that it is impossible to use the assembly language
of one computer on any other computer. This is not the case with high level
languages which are considered problem oriented rather than machine oriented.
One of the first HLLs was FORTRAN which
stands for FORmula TRANslation. It was developed for the IBM 704 by John Backus
and a team of thirteen other programmers at IBM over a three year period (1954-1957).
It was designed to write programs for solving scientific and engineering
problems.
COBOL stands for Common Business Oriented
Language. It was developed in 1959 for solving business computing. It has been
used very successfully for writing programs such as accounting, payroll and
inventory control.
The major advantages of high-level languages
are that they are easy to read and are machine independent. The instructions
are written in a combination of English and ordinary mathematical notation.
Programmers commonly use more English-like languages (called high level languages) such as Basic, C, Java, etc., to write programs which are then translated into machine language (called a low level language) by an assembler, compiler, or interpreter.
BASIC STRUCTURE
OF A C PROGRAM
To introduce the structure of a C program, consider
the following simple program that will print the message:
I love pakistan
The
program may be written as follows:
#include<stdio.h>
#include<conio.h>
void main()
{
printf(“I Love Pakistan”);
getch();
}
The # sign
indicates that this is an instruction for a compiler. <stdio.h> stands
for Standard input output header. One item included in this header is a
declaration of the function printf(). A C program consists of one or more
functions. A function is a set of statements that performs a single well
defined task. A C program cannot run without a main function. Every C program
must have the function main () which is the first section to be executed when
the program runs. The word void before the function main () means that this
function does not return any value and the empty parentheses means it does not
have any arguments.
The body of the
function is surrounded by curly brackets {and}. The left brace indicates the
start of the function and the matching right braces indicates the end of the
body of the function.
The body of the
function in our program consists of a single statement printf( ) which ends
with a semicolon. printf( ) is the standard output function. The text to be
printed is enclosed in double quotes. A statement in C is terminated with a semicolon
(;).
When the
program runs, the string “I Love Pakistan” is printed on the screen.
No comments:
Post a Comment