Wednesday, February 4, 2009

FOCP (Fundamental of Computer & Programming)

Computer

Technically, a computer is a programmable machine. This means it can execute a programmed list of instructions and respond to new instructions that it is given. Today, however, the term is most often used to refer to the desktop and laptop computers that most people use. When referring to a desktop model, the term "computer" technically only refers to the computer itself -- not the monitor, keyboard, and mouse. Still, it is acceptable to refer to everything together as the computer. If you want to be really technical, the box that holds the computer is called the "system unit."

Some of the major parts of a personal computer (or PC) include the motherboard, CPU, memory (or RAM), hard drive, and video card. While personal computers are by far the most common type of computers today, there are several other types of computers. For example, a "minicomputer" is a powerful computer that can support many users at once. A "mainframe" is a large, high-powered computer that can perform billions of calculations from multiple sources at one time. Finally, a "supercomputer" is a machine that can process billions of instructions a second and is used to calculate extremely complex calculations.

  • COMPUTER GENERATIONS

You know that the evolution of computer started from 16th century and resulted in the form that we see today. The present day computer, however, has also undergone rapid change during the last fifty years. This period, during which the evolution of computer took place, can be divided into five distinct phases known as Generations of Computers. Each phase is distinguished from others on the basis of the type of switching circuits used.

First Generation Computers

First generation computers used Thermion valves. These computers were large in size and writing programs on them was difficult. Some of the computers of this generation were:

ENIAC: It was the first electronic computer built in 1946 at University of Pennsylvania, USA by John Eckert and John Mauchy. It was named Electronic Numerical Integrator and Calculator (ENIAC). The ENIAC was 30_ 50 feet long, weighed 30 tons, contained 18,000 vacuum tubes, 70,000 registers, 10,000 capacitors and required 150,000 watts of electricity. Today your favorite computer is many times as powerful as ENIAC, still size is very small.

EDVAC: It stands for Electronic Discrete Variable Automatic Computer and was developed in 1950. The concept of storing data and instructions inside the computer was introduced here. This allowed much faster operation since the computer had rapid access to both data and instructions. The other advantages of storing instruction was that computer could do logical decision internally.

Other Important Computers of First Generation

EDSAC: It stands for Electronic Delay Storage Automatic Computer and was developed by M.V. Wilkes at Cambridge University in 1949.

UNIVAC-1: Ecker and Mauchly produced it in 1951 by Universal Accounting Computer setup.

Limitations of First Generation Computer

Followings are the major drawbacks of First generation computers.

1. The operating speed was quite slow.

2. Power consumption was very high.

3. It required large space for installation.

4. The programming capability was quite low.

Second Generation Computers

Around 1955 a device called Transistor replaced the bulky electric tubes in the first generation computer. Transistors are smaller than electric tubes and have higher operating speed. They have no filament and require no heating. Manufacturing cost was also very low. Thus the size of the computer got reduced considerably.

It is in the second generation that the concept of Central Processing Unit (CPU), memory, programming language and input and output units were developed. The programming languages such as COBOL, FORTRAN were developed during this period. Some of the computers of the Second Generation were

1. IBM 1620: Its size was smaller as compared to First Generation computers and mostly used for scientific purpose.

2. IBM 1401: Its size was small to medium and used for business applications.

3. CDC 3600: Its size was large and is used for scientific purposes.

Third Generation Computers

The third generation computers were introduced in 1964. They used Integrated Circuits (ICs). These ICs are popularly known as Chips. A single IC has many transistors, registers and capacitors built on a single thin slice of silicon. So it is quite obvious that the size of the computer got further reduced. Some of the computers developed during this period were IBM-360, ICL-1900, IBM-370, and VAX-750. Higher level language such as BASIC (Beginners All purpose Symbolic Instruction Code) was developed during this period.

Computers of this generations were small in size, low cost, large memory and processing speed is very high.

Fourth Generation Computers

The present day computers that you see today are the fourth generation computers that started around 1975. It uses large scale Integrated Circuits (LSIC) built on a single silicon chip called microprocessors. Due to the development of microprocessor it is possible to place computer’s central processing unit (CPU) on single chip. These computers are called microcomputers. Later very large scale Integrated Circuits (VLSIC) replaced LSICs.

Thus the computer which was occupying a very large room in earlier days can now be placed on a table. The personal computer (PC) that you see in your school is a Fourth Generation Computer.

Fifth Generation Computer

The computers of 1990s are said to be Fifth Generation computers. The speed is extremely high in fifth generation computer. Apart from this it can perform parallel processing. The concept of Artificial intelligence has been introduced to allow the computer to take its own decision. It is still in a developmental stage.

GENERATION OF MICROPROCESSOR

1ST GENERATION MICROPROCESSOR

At the end of 70’s a group of engineers developed a chip capable of processing data. This chip was given the name, processor chip. This LSI/VSI/VVLSI chip, capable of processing data in a controlled manner was called the microprocessor.

The design team headed by Ted Hoff of Intel Corporation developed the 1st such controlled processor in the year 1969, but, Intel started marketing its first microprocessor in the name of Intel 4004 in 1971. This was a 4-bit microprocessor having 16-pins hocused in a single chip of pMOS technology. This was called the 1st generation MP. The 4-bit MP worked with 4-bit word. The Intel 4004 along with few other devices was used for making calculator. The Intel 8008 was developed in the year 1972 that worked with 8-bit word.

MCROPROCESSOR

WORD SIZE

Intel 4004 & 4040

4-bit

FAIRCHILD PPS-25

4-bit

NATIONAL IMP-4

4-bit

ROCKWELL PPS-4

4-bit

MICROSYSTEM

4-bit

INTEL 8008

8-bit

NATIONAL IMP-8

8-bit

ROCKWELL PPS

8-bit

AMI 7200

8-bit

MOSTEK 5065

8-bit


2ND GENERATION MICROPROCESSOR

The 2nd generation MP using nMOS technology appeared in the marked in the year 1973. the Intel 8080 an 8-bit microprocessor of nMOS was develop in the year 1974 which requires only two additional devices (chip) to design a functional CPU. The advantages of 2nd generation microprocessor are:

  1. Large chip size (170 * 200) with 40-pins
  2. More chip on decoding circuits
  3. Ability to address large memory space (64KB) and I/O ports (256)
  4. More powerful instruction set
  5. Dissipate less power
  6. Better interrupt handling facilities.
  7. Cycle time reduced to half (1.3 to 9 n.s)
  8. Less support chips required
  9. Used single power supply

MICROPROCESSOR

WORD SIZE

Intel 8080/8085

8-bit

FAIRCHILD F8

8-bit

NATIONAL CMP-4

8-bit

MOTOROLA 6800

8-bit

RCA COSMAC

8-bit

MOS TECH 6500

8-bit

SIGNETICS 2650

8-bit

ZILOG Z-80

8-bit

INTERSIL 6100

12-bit

Toshiba tlcs-12

12-bit


3RD GENERATION MICROPROCESSOR

The single chip 3rd generation MP having 64-pin started with the introduction of 16-bit Intel 8086 in year 1978. the 16-bit MP using hMOS technology achieved enhanced performance parameters write the 8-bit MP. The memory addressing capabilities were increased 1mb to 16mb through a variety of flexible and powerful addressing modes.

Intel 8088 was identical to 8086 but for the 8-bit data bus. Hence 8088 could read or write 8-bit data at a time to or from the memory. The Intel 80186 was the improved version of Intel 8086 and 8088.


4TH GENERATION MICROPROCESSOR

The single 32-bit MP was introduced in the year 1981 by Intel as Iapx432. The others were; Bell single chip BELLMAC-32, HEWLETE-PACKARD, NATIONAL NSI-6032, TEXAS INSTRUMENT 99000, MOTOROLA 68020 AND 68030.

Most of the MP was manufactured with hMOS (high density short channel MOS) technology because of the following advantages.

  1. Speed power à 4 times greater
  2. Circuit density was approximately 2 times greater

Processor

Year

No. of Transistors

Initial clock Speed

Address Bus

Data Bus

Addressable Memory

4004

1971

2,300

108 kHz

10-bit

4-bit

640 bytes

8008

1972

3,500

200 kHz

14-bit

8-bit

16 k

8080

1974

6,000

2 MHz

16-bit

8-bit

64 k

8085

1976

6,500

5 MHz

16-bit

8-bit

64 k

8086

1978

29,000

5 MHz

20-bit

16-bit

1 M

8088

1979

29,000

5 MHz

20-bit

8-bit*

1 M

80286

1982

1,34,000

8 MHz

24-bit

16-bit

16 M

80396

1985

2,75,000

16 MHz

32-bit

32-bit

4 G

80486

1989

1.2 M

25 MHz

32-bit

32-bit

4 G

Pentium

1993

3.1 M

60 MHz

32-bit

32/64-bit

4 G

Pentium Pro

1995

5.5 M

150 MHz

36-bit

32/64-bit

64 G

Pentium II

1997

8.8 M

233 MHz

36-bit

64-bit

64 G

Pentium III

1999

9.5 M

650 MHz

36-bit

64-bit

64 G

Pentium 4

2000

42 M

1.4 GHz

36-bit

64-bit



P5 (586) Fifth-Generation Processors

Pentium Processor Specifications

Introduced

March 22, 1993 (first generation); March 7, 1994 (second generation)

Maximum rated speeds

60, 66, 75, 90, 100, 120, 133, 150, 166, 200MHz (second generation)

CPU clock multiplier

1x (first generation), 1.5x–3x (second generation)

Register size

32-bit

External data bus

64-bit

Memory address bus

32-bit

Maximum memory

4GB

Integral-cache size

8KB code, 8KB data

Integral-cache type

Two-way set associative, write-back Data

Burst-mode transfers

Yes

Number of transistors

3.1 million

Circuit size

-0.8 micron (60/66MHz), 0.6 micron (75–100MHz), 0.35 micron (120MHz and up)

External package

273-pin PGA, 296-pin SPGA, tape carrier

Math coprocessor

Built-in FPU (floating-point unit)

Power management

SMM (system management mode), enhanced in second generation

Operating voltage

5v (first generation), 3.465v, 3.3v, 3.1v, 2.9v (second generation)

PGA = Pin Grid Array

SPGA = Staggered Pin Grid Array


Itanium (P7/Merced) Seventh-Generation Processors

Itanium

The most current generation of processor is the P6, which was first seen in the Pentium Pro introduced in November of 1995 and most recently found in the latest Pentium II processors. Obviously, then, the next generation processor from Intel will be called the Itanium.

Itanium will have three levels of cache. The L1 cache will be closely tied to the execution unit. It will be backed by on-die L2 cache. Finally the multimega byte L3 cache will be housed in separate chips contained within the cartridge.

Itanium will be followed in late 2001 by a second IA-64 processor code-named McKinley. McKinley will have larger on-die L2 cache and target clock speeds of more than 1.5GHz, offering more than twice the performance of Itanium, according to Intel reps. Following McKinley will be Madison, based on 0.13 micron technology. Both Itanium and McKinley are based on 0.18 micron technology.

  • By Scott Mueller and Mark Edward Soper
  • Jun 8, 2001
  • Article is provided courtesy of Que

TYPES OF COMPUTERS

Now let us discuss the varieties of computers that we see today. Although they belong to the fifth generation they can be divided into different categories depending upon the size, efficiency, memory and number of users. Broadly they can be divided it to the following categories

1. Microcomputer: Microcomputer is at the lowest end of the computer range in terms of speed and storage capacity. Its CPU is a microprocessor. The first microcomputers were built of 8-bit microprocessor chips. The most common application of personal computers (PC) is in this category. The PC supports a number of input and output devices. An improvement of 8-bit chip is 16-bit and 32-bit chips. Examples of microcomputer are IBM PC, PC-AT .

2. Mini Computer: This is designed to support more than one user at a time. It possesses large storage capacity and operates at a higher speed. The mini computer is used in multi-user system in which various users can work at the same time. This type of computer is generally used for processing large volume of data in an organization. They are also used as servers in Local Area Networks (LAN).

3. Mainframes: These types of computers are generally 32-bit microprocessors. They operate at very high speed, have very large storage capacity and can handle the work load of many users. They are generally used in centralised databases. They are also used as controlling nodes in Wide Area Networks (WAN). Example of mainframes are DEC, ICL and IBM 3000 series.

4. Supercomputer: They are the fastest and most expensive machines. They have high processing speed compared to other computers. They have also multiprocessing technique. One of the ways in which supercomputers are built is by interconnecting hundreds of microprocessors. Supercomputers are mainly being used for whether forecasting, biomedical research, remote sensing, aircraft design and other areas of science and technology. Examples of supercomputers are CRAY YMP, CRAY2, NEC SX-3, CRAY XMP and PARAM from India.

:::::::::The following terms related to memory of a computer are discussed below:::::::::

1. Random Access Memory (RAM): The primary storage is referred to as random access memory (RAM) because it is possible to randomly select and use any location of the memory directly store and retrieve data. It takes same time to any address of the memory as the first address. It is also called read/write memory. The storage of data and instructions inside the primary storage is temporary. It disappears from RAM as soon as the power to the computer is switched off. The memories, which loose their content on failure of power supply, are known as volatile memories .So now we can say that RAM is volatile memory.

2. Read Only Memory (ROM): There is another memory in computer, which is called Read Only Memory (ROM). Again it is the ICs inside the PC that form the ROM. The storage of program and data in the ROM is permanent. The ROM stores some standard processing programs supplied by the manufacturers to operate the personal computer. The ROM can only be read by the CPU but it cannot be changed. The basic input/output program is stored in the ROM that examines and initializes various equipment attached to the PC when the switch is made ON. The memories, which do not loose their content on failure of power supply, are known as non-volatile memories. ROM is non-volatile memory.

3. PROM There is another type of primary memory in computer, which is called Programmable Read Only Memory (PROM). You know that it is not possible to modify or erase programs stored in ROM, but it is possible for you to store your program in PROM chip. Once the programmes are written it cannot be changed and remain intact even if power is switched off. Therefore programs or instructions written in PROM or ROM cannot be erased or changed.

4. EPROM: This stands for Erasable Programmable Read Only Memory, which over come the problem of PROM & ROM. EPROM chip can be programmed time and again by erasing the information stored earlier in it. Information stored in EPROM exposing the chip for some time ultraviolet light and it erases chip is reprogrammed using a special programming facility. When the EPROM is in use information can only be read.

5. Cache Memory: The speed of CPU is extremely high compared to the access time of main memory. Therefore the performance of CPU decreases due to the slow speed of main memory. To decrease the mismatch in operating speed, a small memory chip is attached between CPU and Main memory whose access time is very close to the processing speed of CPU. It is called CACHE memory. CACHE memories are accessed much faster than conventional RAM. It is used to store programs or data currently being executed or temporary data frequently used by the CPU. So each memory makes main memory to be faster and larger than it really is. It is also very expensive to have bigger size of cache memory and its size is normally kept small.

6. Registers: The CPU processes data and instructions with high speed, there is also movement of data between various units of computer. It is necessary to transfer the processed data with high speed. So the computer uses a number of special memory units called registers. They are not part of the main memory but they store data or information temporarily and pass it on as directed by the control unit.

SECONDARY STORAGE

Often it is necessary to store hundreds of millions of bytes of data for the CPU to process. Therefore additional memory is required in all the computer systems. This memory is called auxiliary memory or secondary storage. In this type of memory the cost per bit of storage is low. However, the operating speed is slower than that of the primary storage. Huge volume of data are stored here on permanent basis and transferred to the primary storage as and when required. Most widely used secondary storage devices are magnetic tapes and magnetic disk.

1. Magnetic Tape: Magnetic tapes are used for large computers like mainframe computers where large volume of data is stored for a longer time. In PC also you can use tapes in the form of cassettes. The cost of storing data in tapes is inexpensive. Tapes consist of magnetic materials that store data permanently. It can be 12.5 mm to 25 mm wide plastic film-type and 500 meter to 1200 meter long which is coated with magnetic material. The deck is connected to the central processor and information is fed into or read from the tape through the processor. It similar to cassette tape recorder.

Advantages of Magnetic Tape:

Compact: A 10-inch diameter reel of tape is 2400 feet long and is able to hold 800, 1600 or 6250 characters in each inch of its length. The maximum capacity of such tape is 180 million characters. Thus data are stored much more compactly on tape.

Economical: The cost of storing characters is very less as compared to other storage devices.

Fast: Copying of data is easier and fast.

Long term Storage and Re-usability: Magnetic tapes can be used for long term storage and a tape can be used repeatedly with out loss of data.

2. Magnetic Disk: You might have seen the gramophone record, which is circular like a disk and coated with magnetic material. Magnetic disks used in computer are made on the same principle. It rotates with very high speed inside the computer drive. Data is stored on both the surface of the disk. Magnetic disks are most popular for direct access storage device. Each disk consists of a number of invisible concentric circles called tracks. Information is recorded on tracks of a disk surface in the form of tiny magnetic spots. The presence of a magnetic spot represents one bit and its absence represents zero bit. The information stored in a disk can be read many times without affecting the stored data. So the reading operation is non-destructive. But if you want to write a new data, then the existing data is erased from the disk and new data is recorded.

Floppy Disk: It is similar to magnetic disk discussed above. They are 5.25 inch or 3.5 inch in diameter. They come in single or double density and recorded on one or both surface of the diskette. The capacity of a 5.25-inch floppy is 1.2 mega bytes whereas for 3.5 inch floppy it is 1.44 mega bytes. It is cheaper than any other storage devices and is portable. The floppy is a low cost device particularly suitable for personal computer system.

3. Optical Disk:

With every new application and software there is greater demand for memory capacity. It is the necessity to store large volume of data that has led to the development of optical disk storage medium. Optical disks can be divided into the following categories:

1. Compact Disk/ Read Only Memory (CD-ROM): CD-ROM disks are made of reflective metals. CD-ROM is written during the process of manufacturing by high power laser beam. Here the storage density is very high, storage cost is very low and access time is relatively fast. Each disk is approximately 4 1/2 inches in diameter and can hold over 600 MB of data. As the CD-ROM can be read only we cannot write or make changes into the data contained in it.

2. Write Once, Read Many (WORM): The inconvenience that we can not write any thing in to a CD-ROM is avoided in WORM. A WORM allows the user to write data permanently on to the disk. Once the data is written it can never be erased without physically damaging the disk. Here data can be recorded from keyboard, video scanner, OCR equipment and other devices. The advantage of WORM is that it can store vast amount of data amounting to gigabytes (109 bytes). Any document in a WORM can be accessed very fast, say less than 30 seconds.

3. Erasable Optical Disk: These are optical disks where data can be written, erased and re-written. This also applies a laser beam to write and re-write the data. These disks may be used as alternatives to traditional disks. Erasable optical disks are based on a technology known as magnetic optical (MO). To write a data bit on to the erasable optical disk the MO drive's laser beam heats a tiny, precisely defined point on the disk's surface and magnetises it.



::::::: INTERNET :::::::


The Internet is a network of networks. Millions of computers all over the world are connected through the Internet. Computer users on the Internet can contact one another anywhere in the world. If your computer is connected to the Internet, you can connect to millions of computers. You can gather information and distribute your data. It is very much similar to the telephone connection where you can talk with any person anywhere in the world.

In Internet a huge resource of information is accessible to people across the world. Information in every field starting from education, science, health, medicine, history, and geography to business, news, etc. can be retrieved through Internet. You can also download programs and software packages from anywhere in the world. Due to the tremendous information resources the Internet can provide, it is now indispensable to every organisation.


Origin of Internet

In 1969 Department of Defence (DOD) of USA started a network called ARPANET (Advanced Research Projects Administration Network) with one computer at California and three at Utah. Later on other universities and R & D institutions were allowed to connect to the Network. APARNET quickly grew to encompass the entire American continent and became a huge success. Every university in the country wanted to become a part of ARPANET. So the network was broken into two smaller parts MILNET for managing military sites and ARPANET (smaller) for managing non-military sites. Around 1980, NSFNET (National Science Foundation Network) was created. With the advancement of modern communication facilities, other computers were also allowed to be linked up with any computer of NSFNET. By 1990 many computers were looking up to NSFNET giving birth to Internet.


How Internet functions

Internet is not a governmental organisation. The ultimate authority of the Internet is the Internet Society. This is a voluntary membership organisation whose purpose is to promote global information exchange. Internet has more than one million computers attached to it.

E-mail E-mail stands for electronic mail. This is one of the most widely used features of Internet. Mails are regularly used today where with the help of postage stamp we can transfer mails anywhere in the world. With electronic mail the service is similar. But here data are transmitted through Internet and therefore within minutes the message reaches the destination may it be anywhere in the world. Therefore the mailing system is excessively fast and is being used widely for mail transfer.

::::::: WHAT IS LANGUAGE? :::::::

You are aware with the term language. It is a system of communication between you and me. Some of the basic natural languages that we are familiar with are English, Hindi, Oriya etc. These are the languages used to communicate among various categories of persons. But how you will communicate with your computer. Your computer will not understand any of these natural languages for transfer of data and instruction. So there are programming languages specially developed so that you could pass your data and instructions to the computer to do specific job. You must have heard names like FORTRAN, BASIC, COBOL etc. These are programming languages. So instructions or programs are written in a particular language based on the type of job. As an example, for scientific application FORTRAN and C languages are used. On the other hand COBOL is used for business applications.

3.5.1 Programming Languages

There are two major types of programming languages. These are Low Level Languages and High Level Languages. Low Level languages are further divided in to Machine language and Assembly language.

3.5.2 Low Level Languages

The term low level means closeness to the way in which the machine has been built. Low level languages are machine oriented and require extensive knowledge of computer hardware and its configuration.

(a) Machine Language

Machine Language is the only language that is directly understood by the computer. It does not needs any translator program. We also call it machine code and it is written as strings of 1's (one) and 0’s (zero). When this sequence of codes is fed to the computer, it recognizes the codes and converts it in to electrical signals needed to run it. For example, a program instruction may look like this:

1011000111101

It is not an easy language for you to learn because of its difficult to understand. It is efficient for the computer but very inefficient for programmers. It is considered to the first generation language. It is also difficult to debug the program written in this language.

Advantage

The only advantage is that program of machine language run very fast because no translation program is required for the CPU.

Disadvantages

1. It is very difficult to program in machine language. The programmer has to know details of hardware to write program.

2. The programmer has to remember a lot of codes to write a program which results in program errors.

3. It is difficult to debug the program.

(b) Assembly Language

It is the first step to improve the programming structure. You should know that computer can handle numbers and letter. Therefore some combination of letters can be used to substitute for number of machine codes.

The set of symbols and letters forms the Assembly Language and a translator program is required to translate the Assembly Language to machine language. This translator program is called `Assembler'. It is considered to be a second-generation language.

Advantages:

1. The symbolic programming of Assembly Language is easier to understand and saves a lot of time and effort of the programmer.

2. It is easier to correct errors and modify program instructions.

3. Assembly Language has the same efficiency of execution as the machine level language. Because this is one-to-one translator between assembly language program and its corresponding machine language program.

Disadvantages:

1. One of the major disadvantages is that assembly language is machine dependent. A program written for one computer might not run in other computers with different hardware configuration.

3.6 HIGH LEVEL LANGUAGES

You know that assembly language and machine level language require deep knowledge of computer hardware where as in higher language you have to know only the instructions in English words and logic of the problem irrespective of the type of computer you are using.

Higher level languages are simple languages that use English and mathematical symbols like +, -, %, / etc. for its program construction.

You should know that any higher level language has to be converted to machine language for the computer to understand.

Higher level languages are problem-oriented languages because the instructions are suitable for solving a particular problem. For example COBOL (Common Business Oriented Language) is mostly suitable for business oriented language where there is very little processing and huge output. There are mathematical oriented languages like FORTRAN (Formula Translation) and BASIC (Beginners All-purpose Symbolic Instruction Code) where very large processing is required.

Thus a problem oriented language designed in such a way that its instruction may be written more like the language of the problem. For example, businessmen use business term and scientists use scientific terms in their respective languages.

Advantages of High Level Languages

Higher level languages have a major advantage over machine and assembly languages that higher level languages are easy to learn and use. It is because that they are similar to the languages used by us in our day to day life.

3.6.1 Compiler

It is a program translator that translates the instruction of a higher level language to machine language. It is called compiler because it compiles machine language instructions for every program instructions of higher level language. Thus compiler is a program translator like assembler but more sophisticated. It scans the entire program first and then translates it into machine code.

The programs written by the programmer in higher level language is called source program. After this program is converted to machine languages by the compiler it is called object program.

Higher Level Language --> (Compile) ---> Program --> Machine Language Program

A compiler can translate only those source programs, which have been written, in that language for which the compiler is meant for. For example FORTRAN compiler will not compile source code written in COBOL language.

Object program generated by compiler is machine dependent. It means programs compiled for one type of machine will not run in another type. Therefore every type of machine must have its personal compiler for a particular language. Machine independence is achieved by using one higher level language in different machines.

3.6.2 Interpreter

An interpreter is another type of program translator used for translating higher level language into machine language. It takes one statement of higher level languages, translate it into machine language and immediately execute it. Translation and execution are carried out for each statement. It differs from compiler, which translate the entire source program into machine code and does involve in its execution.

The advantage of interpreter compared to compiler is its fast response to changes in source program. It eliminates the need for a separate compilation after changes to each program. Interpreters are easy to write and do not require large memory in computer. The disadvantage of interpreter is that it is time consuming method because each time a statement in a program is executed then it is first translated. Thus compiled machine language program runs much faster than an interpreted program.


Why learn C?

C is the most commonly used programming language for writing operating systems. Unix was the first operating system written in C. Later Microsoft Windows, Mac OS X, and GNU/Linux were all written in C.

Why C, and not assembly language?

Because Assembly, while extremely powerful, is simply too difficult to program large applications, and hard to read or interpret in a logical way. Additionally, different processors are programmed using different Assembly languages and having to choose and learn only one of them is too arbitrary. In fact, one of the strengths of C is its universality and portability across various computer architectures.

History

The field of computing as we know it today started in 1947 with three scientists at Bell Telephone Laboratories--William Shockley, Walter Brattain, and John Bardeen--and their groundbreaking invention of the transistor. In 1956, the first fully transistor-based computer, the TX-0, was completed at MIT. The first integrated circuit was created in 1958 by Jack Kilby at Texas Instruments but, the first high-level programming language existed even before then.

In 1954, The Fortran project, named for it being the Formula Translator, began. Fortran begot Algol 58, the Algorithmic Language, in 1958. Algol 58 begot Algol 60 in 1960. Algol 60 begot Combined Programming Language CPL, the Combined Programming Language, in 1963. CPL begot Basic CPL BCPL, in 1967. BCPL begot B in 1969. B begot C in 1971.

B was the first language in the C lineage directly. It was created by Ken Thompson. B at Bell Labs and was an interpreted language used in early internal versions of the UNIX operating system. Thompson and Dennis Ritchie, also of Bell Labs, improved B and called it NB. Further extensions to NB created its logical successor, C, a compiled language. Most of UNIX was then rewritten in NB and then C, which led to a more portable operating system.

The portability of UNIX was the main reason for the initial popularity of both UNIX and C. So rather than creating a new operating system for each new machine, system programmers could simply write the few system-dependent parts required for the machine, and write a C compiler for the new system. Thereafter since most of the system utilities were written in C, it simply made sense to also write new utilities in that language.

Characteristics

Like most imperative languages in the ALGOL tradition, C has facilities for structured programming and allows lexical variable scope and recursion, while a static type system prevents many unintended operations. In C, all executable code is contained within functions. Function parameters are always passed by value. Pass-by-reference is achieved in C by explicitly passing pointer values. Heterogeneous aggregate data types (struct) allow related data elements to be combined and manipulated as a unit. C program source text is free-format, using the semicolon as a statement terminator (not a delimiter).

C also exhibits the following more specific characteristics:

  • non-nestable function definitions
  • variables may be hidden in nested blocks
  • partially weak typing; for instance, characters can be used as integers
  • low-level access to computer memory by converting machine addresses to typed pointers
  • function and data pointers supporting ad hoc run-time polymorphism
  • array indexing as a secondary notion, defined in terms of pointer arithmetic
  • a preprocessor for macro definition, source code file inclusion, and conditional compilation
  • complex functionality such as I/O, string manipulation, and mathematical functions consistently delegated to library routines
  • A relatively small set of reserved keywords
  • A lexical structure that resembles B more than ALGOL, for example
    • { ... } rather than ALGOL's begin ... end
    • the equal-sign is for assignment (copying), much like Fortran
    • two consecutive equal-signs are to test for equality (compare to .EQ. in Fortran or the equal-sign in BASIC)
    • && and || in place of ALGOL's and and or (these are semantically distinct from the bit-wise operators & and | because they will never evaluate the right operand if the result can be determined from the left alone (short-circuit evaluation)).
    • a large number of compound operators, such as +=, ++, etc.

Undefined behavior

Many operations in C that have undefined behavior are not required to be diagnosed at compile time. In the case of C, "undefined behavior" means that the exact behavior which arises is not specified by the standard, and exactly what will happen does not have to be documented by the C implementation. A famous, although misleading, expression in the newsgroups comp.std.c and comp.lang.c is that the program could cause "demons to fly out of your nose". Sometimes in practice what happens for an instance of undefined behavior is a bug that is hard to track down and which may corrupt the contents of memory. Sometimes a particular compiler generates reasonable and well-behaved actions that are completely different from those that would be obtained using a different C compiler. The reason some behavior has been left undefined is to allow compilers for a wide variety of instruction set architectures to generate more efficient executable code for well-defined behavior, which was deemed important for C's primary role as a systems implementation language; thus C makes it the programmer's responsibility to avoid undefined behavior. Examples of undefined behavior are:

  • accessing outside the bounds of an array
  • overflowing a signed integer
  • reaching the end of a non-void function without finding a return statement, when the return value is used
  • reading the value of a variable before initializing it

These operations are all programming errors that could occur using many programming languages; C draws criticism because its standard explicitly identifies numerous cases of undefined behavior, including some where the behavior could have been made well defined, and does not specify any run-time error handling mechanism.

Invoking fflush() on a stream opened for input is an example of a different kind of undefined behavior, not necessarily a programming error but a case for which some conforming implementations may provide well-defined, useful semantics (in this example, presumably discarding input through the next new-line) as an allowed extension. Use of such nonstandard extensions generally limits software portability.

Uses

C's primary use is for "system programming", including implementing operating systems and embedded system applications, due to a combination of desirable characteristics such as code portability and efficiency, ability to access specific hardware addresses, ability to "pun" types to match externally imposed data access requirements, and low runtime demand on system resources.

One consequence of C's wide acceptance and efficiency is that compilers, libraries, and interpreters of other programming languages are often implemented in C.

C is sometimes used as an intermediate language by implementations of other languages. This approach may be used for portability or convenience; by using C as an intermediate language, it is not necessary to develop machine-specific code generators. Some compilers which use C this way are BitC, Gambit, the Glasgow Haskell Compiler, Squeak, and Vala.

Unfortunately, C was designed as a programming language, not as a compiler target language, and is thus less than ideal for use as an intermediate language. This has led to development of C-based intermediate languages such as C--.

C has also been widely used to implement end-user applications, but as applications became larger, much of that development shifted to other languages.

Operators

Main article: Operators in C and C++

C supports a rich set of operators, which are symbols used within an expression to specify the manipulations to be performed while evaluating that expression. C has operators for:

  • arithmetic (+, -, *, /, %)
  • equality testing (==, !=)
  • order relations (<, <=, >, >=)
  • boolean logic (!, &&, ||)
  • bitwise logic (~, &, |, ^)
  • bitwise shifts (<<, >>)
  • assignment (=, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=)
  • increment and decrement (++, --)
  • reference and dereference (&, *, [ ])
  • conditional operator (? :)
  • member selection (., ->)
  • type conversion (( ))
  • object size (sizeof)
  • function argument collection (( ))
  • sequencing (,)
  • subexpression grouping (( ))

C has a formal grammar, specified by the C standard.


General comparison

The following table compares general and technical information for a selection of commonly used programming languages. See the individual languages' articles for further information. Please note that the following table may be missing some information.

Language

Intended use

Paradigm(s)

Standardized?

ActionScript 3.0

Web, client-side

imperative, object-oriented, event-driven

Yes, ECMA

Ada

Application, Embedded, System and Realtime

imperative, procedural, concurrent, distributed, generic, object-oriented

Yes, ANSI, ISO, GOST 27831-88

ALGOL 58

Application

imperative

No

ALGOL 60

Application

imperative

Yes, ISO

ALGOL 68

Application

imperative, concurrent

Yes, GOST 27974-88

APL

Application, Data processing

array-oriented, tacit

Yes, ISO

Assembly language

General


No

AutoHotkey

End User Programming

imperative

de facto

AutoIt

Highly domain-specific, GUI automation(macros)

imperative, procedural

No

BASIC

Application, Education

imperative, procedural

Yes, ANSI, ISO

BeanShell

Application, Scripting

imperative, object-oriented, functional, reflective

In progress, JCP

BLISS

System

procedural

No

Boo

Application


No

C

System

imperative

Yes, ANSI C89, ISO C90/C99

C++

Application, System

imperative, object-oriented, generic

Yes, ISO

C#

Application

imperative, object-oriented, functional, generic, reflective

Yes, ECMA, ISO

Clean

General

functional, generic

No

Clojure

General

functional

No

COBOL

Application, Business

imperative, object-oriented

Yes

ColdFusion

Web Development

procedural, object-oriented

No

Common Lisp

General

imperative, functional, object-oriented

Yes

Curl


imperative, event-driven, functional, object-oriented, generic, reflective

No

D

Application; System

imperative, object-oriented, generic

No

Dylan

Application

functional, object-oriented

No

Eiffel

Application

imperative, object-oriented, generic

Yes, ECMA, ISO

Erlang

Application, Distributed and Telecom

functional, concurrent, distributed

No

Factor


stack-oriented

No

FP


functional

No

F#

Application

imperative, functional, object-oriented, generic

No

Forth

General

imperative, stack-oriented

Yes, ANSI

FORTRAN

Application, scientific and engineering

imperative, procedural, object-oriented

Yes, ANSI 66, ANSI 77, MIL-STD-1753, ISO 90, ISO 95, ISO 2003

Game Maker Language

Application, games

imperative, object-oriented, event-driven

No

GraphTalk


logic-oriented, object-oriented

No

Groovy

Application, Web

imperative, object-oriented, aspect-oriented

No

Haskell

Application

functional, generic, lazy evaluation

Yes, Haskell 98

Io

Application, Host-driven Scripting

imperative, object-oriented

No

J

Data processing

array-oriented, function-level, tacit

No

Java

Application, Web

imperative, object-oriented, generic, reflective

No

JavaScript

Web, client-side

imperative, object-oriented, functional, reflective

Yes, ECMA

Joy

research

functional, stack-oriented

No

LabVIEW ("G")

Application, industrial instrumentation and automation

dataflow, visual

No

Lua

Embedded scripting; Application

imperative, object-oriented, functional, aspect-oriented, reflective

No

Mathematica

Highly domain-specific, Math

procedural, functional

No

MATLAB M-code

Highly domain-specific, Math

imperative, object-oriented

No

Modula-2

Application, System

imperative, generic

Yes, ISO

Modula-3

Application

imperative, object-oriented, generic

No

Mythryl

Application, Scripting

imperative, generic, functional

No

Oberon

Application, System

imperative, object-oriented

No

Objective-C

Application

imperative, object-oriented, reflective

Yes

Objective Caml

Application

imperative, object-oriented, functional, generic

No

Object Pascal (Delphi)

Application

imperative, object-oriented, generic, event-driven

No

Occam

Parallel computations

imperative, procedural, concurrent, process-oriented

No

Oxygene

Application

imperative, object-oriented, generic

No

Oz

Education

imperative, logic, functional, object-oriented, concurrent

No

Pascal

Application, Education

imperative, procedural

Yes, ISO

Pawn

Embedded, Host-driven Scripting

imperative

No

Perl

Application, Text processing, Scripting, Web

imperative, procedural, reflective, functional, object-oriented, generic

No

PHP

Web, server-side

imperative, procedural, object-oriented, reflective

No

PL/I

Application, COBOL's and Fortran's original domain

imperative, object-oriented

Yes

Prolog

Application, Artificial intelligence

logic

Yes, ISO

Python

Application, Scripting, Web

imperative, object-oriented, functional, aspect-oriented, reflective

No

REALbasic

Application


Unknown

REBOL

Distributed computing

imperative, prototype-based, functional, dialected

No

RPG

Application


Unknown

Ruby

Application, Scripting, Web

imperative, object-oriented, aspect-oriented, reflective, functional

No

S

Application, Statistics

imperative, procedural, functional, object-oriented

No

S-Lang

Application, Scripting, Numerical

imperative, procedural

No

Scala

Application

object-oriented, functional, generic

No

Scheme

General, Education

functional

Yes, R6RS

Simula

General, Education

imperative, object-oriented, event-driven, discrete event simulation, multi-threaded (quasi-parallel) program execution

Yes

Smalltalk

Application, Education

imperative, object-oriented, concurrent, event-driven, declarative

Yes, ANSI

SNOBOL

Text processing


Unknown

Standard ML

Application

imperative, functional, generic

Yes, SML '97

Tcl

Application, Scripting

imperative, procedural, event-driven

No

Visual Basic

Application, Education

component-oriented, event-driven

No

Visual Basic .NET

Application, Education

object-oriented, event-driven

No

Visual Prolog

Application

imperative, declarative, logical, object-oriented, functional, event-driven

No

Windows PowerShell

Administration

imperative, object-oriented, functional, pipeline, reflective

No

XL


imperative, concept programming, object-oriented

No


No comments:

Post a Comment

Search This Blog