Chapter 1
Chapter 1
Chapter 1
Computer is used to solve mainly numerical problems. Again it is not convenient to work with
symbolic representation. For that purpose we move to numeric representation. In this
convention, we use 0 to represent LOW and 1 to represent HIGH.
0 means LOW
1 means HIGH
To know about the working principle of computer, we use two numeric symbols only namely 0
and 1. All the functionalities of computer can be captured with 0 and 1 and its theoretical
background corresponds to two valued Boolean algebra.
With the symbol 0 and 1, we have a mathematical system, which is knows as binary number
system. Basically binary number system is used to represent the information and manipulation
of information in computer. This information is basically strings of 0s and 1s. (Everything needs
to be converted to strings of 0 and 1 to be processed in the computer)
The smallest unit of information that is represented in computer is known as Bit (Binary Digit),
which is either 0 or 1. Four bits together is known as Nibble, and Eight bits together is known as
Byte.
Non need to worry if the concepts mentioned above are not clear at this point because In this
course, we will touch upon all those factors and finally come up with the concept how these
attributes contribute to build a complete computer system
The model of a computer can be described by four basic units in high level abstraction
which is shown in the next figure. These basic units are:
2
Basic Computer Model and different units of Computer
o The program control unit has a set of registers and control circuit to
generate control signals.
o The execution unit or data processing unit contains a set of registers for
storing data and an Arithmetic and Logic Unit (ALU) for execution of
arithmetic and logical operations.
B. Input Unit:
With the help of input unit data from outside can be supplied to the computer.
Program or data is read into main storage from input device or secondary
storage under the control of CPU input instruction.
C. Output Unit :
With the help of output unit computer results can be provided to the user or it
can be stored in storage device permanently for future use. Output data from
main storage go to output device under the control of CPU output instructions.
Example of output devices: Printer, Monitor, Plotter, Hard Disk, Floppy Disk etc.
D. Memory Unit:
Memory unit is used to store the data and program. CPU can work with the
information stored in memory unit. This memory unit is termed as primary
memory or main memory module. These are basically semi conductor memories.
3
There are two types of semiconductor memories -
Secondary Memory:
o There is another kind of storage device, apart from primary or main memory,
which is known as secondary memory. Secondary memories are non volatile
memory and it is used for permanent storage of data and program.
o Example of secondary memories:
Hard Disk, Floppy Disk, Magenetic Tape ------ These are magnetic devices,
CD-ROM ------ is optical device
Thumb drive (or pen drive) ------ is semiconductor memory.
The present day digital computers are based on stored-program concept introduced by Von
Neumann. In this stored-program concept, programs and data are stored in separate storage
unit called memories.
Central Processing Unit, the main component of computer can work with the information
stored in storage unit only.
In 1946, Von Neumann and his colleagues began the design of a stored-program computer at
the Institute for Advanced Studies in Princeton.This computer is referred as the IAS computer.
4
The IAS computer is having three basic units:
This is the main unit of computer, which is responsible to perform all the operations. The CPU
of the IAS computer consists of a data processing unit and a program control unit.
The data processing unit contains a high speed registers intended for temporary storage of
instructions, memory addresses and data. The main actions specified by instructions are
performed by the arithmetic-logic circuits of the data processing unit.
The control circuits in the program control unit are responsible for fetching instructions,
decoding opcodes, controlling the information movements correctly through the system, and
providing proper control signals for all CPU actions.
It is used for storing programs and data. The memory locations of memory unit are uniquely
specified by the memory address of the location. M(X) is used to indicate the location of the
memory unit M with address X.
The data transfer between memory unit and CPU takes place with the help of data register DR.
When CPU wants to read some information from memory unit, the information first brings to
5
DR, and after that it goes to appropriate position. Similarly, data to be stored to memory must
put into DR first, and then it is stored to appropriate location in the memory unit.
The address of the memory location that is used during memory read and memory write
operations are stored in the memory register AR.
The information fetched from the memory is an operand of an instruction, and then it is moved
from DR to data processing unit (either to AC or MQ). If it is an operand, then it is moved to
program control unit (either to IR or IBR).
Two additional registers for the temporary storage of operands and results are included in data
processing units: the accumulator AC and the multiplier-quotient register MQ.
Two instructions are fetching simultaneously from M and transferred to the program control
unit. The instruction that is not to be executed immediately is placed in the instruction buffer
register IBR. The opcode of the other instruction is placed in the instruction register IR where it
is decoded.
In the decoding phase, the control circuits generate the required control signals to perform the
specified operation in the instruction.
The program counter (PC) is used to store the address of the next instruction to be fetched
from memory.
Input devices are used to put the information into computer. With the help of input devices we
can store information in memory so that CPU can use it. Program or data is read into main
memory from input device or secondary storage under the control of CPU input instruction.
Output devices are used to output the information from computer. If some results are
evaluated by computer and it is stored in computer, then with the help of output devices, we
can present it to the user. Output data from the main memory go to output device under the
control of CPU output instruction.
A mother guides her daughter to cook food for lunch. The mother knows how to cook food
from her past experience while the daughter listen instruction from her mother and accomplish
it to cook today’s lunch. The mother sits in a chair looking carefully the daughter who performs
the real tasks for cooking food. The daughter puts the tools that are needed to cook today’s
lunch in a bench/table near to her. But now she is to add salt so the puts the salt container the
table very near to her. However, those tools that are not needed to cook today’s lunch are put
in the table far away. For example: the daughter brings an instruction from mother who says
6
“bring salt”, and then the daughter brings the salt container. Then “add salt” instruction is
fetched from mother where the daughter adds salt to the cooking food.
Based on the above analogy, determine the following points in real computer: Mother,
Mother’s knowledge of how to cook food, Daughter, Register, RAM, External Storage
(Hard disk), Instruction, data. Check your answer with the one provided below. A
student who gets all the answers understands this chapter perfectly. Try it by yourself
before looking into the answer.
Answer:
Mother’s knowledge of how to cook food = programmer write algorithm/code on how to cook
food
Daughter = CPU (interpreting mother’s instruction and accomplishing the real lunch
preparation actions)
Register = bench very near to daughter containing the data (salt) or instruction saying “add
salt”
RAM: bench near to daughter containing data needed for today’s lunch preparation
External Storage (Hard disk) = bench far away from daughter containing data for not needed
for today’s lunch, may be for breakfast or dinner.
Data: salt.
The base of a number system specifies the actual number of digits included in its order. The size
of the number symbols determine the base of the number system. Decimal system includes
7
0,1,2,3,4,5,6,7,8,9. Binary system includes 0 and 1. Computers use binary system. (Why? the
reason to be clear as the course goes on). Decimal is human (our) language while binary is
digital language. Since computers are digital devices it uses binary languages (or binary
systems).
In general:
Decimal (base 10 system): 0,1,2,3,4,5,6,7,8,9. (10 symbols) which Is human language
Binary (base 2 system): 0, 1 (2 symbols) which is computer (or digital language)
Hexadecimal (or hexal) system: (base 16 system):
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F (16 symbols)
Octal (base 8 system): 0,1,2,3,4,5,6,7 ( 8 symbols):
Hexal and Octal systems are used to narrow the distance between human language (decimal
system) and digital systems. In other words, they are used to simplify our digital system so that
we can easily represent digital numbers in a very shorthand form. Note that base x system
always use x symbols (from 0 up to x-1). Also note that the more symbols a number system
has the fewer digits it will utilize for an equivalent number in other base.
For example:
(15)10 = (15)10 2 digits
= (1111)2 4 digits
= (F)16 1 digits
The positional nature of number system is very important. The number systems we use are in
weighted-positional notation.
Decimal number system, symbols = { 0, 1, 2, 3, …, 9 }
Position is important
o Example: (7594)10 = (7x103) + (5x102) + (9x101) + (4x100). The value of each
symbol is dependent on its type and its position in the number.
In general, (anan-1… a0)10 = (an x 10n) + (an-1 x 10n-1) + … + (a0 x 100)
Fractions are written in decimal numbers after the decimal point.
(2.75)10 = (2 x 100) + (7 x 10-1) + (5 x 10-2)
In general,
8
• Base R: weights in powers-of-R.
(1101.101)2 = 1´23 + 1´22 + 1´20 + 1´2-1 + 1´2-3= 8 + 4 + 1 + 0.5 + 0.125 = (13.625) 10
(572.6)8 = 5´82 + 7´81 + 2´80 + 6´8-1 = 320 + 56 + 16 + 0.75 = (392.75)10
(2A.8)16 = 2´161 + 10´160 + 8´16-1 = 32 + 10 + 0.5 = (42.5)10
(341.24)5 = 3´52 + 4´51 + 1´50 + 2´5-1 + 4´5-2 = 75 + 20 + 1 + 0.4 + 0.16 = (96.56) 10
9
6.2400000…=6.24
Rule: to the left of the radix point group each 3 binary digits and convert it to
octal; if a group of three can’t be fulfilled add zero to the left until fulfilled. To the
right of the radix point, group each 3 binary digits and convert it to octal, if a group
to three can’t be fulfilled, add zero digits to the right until fulfilled.
Example: (1001.1000011)2=(?)8
=001 001.100 001 100
=(11.414)8
Exercise: (1001001111.0000110001110) 2=(?)8
Ans=(1117.0307)8
Notice the following points when you do octal to binary conversion.
1 octal digit will be converted to exactly 3 binary digits
Rule: convert each octal digits into 3 binary digits.
Example: (123.3005)8=(?)2
=(001 010 111.011 000 000 101) 2
Exercise: (7113.7701)8=(?)2
Ans: (111001001011.111111000001)2
Notice the following points when you do binary to hexal conversion.
Four binary digits make one octal digit.
Putting zero to the left of a given number or right of the fractional part makes no
change in value.
o For example:
000…453=453
6.2400000…=6.24
Rule: to the left of the radix point group each 4 binary digits and convert it to
hexal; if a group of four can’t be fulfilled add zero to the left until fulfilled. To the
right of the radix point, group each r binary digits and convert it to hexal, if a group
to four can’t be fulfilled, add zero digits to the right until fulfilled.
Notice the following points when you do hexal to binary conversion.
1 hexal digit will be converted to exactly 4 binary digits
Rule: convert each hexal digit into 4 binary digits.
Note: students are expected to practice hexal/binary conversion based on examples provided
for octal/binary conversion.
Summary: conversion between bases
Binary to Octal: Partition in groups of 3
(10 111 011 001. 101 110)2 = (2731.56)8
Octal to Binary: reverse the above step
(2731.56)8 = (10 111 011 001. 101 110)2
Binary to Hexadecimal: Partition in groups of 4
(101 1101 1001. 1011 1000)2 = (5D9.B8)16 = 0x5D9.B8
Hexadecimal to Binary: reverse of the above step
(5D9.B8)16 = (101 1101 1001. 1011 1000)2
10
Table: Conversion map of common number systems. Try to remember this table, knowing it by
heart simplify a lot in the conversion process though it is possible to calculate this table by
simple conversion calculations discussed earlier.
11
each step and how the next step tries to solve the weakness of the previous. The
steps are:
I. Discuss a number of signed number representations (at least three)
II. Test each representation with a known calculation (using our previous decimal
number system knowledge) with strength and weakness of each representation.
III. For all our discussion, assume a fixed width 8 bit binary machine with the left
most bit representing the sign. Bits mean Binary digit (which is 0 or 1).This
means all numbers are assumed to be represented in 8 bits. More about this in
later chapters.
Now, let’s see the three most common signed number representations.
1) Sign magnitude representation.
2) 1’s complement (ones complement) representation.
3) 2’s complement (twos complement) representation.
The third (2’s complement) is the widely accepted and currently universal
representation used in binary number system. The reason will be discussed later.
In unsigned number representation (where all bits are used for value) number
representation
+3=00000001
-5= no representation for negative numbers
+126=01111110
-127=no representation for negative numbers
+254=11111110
12
1024=no representation because in 8 bit fixed width unsigned number
representation. We can only represent number from 0 (0000000) to 255 (11111111)
Problems of signed magnitude representation: there are two zeros, but we actually
have only one zero.
+0=0000000
-0=10000000
Now let’s check the usability of signed magnitude representation through arithmetic
examples.
a. 3 + 4 = (+3) + (+4)
= 00000011 +
00000100
= 00000111
=+7 which is a correct result. (it works when all numbers are positive
b. 3 – 4 = 3 + (-4)
=00000011 +
10000100
=10000111
= -7 which is the wrong answer.
c. 4 – 3 = 4 + (-3)
=00000100 +
10000011
=-7 which is again a wrong answer
d. -3 – 4 = (-3) + (-4)
=10000011 +
10000100
=100000111 the left most bit is the overflow, rejecting it gives
=00000111
=+7 again wrong answer.
What about -127 – 127?
This approach has several wrong answers.
Important note: the computer knows 0 and 1, it doesn’t know the sign, and the sign
should also be represented in 0 and 1. Moreover, subtraction should
be defined in terms of addition of signed numbers. You can’t have
subtraction without signed number representation.
2) 1’s complement
Positive number is exactly the same as sign numbers
Negative number is the complement of the negative number.
Complement of 1 is 0 and complement of 0 is 1. Symbol of complement
is ‘.
Example: +4=00000100
-4=(+4)’=(00000100)’
= 11111011
13
-3=(+3)’=(00000011)’
=11111100
To read a number
If the first bit is zero, put positive and take the remaining bits as
magnitude
If the first bit is one, first invert the remaining bits and take
them as a value with negative prefix.
Example:
a) 3 + 4 , students are expected to check this gives the correct result.
b) 3 – 4 = 3 + (-4)
= 00000011 +
11111011
= 11111110
= -1 which is a correct answer
c) 4 – 3 = 4 + (-3)
= 00000100 +
11111100
= 100000000 the left most bit is overflow, bring it add to the rest of the
value.
= 00000000 +
1
= 00000001
=+1 which is correct answer. But it is difficult to handle end around
carry in reality.
d) -4 -3 = (-3) + (-4)
= 11111011 +
11111100
=100000111 then handling the end around carry gives
= 00000111 +
1
=11111000
= -7 which is the correct answer , but still end around carry.
3) 2’s complement
14
Positive numbers same as sign magnitude and 1’s complement
Negative numbers = (positive representation)’ +1
Positive numbers read as just like 1’s complement
To read negative numbers (first bit 1), take the complement of the rest of
bits and add 1 to it.
Example: -4 = (00000100)’ + 1
= 11111011 + 1
= 11111100 (how do you read/interpret this number)
-3 = (00000011)’ +1
= 11111100 + 1
= 11111101
Success of 2’s complement
There is only one zero
o 00000000 = +0
o 11111111 = -1
There is no end around carry, if overflow occurs just discard it. Discarding
carry is easier than end around carry.
15