Thursday, July 14, 2011

PROGRAMMING CONCEPT

PROGRAMMING CONCEPT

The earliest computers

It is an astonishing fact that as we enter the 21st century, computers has been around for less than 60 years. Many of those who worked on the earliest computer are still alive to tell us of their experiences. If you ever get a chance to visit Bletchley Park, don't miss it - it is the location of the breaking of the Enigma code (used by the Germans to code all their most secret messages), with the aid of the first programmable computer, named Colossus, built for this purpose in 1943. A fascinating exhibition the fie story and Colossus has been reconstructed there.

Generations of programming language

Machine language - the first generation

Programming languages are often characterised by 'generation'- The first generation of computer language, known as machine code, executes directly without translation. Machine code is the actual pattern of 0s and 1s used in a computer's memory. The programming of Colossus and other early computers was laboriously done with toggle switches representing a pattern of binary codes for each instruction.
Machine language, however it is entered into a computer, is time-consuming, laborious and error-prone. Few programmers code in it today. A language suited to fie particular application would be used instead.

Assembly code - the second generation

In the 1950s when computers were first used commercially, machine code gave way to assembly code, which allowed programmers to use mnemonics (abbreviations that represent the instructions in a more memorable way) and denary numbers (i-e.0-9) instead of 0s and 1s. Thus ADD or ADX might be an instruction to add two numbers, SIJB or SBX an instruction to subtract.
Programs written in assembly languages have to be translated into machine code before they can be executed, using a program called an assembler-There is more or less a one-to-one correspondence between each assembly code statement and its equivalent machine code statement, which means that programs can be written in the most efficient way possible, occupying as little space as possible and executing as fast as possible. For this reason assembly code is still used for applications where timing or storage space is critical. Assembly languages are called low level languages because they are close to machine code and the detail of the computer architecture.
Since different types of computer have different instruction sets, which depend on how the machine carries out the instructions, both machine code and assembly code are machine-dependent - each type of computer will have its own assembly language.

lmperative high level languages - the third generation

As computer use increased dramatically in the 1950s, the need grew to make it easier and faster to write error-free programs. Computer manufacturers and user groups started to develop so-called high-level languages such as Algol (standing for AlGOrithmic Language) and Fortran (standing for FORmula TRANslation).In the 1950s most of the people actually writing programs were scientists, mathematicians and engineers and so both these languages were created to be used in mathematical applications.
COBOL (Common Business Oriented Language) was invented by the redoubtable Admiral Grace Hopper in 1960 specifically for writing commercial and business, rather than scientific, programs.-Whilst serving in the US Navy in 1947, Grace Hopper was investigating why one of the earliest computers was not working, and discovered a small dead moth in the machine. After removing it (and taping it in her logbook) the machine worked fine, and from then on computer errors were known as 'bugs'.
Other third generation languages followed: BASIC was created in the 1960s as a language for students to learn programming. Early versions of the language however did not contain the facilities to write well-structured programs that were easy to maintain and debug, although the language has since developed. In I97l Nicklaus Wirth designed Pascal (named after the seventeenth century French mathematician) to teach structured programming to students.
High level languages are so-called because they are independent of the architecture of any particular computer; one statement written in a high level language is translated into several machine code instructions before it can be executed. The term imperative high level language refers to languages such as Pascal, BASIC, COBOL and FORTRAN - in contrast to object-oriented and declarative languages, which you will learn about in the second year of this course.

Fourth-Generation programming language

A fourth-generation programming language (4GL) is a programming language closer to human languages than typical high-level programming languages. Such languages arose after the introduction of modern, block-structured third-generation programming languages, which improved the process of software development. Most 4GLs are used to access databases. For example, a typical 4GL command is
SQL > SELECT * FROM tblStudent WHERE gender='Male'
Why use assembly code?
Assembly language, although it is laborious to write and hard to debug, is still used in some circumstances, for example:
  • when there is a need for the program to execute as fast as possible;
  • when the program must occupy as little space as possible;
Parts of an operating system, and device drivers that control the operation of devices such as a printer, mouse or CD-ROM may be written in assembly code. Programs in embedded systems like satellite decoders, encryption and decryption software, and routines that are called frequently from high-level programs may also be written in assembly code.

Types of program translator

There are three types of program used for translating the code that a programmer writes into a form (i.e. machine code) that the computer can execute. These are:
  • assembler
  • compiler
  • interpreter.

Assembler

An assembler is a program that translates an assembly code program into machine code ready for the computer to execute it. Since each type of computer has its own assembly language, it also 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 type of programming.

Compiler

A compiler is a program that translates a high level language program into machine code. The Turbo Pascal compiler, for example, translates a program written in Turbo Pascal on a PC into object code, which can be run on a PC. The code written by the programmer is known as the source code, and the compiled code is known as the object code.
A compiler is a complex program which takes the source code and scans through it several times, each time performing different checks and building up tables of information needed to produce the fina1 object code. When you write a short program, this process appears to happen almost instantaneously, but a long program of several thousand lines can take several minutes to compile.
Compiler: Translates the whole high level language source code into object code, which can then be executed without the presence of a compiler.

Interpreter

An interpreter also translates high-level source code. However the crucial difference between a compiler and an interpreter is that an interpreter translates one line at a time and then executes it; no object code is produced, and so the program has to be interpreted each time it is to be run. If the program performs a section of code 10,000 times, then that section of code is translated into machine code 10,000 times as each line is interpreted and then executed.
Interpreter: Analyses the source code statement by statement as execution proceeds decoding each statement and calling routines to carry out each instruction.

Relative advantages of compilers and interpreters

A compiler has many advantages over an interpreter:
  • the object code can be saved on disk and run whenever required without the need to recompile. However, if an error is discovered in the program, the whole program has to be recompiled.
  • the object code executes faster than interpreted code.
  • the object code produced by a compiler can be distributed or executed without having to have the compiler present.
  • the object code is more secure, as it cannot be read without a great deal of 'reverse engineering'.

An interpreter has some advantages over a compiler:

  • it is useful for program development as there is no need for lengthy recompilation each time an error is discovered.
  • it is easier to partially test and debug programs.
Typically, a programmer might use an interpreter during program development. A program that is tested and ready for distribution would then be compiled and the saved object code would be distributed.

0 comments:

Post a Comment