0% found this document useful (0 votes)
23 views

1 Foundations of Computing

The document discusses the foundations of computing including the basic components and architecture of a computer system. It describes the four main parts of a computer system: hardware, software, data, and users. It then explains the typical architecture including input/output units, central processing unit, and memory unit. It provides details on these components and how they work together.

Uploaded by

Narasimhan T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

1 Foundations of Computing

The document discusses the foundations of computing including the basic components and architecture of a computer system. It describes the four main parts of a computer system: hardware, software, data, and users. It then explains the typical architecture including input/output units, central processing unit, and memory unit. It provides details on these components and how they work together.

Uploaded by

Narasimhan T
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

EST102 : Programming in C

Chapter 1
Foundations of computing

Narasimhan T.

1.1 Introduction
Computer is an advanced electronic device that takes raw data as input from the user and
processes these data under the control of a set of instructions (called program) and gives
the result (output) and saves the output for future use. It can perform both numerical
(arithmetic) and non-numerical (logical) calculations.

1.2 Parts of a computer system


A computer system typically is composed of four main parts:

1. Hardware – consists of the physical devices of a computer. The devices are required
for input, output, storage and processing of the data. Keyboard, monitor, hard disk
drive, processor are some of the hardware devices.

2. Software – is a collection of programs and related documents. Program is a set of


instructions, written in a language understood by the computer, to perform a specific
task. Software instructs the computer about the task to be performed. The hardware
carries out these tasks.

3. Data – are isolated values or raw facts, provided as input to the computer, which are
processed to generate some meaningful information.

4. Users – are people who write computer programs or interact with the computer. Pro-
grammers, data entry operators, computer hardware engineers fall into this category.

1
2 CHAPTER 1. FOUNDATIONS OF COMPUTING

Figure 1.1: A typical computer architecture

1.3 Architecture of a computer


A typical computer architecture comprises of three main components:

1. Input/Output (I/O) Unit,

2. Central Processing Unit (CPU), and

3. Memory Unit.

The I/O unit consists of the input unit and output unit. The input unit accepts data
from the user and the output unit provides the processed data (information) to user. CPU
performs calculations and processing on the input data, to generate the output. The memory
unit is used to store the data, the instructions and the output information. Figure 1.1
illustrates a typical architecture of a computer.

1.3.1 Input/output unit


The user interacts with the computer via the I/O unit which comprises of input and output
devices.

1.3.1.1 Input devices


Input devices allow users to input data into the computer for processing. They are necessary
to convert the input data into a form which can be understood by the computer. The data
input to a computer can be in the form of text, audio, video etc. Input devices are classified
into two categories:

1. Human data entry devices – the user enters data into the computer either by typing
or by pointing a device to a particular location. Some examples are

(a) Keyboard – the most common typing device.


(b) Mouse – the most common pointing device. You move the mouse around on
a mouse pad and a small pointer called cursor follows your movements on the
computer screen.
1.3. ARCHITECTURE OF A COMPUTER 3

(c) Track ball – an alternative to a mouse which has a ball on the top. The cursor
on the computer screen moves in the direction in which the ball is moved.
(d) Joystick – has a stick whose movement determines the cursor position.
(e) Graphics tablet – converts hand-drawn images into a format suitable for com-
puter processing.
(f) Light pen – can be used to “draw” on the screen or to select options from menus
presented on the screen by directly pointing the pen on the screen.
2. Source data entry devices – use special equipment to collect data at the source, cre-
ate machine-readable data and feed them directly into the computer. This category
comprises:
(a) Audio input devices – uses human voice or speech to give input. Microphone is
an example.
(b) Video input devices – gives input in the form of video or images. Video camera,
webcam are examples.
(c) Optical input devices – uses optical technology (light source) to input the data
into the computers. Some common optical input devices are scanner, bar code
reader. Other examples include Optical Character Recognition (OCR), Magnetic
Ink Character Recognition (MICR) and Optical Mark Recognition (OMR).

1.3.1.2 Output devices


An output device takes the processed data from the computer and converts them into
information in a form which is normally understandable by humen. The output could be
on a paper or on a film in a tangible form or in an intangible form like audio, video etc.
Output devices are classified as follows:
1. Hard copy devices – The output obtained in a tangible form on a paper or any
surface is called hard copy output. The hard copy can be stored permanently and is
portable. The hard copy output can be read or used without a computer. Examples
in this category include:
(a) Printer – prints information on paper. The information could be textual or even
images. Many printer types like drum printers, laser printers, inkjet printers
exist.
(b) Plotter – used to produce very large drawings on paper sizes up to A0 (16 times
as big as A4). A plotter draws onto the paper using very fine pens. Flat bed
plotter and drum plotter are the two types.
(c) COM (Computer Output on Microfilm) – stores the output (mostly as images)
on a microfilm. The copy of the image on microfilm retains its original clarity.
2. Soft Copy Devices – generates soft copy of the output (output obtained in an intan-
gible form) on a visual display, audio unit or video unit. The soft copy can be stored
and sent via e-mail to other users. It also allows corrections to be made. The soft
copy output requires a computer to be read or used. This category comprises of:
4 CHAPTER 1. FOUNDATIONS OF COMPUTING

(a) Monitor – main output device of a computer. Monitors can be of two types:
monochrome (black and white) or colour. It forms images from tiny dots, called
pixels that are arranged in a rectangular form.
(b) Video output devices – produces output in the form of video or images. An
example is screen image projector or data projector that displays information
from the computer onto a large white screen.
(c) Audio output devices – speakers, headset or headphone are used for audio output
(in the form of sound) from computer. The signals are sent to the speakers via
sound card that translates the digital sound back into analog signals.

1.3.2 Central Processing Unit


Central Processing Unit (CPU) or the processor is also often called the brain of computer.
It consists of Arithmetic Logic Unit (ALU) and Control Unit (CU). In addition, CPU also
has a set of registers which are temporary storage areas for holding data and instructions.

1.3.2.1 Arithmetic Logic Unit


This unit consists of two sub-units namely arithmetic and logic units.

1. Arithmetic unit – performs arithmetic operations like addition, subtraction, multi-


plication and division.

2. Logic unit – performs logical operations like comparisons of numbers, characters.


Comparison includes testing for greater than, less than or equal to conditions.

1.3.2.2 Registers
Registers are high-speed storage areas within the CPU, but have the least storage capacity.
They store data, instructions, addresses and intermediate results of processing. Some of
the commonly used registers are:

• Accumulator (ACC) stores the result of arithmetic and logic operations.

• Instruction Register (IR) contains the instruction that is currently being executed.

• Program Counter (PC) contains the address of next instruction to be processed.

• Memory Address Register (MAR) contains the address of the data to be fetched.

• Memory Buffer Register (MBR) temporarily stores data fetched from memory or the
data to be sent to memory. It is also called Memory Data Register (MDR).

• Data Register (DR) stores the operands and any other data.
1.3. ARCHITECTURE OF A COMPUTER 5

CPU
registers internal
memory
cost, speed Cache memory
increases
capacity Main memory
decreases
Magnetic disk
external
Optical disk memory

Magnetic tape

Figure 1.2: Memory hierarchy

1.3.2.3 Control Unit


This unit manages and coordinates the operations of all parts of the computer but does not
carry out any actual data processing operations. Functions of this unit are:

1. responsible for generating control signals which control the various operations of the
computer.

2. obtains the instructions from the memory, interprets them, and directs the computer
to execute the instructions by communicating with the ALU and the registers.

3. communicates with IO devices for transfer of data or results from/to memory.

4. decides when to fetch the data and instructions, what operation to perform, where to
store the results, the ordering of various events during processing etc.

1.3.3 Memory unit


Memory is the storage space in computer where data to be processed and instructions
required for processing are stored. Different types of memories, each having its own unique
features exist. The various memories can be organized in a hierarchical manner called
memory hierarchy as shown in Figure 1.2. The characteristics of memory hierarchy, as we
go from bottom to top are:

• Capacity in terms of storage decreases.

• Cost per bit of storage increases.

• Frequency of access of the memory by the CPU increases.

• Access time decreases.


6 CHAPTER 1. FOUNDATIONS OF COMPUTING

Memory is primarily of two types :


1. Internal Memory : memories that are on the motherboard.
2. External memory : memories that are outside the motherboard.

1.3.3.1 Internal Memory


Internal memory includes:
1. Registers – high-speed storage areas within the CPU.
2. Primary memory – main memory of computer. It is categorized into two:
(a) Random Access Memory (RAM) – used for storing data and instructions during
the operation of computer. Data to be processed are brought to RAM from input
devices or from secondary memory. After processing, the results are stored in
RAM before sending to the output device. RAM is volatile, i.e. data stored in it
are lost when we switch off the computer or if there is a power failure. Dynamic
RAM (DRAM) and Static RAM (SRAM) are the two types of RAM.
(b) Read Only Memory (ROM) – a non-volatile primary memory. It does not lose
its content when the power is switched off. ROM, as the name implies, has
only read capability and no write capability. After the information is stored
in ROM, it is permanent and cannot be corrected. Therefore, ROM is used to
store the data that does not require a change, for example the boot information
(information required while starting the computer when it is switched on) is
kept on ROM. PROM (Programmable Read Only Memory), EPROM (Erasable
and Programmable Read Only Memory), EEPROM (Electrically Erasable and
Programmable Read Only Memory) and UVEPROM (Ultra-Violet Erasable and
Programmable Read Only Memory) are the various ROM types.
3. Cache memory – placed between RAM and CPU and stores the data and instructions
that are used frequently. During data processing, CPU first checks cache for the
required data or instruction. If it is found in cache, the data or instruction is retrieved
from the cache itself. If the required data/instructions are not present in cache, they
are then retrieved from RAM.

1.3.3.2 External Memory


External memory includes:
1. Magnetic tape – a plastic tape with magnetic coating mounted on a reel or in a
cassette. It is a sequential access device, which means that the data can be read only
in the order they are written.
2. Magnetic disk – a thin plastic or metallic circular plate coated with magnetic oxide
and encased in a protective cover. Hard disk is an example. Magnetic disk is a direct
access secondary storage device. Direct access means that we can directly access the
location we want, without accessing the previous locations.
1.4. VON NEUMANN ARCHITECTURE 7

3. Optical disk – a flat and circular disk which is coated with reflective plastic material
that can be altered by laser light. The data bits 1 and 0 are stored as spots that are
relatively bright and light, respectively. CDs, DVDs are examples.

1.4 Von Neumann architecture


If we want to do some processing on data, they must be stored in computer memory.
Similarly the instructions that process the data must also be stored in the memory. This
concept of storing programs in computer memory is what is called stored program con-
cept. A computer based on Von Neumann architecture stores data and instructions in
the same memory; a computer based on Harvard architecture has separate memories (code
memory for programs and data memory for data) for storing program and data. Both are
stored-program designs.
The Von Neumann architecture describes a design architecture for an electronic digital
computer with parts consisting of a processing unit containing an arithmetic logic unit and
a control unit, a memory to store both data and instructions, external memory storage,
and input and output mechanisms. The design of a von Neumann architecture machine is
simpler than that of a Harvard architecture machine.

1.5 Instruction execution


An instruction is an elementary operation that the processor can perform and is written to
accomplish some task. Now we discuss about the instruction format and how an instruction
is executed.

1.5.1 Instruction format


An instruction format defines the layout of an instruction, in terms of its constituents
parts. An instruction is divided into various parts called fields. The common fields of an
instruction are Operation code (opcode) and Operand code as shown below.

opcode operand code

The remainder of the instruction fields differs from one computer type to other. The
operation code represents action that the processor must execute. It tells the processor
what basic operations (add, subtract etc.) to perform. The operand code defines the data
(operands) on which the operations are to be performed. It specifies either the locations
where to fetch the operands or the value of the operands itself.

1.5.2 Instruction execution cycle


CPU executes an instruction in a series of steps called instruction execution cycle. An
instruction cycle (sometimes called a fetch–decode–execute cycle) is the basic operational
process of a computer. It is the process by which a computer retrieves a program instruction
8 CHAPTER 1. FOUNDATIONS OF COMPUTING

from its memory, determines what actions to perform, and carries out those actions. The
instruction cycle is shown in Figure 1.3.

fetch

store decode

execute

Figure 1.3: Instruction execution cycle

The cycle comprises of the following steps:

1. Fetch the instruction

1.1 Fetch the instruction from memory whose address is held currently in program
counter.
1.2 Store the fetched instruction in instruction register.
1.3 Increment the program counter so that it then has the address of the next in-
struction to be fetched.

2. Decode the instruction

2.1 Based on the instruction set architecture, the instruction is broken into opcode
and operand codes
2.2 The operation to be performed is identified.

3. Execute the instruction

3.1 The operation identified in the decode step is now performed by the CPU.

4. Store the result

4.1 The result generated by the operation is stored in the main memory, or sent to
an output device.

The cycle is then repeated for the next instruction.


1.6. PROGRAMMING LANGUAGES 9

1.6 Programming languages


Programming Languages are used to write programs that are precise representations of
algorithms and which control the behaviour of a computer. Each language has a unique
set of keywords (words that it understands) and syntax (set of rules) for organizing the
program instructions. Programming languages fall into three categories:
1. Machine Language :- is what the computer can understand but it is difficult for the
programmer to understand. Machine languages consist of binary numbers only.

2. High level language :- is easier to understand and use for the programmer but difficult
for the computer. The programs written in high level languages contain English-like
statements as well as mathematical expressions.

3. Assembly Language :- falls in between machine language and high-level language.


They are similar to machine language, but easier to write code, because they allow
the programmer to substitute names for numbers.
Machine languages and assembly languages are also called low-level languages.

1.6.1 Machine Language


A program written in machine language is a collection of binary digits or bits (strings of
0’s and 1’s) that the computer reads and interprets. It is also referred to as machine code
or object code. Some of the features of a program written in machine language are:
1. The computer can understand the programs written in machine language directly. No
translation of the program is needed.

2. Program written in machine language can be executed very fast (Since no translation
is required).

3. Machine language is defined by the hardware of a computer. It depends on the type of


the processor that the computer uses, memory arrangement, operating systems, and
peripheral devices; and is thus machine-dependent. A machine-level program written
for one type of computer may not work on another type.

4. The machine-level instructions have an opcode field which specifies the actual oper-
ation (such as add or compare), and some other fields for the operands. For example
if the opcode for addition is 1010, then to add 3 and 6, the binary code would be
1010
|{z} 0011
|{z} 0110
|{z}
add 3 6

1.6.2 Assembly Language


A program written in assembly language uses symbolic representation of machine codes.
The opcodes are replaced by symbolic names called mnemonic codes that are much easier
to remember. The mnemonics for various operations are decided by the CPU manufacturer
10 CHAPTER 1. FOUNDATIONS OF COMPUTING

and cannot be changed by the programmer. Some of the features of assembly code ( program
written in assembly language) are:

1. Assembly language programs are easier to write than the machine language programs,
since assembly language programs use short, English-like representation of machine
code. For example to add 3 and 6, we would write ADD 3,6.

2. Assembly language programs are also machine-dependent.

3. Although assembly language programs use symbolic representation, they are still diffi-
cult to write. They are generally written when the efficiency and the speed of program
matters.

1.6.3 High-level Language


A high-level language is a programming language such as C, FORTRAN, or Pascal that
enables a programmer to write programs that are more or less independent of a particular
type of computer. Such languages are considered high-level because they are closer to
human languages and farther from machine languages. Some of the features of programs
written in high-level language are as follows:

1. Programs are easier to write, read and understand in high-level languages than in
machine language or in assembly language.

2. Most of the operations like arithmetic and logical operations are denoted by operators.
Thus to add 3 and 6, we just write 3+6. Here ‘+’ is the operator for addition.

3. Since the programs written in high-level languages are not machine-dependent, they
are easily portable from one computer to another.

1.7 Translator softwares


The computer can understand only machine code (strings of 0’s and 1’s). Thus when the
program is written in a language other than machine language (assembly or high level
languages), the program is to be converted to machine code. This conversion is called
translation and is done by translator software. The original program is called source code
and the translated code (object code) is the target code. There are three types of translator
software as discussed below.

1.7.1 Assembler
Assembler converts a program written in assembly language into machine code. There is
usually a one-to-one correspondence between the assembly statements and the machine lan-
guage instructions. The machine language is dependent on the processor architecture. Thus
the converted assembly language programs also differ for different computer architectures.
1.8. SYSTEM SOFTWARE AND APPLICATION SOFTWARE 11

1.7.2 Compiler
Compiler is the software that translates the program written in a high-level language to
object code which can be then executed independently. Each programming language has its
own compiler. The compilation process generally involves breaking down the source code
into small pieces and creating an intermediate representation, and then constructing the
object code from the intermediate representation. The compiler also reports any errors in
the source code.

1.7.3 Interpreter
The interpreter also converts the high-level language program into machine code. However,
the interpreter functions in a different way than a compiler. 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.
The key differences between a compiler and an interpreter are shown in Table 1.1.

Table 1.1: Comparison of compiler and interpreter

Compiler Interpreter
1. translates the entire source code at
1. translates the source code line-by-line.
once.
2. converts the entire source code into 2. converts a line of source code into ma-
object-code which is then executed by the chine executable form, executes the line,
user. and proceeds with the next line.
3. Once the object code is created, it
can be executed multiple number of times 3. During each execution, the source code
without the need to compile during each is first interpreted and then executed.
execution.
4. During execution of an object code, 4. Both interpreter and the source code
the compiler is not required are required during execution.
5. faster 5. slower
6. Languages like C, C++ and Java are 6. Languages like BASIC, Pascal and
compiled. Python are interpreted.

1.8 System software and application software


Software is a set of programs, which is designed to perform a well-defined function. There
are two types of software – Application software and System software. Application software
is a software that is used to achieve a specific task. For example word processing software
12 CHAPTER 1. FOUNDATIONS OF COMPUTING

like Microsoft Word is an application software. Application software is usually written


in high-level languages. System software is a collection of programs designed to operate,
control, and extend the processing capabilities of the computer itself. Such softwares which
are mostly written in low-level languages interact with the hardware at a very basic level.
Some examples of system software are:

• Operating System – interface between hardware and the end users.

• Translator software like compilers, interpreters and assemblers.

• Loader – loads the executable object code into main memory for execution.

• Linker – links several object code modules into a single executable code.

1.9 Structured approach to programming


Structured programming is one of the extensively used programming paradigms. A pro-
gramming paradigm is a style, or “way” of writing programs. With unstructured program-
ming style, all the actions required to accomplish a task were written as a single program.
As the task grew complex, the program became longer and unreadable.
Structured programming adopts a “divide and conquer” strategy to solve problems. The
problem to be solved is divided into simpler tasks called “subproblems” which are solved
independently. These solutions are then combined together to obtain the solution for the
problem at hand. In structured programming, the execution sequence follows the order in
which the code is written. This enhances readability of code which aids in understanding,
debugging, testing, documentation and modification of programs. Structured programming
can be accomplished in two ways as discussed below:

1.9.1 Procedural programming


Here, the solutions to the subproblems are written as procedures or functions. Each function
does a specific task. In procedural programming, the program is a single large file consisting
of many functions. There is a specific function called main function where the execution
starts. The main function “calls” (accesses) other functions to get the subproblems solved.
When a function named funA calls another function funB, the control of execution is trans-
ferred to funB which is executed. After the completion of execution, control is transferred
back to funA.

1.9.2 Modular programming


Here the solutions to the subproblems are written as separate programs (modules) that can
be executed independently. Each such program accomplishes a specific task. In modular
programming, a program consists of a group of files where each file has a program which
solves some subproblem. The programs are integrated using a main program file. This main
program calls other programs in an order that fulfils the required task.

You might also like