Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

UNIT 1

Components of a personal computer


Computer systems ranging from a controller in a microwave oven to a large supercomputer
contain components providing five functions. A typical personal computer has hard, floppy
and CD-ROM disks for storage, memory and CPU chips inside the system unit, a keyboard
and mouse for input, and a display, printer and speakers for output. The arrows represent
the direction information flows between the functional units.

A computer is really a system of many parts working together. The physical parts, which you
can see and touch, are collectively called hardware. Software, on the other hand, refers to
the instructions, or programs, that tell the hardware what to do.

A typical personal computer should have the following main components:


Monitor,Motherboard,Central processing unit or CPU, Memory,Cables and
connectors,Peripherals

Monitor Displays information in visual form, using text and graphics.The portion of the
monitor that displays the information is called the screen. Like a television screen, a
computer screen can show still or moving pictures.There are two basic types of monitors:
CRT (cathode ray tube) monitors and LCD (liquid crystal display) monitors.Both types
produce sharp images, but LCD monitors have the advantage of being much thinner and
lighter. CRT monitors, however, are generally more affordable.

Motherboard Also known as mainboard or logic board Serves to connect all of the parts of
a computer together. The CPU, memory, hard drives, optical drives, video card, sound card
and other ports and expansion cards all connected to the motherboard directly or via
cables.

CentralProcessingUnit
Also called as a processor, microprocessor, central processor, "the brains of the
computer”, the CPU is the heart of any computer system. It interprets and carries out basic
instructions that operate a computer.Central Processing Unit itself consists of three main
subsystems; first is the Control Unit, the second is Registers, and the third is Arithmetic and
Logic Unit(ALU).

 How the CPU Executes Program Instructions


Before an instruction can be executed, program instructions and data must be placed into
memory from an input device or a secondary storage device. Once the necessary data and
instruction are in memory, the central processing unit performs the following four steps for
each instruction:The control unit fetches (gets) the instruction from memory.The control
unit decodes the instruction (decides what it means) and directs that the necessary data be
moved from memory to the arithmetic/logic unit. These first two steps together are called
instruction time, or I-time.The arithmetic/logic unit executes the arithmetic or logical
instruction. That is, the ALU is given control and performs the actual operation on the
data.The arithmetic/logic unit stores the result of this operation in memory or in a register.
Steps 3 and 4 together are called execution time, or E-time.
Control Unit: The control unit of the CPU contains circuitry that uses electrical signals to
direct the entire computer system to carry out, or execute, stored program instructions.The
control unit does not execute program instructions; rather, it directs other parts of the
system to do so. The control unit must communicate with both the arithmetic/logic unit and
memory.

Arithmetic Logic Unit (ALU): Arithmetic logic unit (ALU) is a digital circuit that performs
arithmetic and logical operations.An ALU loads data from input registers, an external
Control Unit then tells the ALU what operation to perform on that data, and then the ALU
stores its result into an output register. The Control Unit is responsible for moving the
processed data between these registers, ALU and memory.Arithmetic/logic unit (ALU)
performs execution part of the machine cycle. The execution consists of Arithmetic
(addition, subtraction, multiplication, and division), Comparison (greater than, equal to, or
less than) and Logical (AND, OR, NOT).

Registers -PROGRAM COUNTER


Registers are temporary storage areas for instructions or data. They are not a part of
memory; rather they are special additional storage locations that offer the advantage of
speed. Registers work under the direction of the control unit to accept, hold, and transfer
instructions or data and perform arithmetic or logical comparisons at high speed.

Memory

Memory is also known as primary storage, primary memory, main storage, internal storage,
main memory, and RAM (Random Access Memory); all these terms are used
interchangeably by people in computer circles.Memory is the part of the computer that
holds data and instructions for processing. Although closely associated with the central
processing unit, memory is separate from it. Memory stores program instructions or data
for only as long as the program they pertain to is in operation.

L1 cache
L1 cache is a small, fast memory cache that is built in to a CPU and helps speed access to
important and frequently-used data. L1 cache is typically smaller and faster than L2
cache.L1 cache is an abbreviation of Level 1 cache.

Disk Access : P1 P2 P3 P1 P4 P5 P1 P2 P6 P1

Main Memory Access: P3 P1

Cache Memory Access: P2

L2 cache is typically larger but slower than L1 cache.


L2 cache is a set of memory circuits designed to speed access to important and frequently
used data.Early L2 cache designs involved fast static RAM memory chips placed near the
CPU. Modern L2 caches involve RAM built directly into the CPU.L2 cache is an abbreviation
of Level 2 cache.

RAM (Random Access Memory)


Random-access, commonly known as RAM or simply memory, provides space for your
computer to read and write data to be accessed by the CPU (central processing unit). When
people refer to a computer's memory, they usually mean its RAM.The strength of the RAM
determines, at random, how fast a piece of data can be pulled and returned.

RAM is volatile, so data stored in RAM stays there only as long as the computer is
running. As soon as the computer is switched off, the data stored in RAM disappears.

There are two different types of RAM: DRAM (Dynamic Random Access Memory) and
SRAM (Static Random Access Memory).

SRAM (Static Random Access Memory)SRAM is a type of memory that is faster and more
reliable than the more common DRAM (dynamic RAM). The term static is derived from the
fact that it doesn't need to be refreshed like dynamic RAM.Uses multiple transistors,
typically four to six, for each memory cell but doesn't have a capacitor in each cell.It is
volatile i.e. they lose their contents when the power is turned off.It is used primarily for
cache.

DRAM (Dynamic Random Access Memory)It has memory cells with a paired transistor and
capacitor requiring constant refreshing.The advantage of DRAM is its structural simplicity:
only one transistor and a capacitor are required per bit, compared to six transistors in
SRAM. This allows DRAM to reach very high densities.DRAM is used in main memory .

ROM(Read-OnlyMemory)
Read-Only Memory or ROM is an integrated-circuit memory chip that contains configuration
data. ROM is commonly called firmware because its programming is fully embedded into
the ROM chip. As such, ROM is a hardware and software in one. Because data is fully
incorporated at the ROM chip's manufacture, data stored can neither be erased nor
replaced. This means permanent and secure data storage. Data stored in ROM is
nonvolatile - it is not lost when your computer is turned off.Data stored in ROM is
either unchangeable or requires a special operation to change. Examples of ROM are:
Programmable ROM (PROM), Erasable Programmable ROM (EPROM) and Electrically
Erasable Programmable ROM (EEPROM).
Sr.No. Primary memory Secondary memory

1. Primary memory is temporary. Secondary memory is permanent.

Primary memory is directly accessible by Secondary memory is not directly


2. Processor/CPU. accessible by the CPU.

Nature of Parts of Primary memory varies,


RAM- volatile in nature. ROM- Non-
3. volatile. It’s always Non-volatile in nature.

Primary memory devices are more Secondary memory devices are less
expensive than secondary storage expensive when compared to primary
4. devices. memory devices.

The memory devices used for primary The secondary memory devices are
5. memory are semiconductor memories. magnetic and optical memories.

Primary memory is also known as Main Secondary memory is also known as


6. memory or Internal memory. External memory or Auxiliary memory.

Examples: RAM, ROM, Cache memory, Examples: Hard Disk, Floppy Disk,
7. PROM, EPROM, Registers, etc. Magnetic Tapes, etc.
Ports

A port serves as an interface between the computer and other computers or peripheral
devices through which data is sent and received.

Bus

In order for multiple hardware components to communicate with one another, a bus is used
to transmit the data from one part of a computer to another.A bus is a collection of wires
through which data is transmitted from one part of a computer to another.The purpose of
buses is to reduce the number of "pathways" needed for communication between the
components, by carrying out all communications over a single data channel.

Characteristics of a bus
The size of a bus, known as its width, is important because it determines how much data
can be transmitted at one time.For example, a 16-bit bus can transmit 16 bits of data,
whereas a 32-bit bus can transmit 32 bits of data. Additionally, the bus speed is also defined
by its frequency (expressed in Hertz), the number of data packets sent or received per
second.Each time that data is sent or received is called a cycle.

A bus is generally divided into three sub-assemblies:

 The address bus (sometimes called the memory bus) transports memory addresses
which the processor wants to access in order to read or write data. It is a
unidirectional bus.
 The data bus transfers instructions coming from or going to the processor. It is a
bidirectional bus.
 The control bus (or command bus) transports orders and synchronisation signals
coming from the control unit and travelling to all other hardware components. It is a
bidirectional bus, as it also transmits response signals from the hardware.

Peripheral Devices

Peripheral devices are computer devices that are connected to the computer externally
such as printer, scanner, keyboard, mouse, tape device, microphone and external modem
or internally such as CD-ROM or internal modem and external as the scanner, printer and
Zip drive. Peripheral devices can be classified according to their functions.

Input devices are the type of the computer devices that are used to provide the control
signals to the computer.  Keyboard and the Mouse are the examples of the input devices.

Output devices are the devices that are used to display the results.  Printer, scanner,
speaker and the monitor are the examples of the output devices.

Storage: A storage device is a device that is used to store the information such as hard disk
drive, flash drive, floppy disk and the tape drive.

OPERATING SYSTEM
An operating system acts as an intermediary between the user of a computer and computer
hardware. The purpose of an operating system is to provide an environment in which a user
can execute programs conveniently and efficiently. BOOT LOADER

Importance of OS

1. Convenience: An OS makes a computer more convenient to use.


2. Efficiency: An OS allows the computer system resources to be used efficiently.
3. Ability to Evolve: An OS should be constructed in such a way as to permit the
effective development, testing, and introduction of new system functions at the
same time without interfering with service.
4. Throughput: An OS should be constructed so that It can give
maximum throughput(Number of tasks per unit time).

Major Functionalities of Operating System: 

 Resource Management: When parallel accessing happens in the OS means when


multiple users are accessing the system the OS works as Resource Manager, Its
responsibility is to provide hardware to the user. It decreases the load in the system.
 Process Management: It includes various tasks like scheduling, termination of the
process. OS manages various tasks at a time. Here CPU Scheduling happens means
all the tasks would be done by the many algorithms that use for scheduling.
 Storage Management: The file system mechanism used for the management of
the storage. NIFS, CFS, CIFS, NFS, etc. are some file systems. All the data stores in
various tracks of Hard disks that all managed by the storage manager. It
included Hard Disk.
 Memory Management: Refers to the management of primary memory. The
operating system has to keep track, how much memory has been used and by
whom. It has to decide which process needs memory space and how much. OS also
has to allocate and deallocate the memory space.
 Security/Privacy Management: Privacy is also provided by the Operating system by
means of passwords so that unauthorized applications can’t access programs or
data. For example, Windows uses Kerberos authentication to prevent unauthorized
access to data.

• Booting is the process of starting a computer. After it is switched on, a


computer's central processing unit (CPU) has no software in its main memory, so
some process must load software into memory before it can be executed.

Types of Booting 

1. ColdBooting/SwitchBooting
When the user starts computer by pressing power switch on system unit, the
operating system is loaded from disk to main memory this type of booting is
called Cold Booting. This booting takes more time than Hot or Warm Booting.

2. HotorWarmBooting
Hot booting is done when computer system comes to no response state/hang state.
Computer does not respond to commands supplied by user. There are many
reasons for this state, only solution is to reboot computer by using the Reset
button on cabinet or by pressing a combination of ALT + CTRL + DEL keys from
keyboard.

LANGUAGE PROCESSORS

Compiler
The language processor that reads the complete source program written in high-level
language as a whole in one go and translates it into an equivalent program in machine
language is called a Compiler.  Example: C, C++, C#, Java.   
In a compiler, the source code is translated to object code successfully if it is free of errors.
The compiler specifies the errors at the end of the compilation with line numbers when
there are any errors in the source code. 

 Assembler
The Assembler is used to translate the program written in Assembly language into machine
code. The source program is an input of an assembler that contains assembly language
instructions. The output generated by the assembler is the object code or machine code
understandable by the computer. We need an Assembler to fill the gap between human and
machine so that they can communicate with each other.

Example of Assembly language: ADD R1,R2,R3

MOV R1,5

Interpreter
The translation of a single statement of the source program into machine code is done by a
language processor and executes immediately before moving on to the next line is called an
interpreter. If there is an error in the statement, the interpreter terminates its translating
process at that statement and displays an error message. The interpreter moves on to the
next line for execution only after the removal of the error. An Interpreter directly executes
instructions written in a programming or scripting language without previously converting
them to an object code or machine code.            
Example: Perl, Python and Matlab.
Compiler Interpreter

A compiler is a program that converts the


entire source code of a programming An interpreter takes a source
language into executable machine code program and runs it line by line,
for a CPU.   translating each line as it comes
  to it

The compiler takes a large amount of time An interpreter takes less


to analyze the entire source code but the amount of time to analyze the
overall execution time of the program is source code but the overall
comparatively faster.  execution time of the program is
  slower.

The compiler generates the error


message only after scanning the whole
program, so debugging is comparatively Its Debugging is easier as it
hard as the error can be present continues translating the
anywhere in the program.   program until the error is met.

It requires less memory than a


The compiler requires a lot of memory for compiler because no object
generating object codes. code is generated.

Generates intermediate object code.  No intermediate object code is


Compiler Interpreter

generated.

For Security purpose compiler is more The interpreter is a little


useful. vulnerable in case of security.

Examples: Python, Perl,


Examples: C, C++, Java   JavaScript, Ruby

PROGRAMMING ENVIRONMENT

 Source code refers to high level code or assembly code which is


generated by human/programmer. Source code is easy to read and
modify. It is written by programmer by using any High Level Language
or Intermediate language which is human-readable.
 Object code refers to low level code which is understandable by
machine. Object code is generated from source code after going
through compiler. It is in executable machine code format.
 Executable code is a file or a program that indicates tasks according
to encoded instructions. The CPU can directly execute an executable
file to defined tasks.
Difference between Linker and Loader
Linker Loader

Linker generates the executable Loader loads the executable module


module of a source program. to the main memory for execution.

Linker takes the object code Loader takes executable module


generated by an assembler, as generated by a linker as input.
Linker Loader

input.

Linker combines all the object Loader allocates the addresses to an


modules of a source code to executable module in main memory
generate an executable module. for execution.

The types of Loader are Absolute


The types of Linker are Linkage loading, Relocatable loading and
Editor, Dynamic linker. Dynamic Run-time loading.

Variables and Keywords in C


A variable is a storage place which has some memory allocated to it.
Basically, a variable is used to store some form of data.

Variable Declaration
type variable_name;
or for multiple variables:
type variable1_name, variable2_name, variable3_name;
Variable declaration refers to the part where a variable is first declared or
introduced before its first use. Variable definition is the part where the
variable is assigned a memory location and a value.
Variable Naming Convention
A variable name can consist of alphabets (both upper and lower case),
numbers and the underscore ‘_’ character.
Rules for defining variables
1. A variable can have alphabets, digits, and underscore.
2. A variable name can start with the alphabet, and underscore only. It
can’t start with a digit.
3. No whitespace is allowed within the variable name.
4. A variable name must not be any reserved word or keyword, e.g.
int, goto , etc.

Example: WAP to calculate area of a circle.


#include<stdio.h> // header file
int main() // function name
{
Int r,area; // variable declaration
Float f;
f=45.6;
r=4; // variable definition
scanf(“%d”,&r); // input function
area=(22/7)*r*r;
printf(“area of circle having radius %d is %d”,r,area); // output function
return 0;
}
Input=7
Output: area of circle having radius 7 is 154
Keywords are specific reserved words in C each of which has a specific
feature associated with it. There are a total of 44 keywords in C.
Example of keywords: continue,break,switch,if,else,void,return

Type Casting
A type cast is basically a conversion from one type to another. There are two
types of type conversion:
1. Implicit Type Conversion
Also known as ‘automatic type conversion’.
Done by the compiler on its own, without any external
trigger from the user.
 Generally, takes place when in an expression more than
one data type is present. In such condition type
conversion (type promotion) takes place to avoid loss of
data.
 All the data types of the variables are upgraded to the
data type of the variable with largest data type.
Example of Type Implicit Conversion:

Explicit Type Conversion


This process is also called type casting and it is user defined. Here the user
can type cast the result to make it of a particular data type.
The syntax in C:
(type) expression
Type indicates the data type to which the final result is converted.

Types of Variables in C 
1. Local Variable 
A variable that is declared and used inside the function or block is
called local variable. It’s scope is limited to function or block. It cannot
be used outside the block.
2. Global Variable 
A variable that is declared outside the function or block is called a
global variable. It is declared at the starting of program. It is available
to all the functions. 
3. Static Variable 
A variable that retains its value between multiple function calls is
known as static variable. It is declared with the static keyword. 
4. Automatic Variable 
All variables in C that are declared inside the block, are automatic
variables by default. We can explicitly declare an automatic variable
using auto keyword.Automatic variables are similar as local variables.
5. External Variable 
External variable can be shared between multiple C files.We can
declare external variable using extern keyword.

Data Types in C
Each variable in C has an associated data type. Each data type
requires different amounts of memory and has some specific
operations which can be performed over it.Some very common data
types used in C:
 char: The most basic data type in C. It stores a single character
and requires a single byte of memory in almost all compilers.
 int: As the name suggests, an int variable is used to store an
integer.
 float: It is used to store decimal numbers (numbers with floating
point value) with single precision.
 double: It is used to store decimal numbers (numbers with floating
point value) with double precision.

Different data types also have different ranges upto which they can
store numbers. These ranges may vary from compiler to compiler.
Below is list of ranges along with the memory requirement and format
specifiers on 32 bit gcc compiler.
Memory Format
Data Type  (bytes)  Range  Specifier 
       

short int  2  -32,768 to 32,767  %hd 


       

unsigned
short int  2  0 to 65,535  %hu 
       

unsigned int  4  0 to 4,294,967,295  %u 


       

-2,147,483,648 to
int  4  2,147,483,647  %d 
       

-2,147,483,648 to
long int  4  2,147,483,647  %ld 
       

unsigned
long int  4  0 to 4,294,967,295  %lu 
       

long long int  8  -(2^63) to (2^63)-1  %lld 


       

unsigned 0 to
long long int  8  18,446,744,073,709,551,615  %llu 
       

signed char  1  -128 to 127  %c 


       

unsigned
char  1  0 to 255  %c 
       

float  4  %f 
       

double  8  %lf 
       

long double  16  %Lf 


       
Types of Errors
1. Syntax errors: Errors that occur when you violate the rules of
writing C/C++ syntax are known as syntax errors. This compiler
error indicates something that must be fixed before the code can be
compiled. All these errors are detected by compiler and thus are
known as compile-time errors. 
Most frequent syntax errors are: 
 Missing Parenthesis (})
 Printing the value of variable without declaring it
 Missing semicolon like this:
2. Logical Errors: On compilation and execution of a program, desired
output is not obtained when certain input values are given. These
types of errors which provide incorrect output but appears to be error
free are called logical errors. These are one of the most common
errors done by beginners of programming. 
3. Run-time Errors: Errors which occur during program execution(run-
time) after successful compilation are called run-time errors. One of
the most common run-time error is division by zero also known as
Division error.
Example of run-time error

#include<stdio.h>
void main()
{
    int n = 9, div = 0;
   
    // wrong logic
    // number is divided by 0,
    // so this program abnormally terminates
    div = n/0;
    printf("result = %d", div);
}

You might also like