-->
R27mUISKY8MAeCpFpAtsSpjGWGukfoZYVKEfkHA4
Free Download Blogger Template High CTR AdSense

 

Unit-I: Basics of Programming

 

 

1.1. Definition and Characteristics of Computer

A computer is an electronic device that has the ability to store, retrieve, and process data, and can

be programmed with instructions that it remembers. The physical parts that make up a computer

(the central processing unit, input, output, and memory) are called hardware. Programs that tell a

computer what to do are called software.

A set of instructions that perform a particular task is called a program, software program, or

software. Peripherals are any hardware device connected to a computer, any part of the computer

outside the CPU and working memory. Some examples of peripherals are keyboards, the mouse,

monitors, printers, scanners, disk and tape drives, microphones, speakers, joysticks, plotters, and

cameras. Computer is an advanced electronic device that takes raw data as input from the user and

processes these data under the control of set of instructions (called program) and gives the result

(output) and saves output for the future use. It can process both numerical and non-numerical

(arithmetic and logical) calculations.

Definition of a Computer

 A computer is an electronic device that operates under the control of a set of instructions

that is stored in its memory unit.

 A computer can be more accurately defined as an electronic device that takes data as input,

stores and processes it and displays the output according to the given instructions.

Characteristics of Computer

1. Speed

The computer can process data very fast, at the rate of millions of instructions per second.

Some calculations that would have taken hours and days to complete otherwise, can be

completed in a few seconds using the computer. For example, calculation and generation of

salary slips of thousands of employees of an organization, weather forecasting that requires

analysis of a large amount of data related to temperature, pressure and humidity of various

places, etc.

2. Accuracy

Computer provides a high degree of accuracy. For example, the computer can accurately give

the result of division of any two numbers up to 10 decimal places.


3. Diligence

When used for a longer period of time, the computer does not get tired or fatigued. It can

perform long and complex calculations with the same speed and accuracy from the start till the

end.

4. Storage Capability

Large volumes of data and information can be stored in the computer and also retrieved

whenever required. A limited amount of data can be stored, temporarily, in the primary

memory. Secondary storage devices like floppy disk and compact disk can store a large amount

of data permanently.

5. Versatility

Computer is versatile in nature. It can perform different types of tasks with the same ease. At

one moment user can use the computer to prepare a letter document and in the next moment

user may play music or print a document.

1.2.Block diagram of Computer

1.2.1. Input Unit

Computers need to receive data and instruction in order to solve any problem. Therefore, we need

to input the data and instructions into the computers. The input unit consists of one or more input

devices. Keyboard is the one of the most commonly used input devices. Other commonly used

input devices are the Mouse, Scanner, Microphone etc. All the input devices perform the following

functions.

 Accept the data and instructions from the outside world.

 Convert it to a form that the computer can understand.

 Supply the converted data to the computer system for further processing.

1.2.2. Storage Unit

The storage unit of the computer holds data and instructions that are entered through the input unit,

before they are processed. It preserves the intermediate and final results before these are sent to

the output devices. It also saves the data for the later use. The various storage devices of a computer

system are divided into two categories.

1.2.2.1.Primary Storage (also known as Main memory or Internal memory)

Stores and provides very fast. This memory is generally used to hold the program being currently

executed in the computer, the data being received from the input unit, the intermediate and final

results of the program. The primary memory is temporary in nature. The data is lost, when the

computer is switched off. In order to store the data permanently, the data has to be transferred to

the secondary memory. The cost of the primary storage is more compared to the secondary storage.

Therefore, most computers have limited primary storage capacity. Examples: RAM, ROM, Cache

memory etc

1.2.2.2.Secondary Storage

Secondary storage is used like an archive. It stores several programs, documents, data bases etc.

The programs that user run on the computer are first transferred to the primary memory before it

is actually run. Whenever the results are saved, again they get stored in the secondary memory.

The secondary memory is slower and cheaper than the primary memory. Some of the commonly

used secondary memory devices are Hard disk, CD, etc.,

1.2.2.3.Memory Size

All digital computers use the binary system, i.e., 0’s and 1’s. Each character or a number is

represented by an 8-bit code. The set of 8 bits is called a byte. A character occupies 1-byte space.

A numeric occupies 2-byte space. Byte is the space occupied in the memory. The size of the

primary storage is specified in KB (Kilobytes) or MB (Megabyte). One KB is equal to 1024 bytes

and one MB is equal to 1000KB. The size of the primary storage in a typical PC usually starts at

16MB. PCs having 32 MB, 48MB, 128 MB, 256MB memory are quite common.

1.2.3. Output Unit


The output unit of a computer provides the information and results of a computation to outside

world. Printers, Visual Display Unit (VDU) are the commonly used output devices. Other

commonly used output devices are Speaker, Headphone, Projector etc.

1.2.4. Central Processing Unit

The Control Unit (CU) and Arithmetic Logic Unit (ALU) of the computer are together known

as the Central Processing Unit (CPU). The CPU is like brain performs the following functions:

• It performs all calculations.

• It takes all decisions.

•It controls all units of the computer.

1.2.4.1.Arithmetic Logical Unit

All calculations are performed in the Arithmetic Logic Unit (ALU) of the computer. It also does

comparison and takes decision. The ALU can perform basic operations such as addition,

subtraction, multiplication, division, etc and does logic operations viz, >, <, =, ‘etc. Whenever

calculations are required, the control unit transfers the data from storage unit to ALU once the

computations are done, the results are transferred to the storage unit by the control unit and then it

is sent to the output unit for displaying results.

1.2.4.2.Control Unit

It controls all other units in the computer. The control unit instructs the input unit, where to

store the data after receiving it from the user. It controls the flow of data and instructions from

the storage unit to ALU. It also controls the flow of results from the ALU to the storage unit.

The control unit is generally referred as the central nervous system of the computer that control

and synchronizes it’s working.

Difference Between Primary Memory and Secondary Memory

Primary memory Secondary memory

Primary memory is temporary. Secondary memory is permanent.

Primary memory is directly accessible by

Processor/CPU.

Secondary memory is not directly accessible

by the CPU.

Nature of Parts of Primary memory varies,

RAM- volatile in nature. ROM- Non-volatile.

It’s always Non-volatile in nature.

Primary memory devices are more expensive

than secondary storage devices.

Secondary memory devices are less

expensive when compared to primary

memory devices.

The memory devices used for primary

memory are semiconductor memories.

The secondary memory devices are

magnetic and optical memories.


Primary memory is also known as Main

memory or Internal memory.

Secondary memory is also known as

External memory or Auxiliary memory.

Examples: RAM, ROM, Cache memory,

PROM, EPROM, Registers, etc.

Examples: Hard Disk, Floppy Disk,

Magnetic Tapes, etc.

1.3. Compiler

Compiler is the software that translates the program written in a high-level language to machine

language. The program written in high-level language is referred to as the source code (Source

program) and compiled program is referred as the object code (Target program).

1. Source program

It is normally a program written in a high-level programming language. It contains a set of

rules, symbols, and special words used to construct a computer program.

2. Target program

It is normally the equivalent program in machine code. It contains the binary representation of

the instructions that the hardware of computer can perform.

3. Error Message

A message issued by the compiler due to detection of syntax errors in the source program.

Each programming language has its own compiler. Some languages that use a compiler are C++,

COBOL, Pascal, and FORTRAN. In some languages, compilation using the compiler and linking

using the linker are required for creating the executable object code. The compilation process

generally involves two parts:

1. breaking down the source code into small pieces and creating an intermediate

representation.

2. constructing the object code for the intermediate representation.

The compiler also reports syntax errors, if any, in the source code.

1.4. Interpreter

The interpreter is used to convert the high-level language program into computer-understandable

form. However, the interpreter functions in a different way than a compiler. Interpreter performs

line-by-line execution of the source code during program execution. Interpreter reads the source

code line-by-line, converts it into machine understandable form, executes the line, and then

proceeds to the next line. Some languages that use an interpreter are BASIC and Python.


Difference between Compiler and Interpreter

Compiler Interpreter

1 Compiler works on the complete program at

once. It takes the entire program as input.

Interpreter program works line‐by‐line. It

takes one statement at a time as input

2 Compiler generates intermediate code,

called the object code or machine code.

Interpreter does not generate intermediate

object code or machine code.

3 Compiler executes conditional control

statements (like if‐else and switch‐case) and

logical constructs faster than interpreter.

Interpreter execute conditional control

statements at a much slower speed.

4 Compiled programs take more memory

because the entire object code has to reside

in memory.

Interpreter does not generate intermediate

object code. As a result, interpreted

programs are more memory efficient.

5 Compile once and run anytime. Compiled

program does not need to be compiled every

time.

Interpreted programs are interpreted line‐

by‐ line every time they are run.

6 Errors are reported after the entire program

is checked for syntactical and other errors.

Error is reported as soon as the first error is

encountered. Rest of the program will not

be checked until the existing error is

removed.

7 A compiled language is more difficult to

debug.

Debugging is easy because interpreter stops

and reports errors as it encounters them.

8 Compiler does not allow a program to run

until it is completely error‐free.

Interpreter runs the program from first line

and stops execution only if it encounters an

error.

9 Interpreter runs the program from first line

and stops execution only if it encounters an

error.

Interpreted languages are less efficient but

easier to debug. This makes such languages

an ideal choice for new students.

10 Examples of programming languages that

use compilers: C, C++, COBOL

Examples of programming languages that

use interpreters: BASIC, Visual Basic,

Python, Ruby, PHP, Perl, MATLAB, Lisp

1.5. Linker


A program that takes as input the object files of one or more separately compiled program modules,

and links them together into a complete executable program, resolving reference from one module

to another.

Linkers are of two types:

1. Linkage Editor

2. Dynamic Linker

The major task of a linker is to search and locate referenced module/routines in a program and to

determine the memory location where these codes will be loaded, making the program instruction

to have absolute references.

1.6. Loader

A program that takes an input an executable program, loads it into main memory, and causes

execution to being by loading the correct starting address into the computer register. When the

program finished, control must somehow be returned to the operating system. Following are the

functions:

1. Allocation: Allocates space in memory for the program.

2. Linking: Symbol Resolution between object modules.

3. Relocation: Adjust addresses dependent locations of address constants i.e., assign load

addresses to different parts of a program.

4. Loading: Store machine instructions and data into memory.

Following are the types of loaders:

1. Absolute Loaders

2. Relocating Loaders

3. Direct Linking Loaders

4. Bootstrap Loaders

Differences between Linker and Loader are as follows:

Linker Loader

The main function of Linker is to generate

executable files.

Whereas main objective of Loader is to load

executable files to main memory.

The linker takes input of object code

generated by compiler/assembler.

And the loader takes input of executable files

generated by linker.

Linking can be defined as process of

combining various pieces of codes and

source code to obtain executable code.

Loading can be defined as process of loading

executable codes to main memory for further

execution.

Linkers are of 2 types: Linkage Editor and

Dynamic Linker.

Loaders are of 4 types: Absolute, Relocating,

Direct Linking, Bootstrap.

Related Posts

Related Posts

Post a Comment