Lecture 3 ELL305
Lecture 3 ELL305
21/08/2021
Recap of Last Lectures
• Basics of Computer Architecture
• Computer Systems and its components
• Language of Bits
• Boolean Algebra
• Number system
• Conversions from different number systems
How to add binary numbers
• Consider adding two 1-bit binary numbers x and y
– 0+0 = 0
– 0+1 = 1
– 1+0 = 1 x y Carry Sum
– 1+1 = 10 0 0 0 0
0 1 0 1
1 0 0 1
• Carry is x AND y 1 1 1 0
• Sum is x XOR y
• The circuit to compute this is called a half-adder
3
The half-adder
x y Carry Sum
• Sum = x XOR y 0 0 0 0
• Carry = x AND y 0 1 0 1
1 0 0 1
1 1 1 0
4
Using half adders
• We can then use a half-adder to compute the
sum of two Boolean numbers
1 0 0
1 1 0 0
+1 1 1 0
? 0 1 0
5
How to fix this
• We need to create an adder that can take a carry bit as
an additional input
– Inputs: x, y, carry in x y c carry sum
– Outputs: sum, carry out 1 1 1 1 1
• This is called a full adder 1 1 0 1 0
– Will add x and y with a half-adder 1 0 1 1 0
– Will add the sum of that to the
carry in 1 0 0 0 1
• What about the carry out? 0 1 1 1 0
– It’s 1 if either (or both): 0 1 0 0 1
– x+y = 10
0 0 1 0 1
– x+y = 01 and carry in = 1
0 0 0 0 0
6
x y c s1 c1 carry sum
The full adder 1 1 1 0 1 1 1
1 1 0 0 1 1 0
1 0 1 1 0 1 0
• The “HA” boxes are
1 0 0 1 0 0 1
half-adders
0 1 1 1 0 1 0
0 1 0 1 0 0 1
0 0 1 0 0 0 1
0 0 0 0 0 0 0
s1
c1
7
The full adder
• The full circuitry of the full adder
8
Adding bigger binary numbers
• Just chain full adders together
x0 X HA S
s0
y0 Y C
x1
C
X
FA S
s1
y1 Y C
x2
C
X
FA S
s2
y2 Y C
x3
C
X
FA S
s3
y3 Y C
c
...
9
Adding bigger binary numbers
• A half adder has 4 logic gates
• A full adder has two half adders plus a OR gate
– Total of 9 logic gates
• To add n bit binary numbers, you need 1 HA and n-1
FAs
• To add 32 bit binary numbers, you need 1 HA and 31
FAs
– Total of 4+9*31 = 283 logic gates
• To add 64 bit binary numbers, you need 1 HA and 63
FAs
– Total of 4+9*63 = 571 logic gates
10
More about logic gates
• To implement a logic gate in hardware, you
use a transistor
• Transistors are all enclosed in an “IC”, or
integrated circuit
• The Intel Pentium IV processors have 55
million transistors!
11
Representing Negative Integers
• Problem
• Assign a binary representation to a negative integer
• Consider a negative integer, S
• Let its binary representation be : xnxn-1….x2x1 (xi=0/1)
• We can also expand it to represent an unsigned, +ve,
number, N
• If we interpret the binary sequence as :
• An unsigned number, we get N
• A signed number, we get S
Continued…
● We need a mapping :
– F : S → N (mapping function)
– S → set of numbers (both positive and negative –
signed)
– N → set of positive numbers (unsigned)
mapping
Set of
Set of +ve
+ve and -ve
numbers
numbers
Properties of the Mapping Function
SgnBit(u) = 1,u<0
0 , u >= 0
Sign-Magnitude Base
Representation
Examples :
-5 in a 4 bit number system : 1101
5 in a 4 bit number system : 0101
-3 in a 4 bit number system : 1011
Problem
There are two representations for 0
000000
100000
Addition and subtraction are difficult
The most important takeaway point :
Notion of the sign bit
1's Complement Representation
Examples in a 4 bit number system
3 → 0011
-3 → 1100
5 → 0101
-5 → 1010
Problem
Two representations for 0
0000000
1111111
Easy to add +ve numbers
Hard to add -ve numbers
Point to note :
The idea of a complement
2's Complement Notation
Examples
4 → 0100
-4 → 1100
5 → 0101
-3 → 1101
The Number Circle
0000 (0)
1111 (15)
0001 (1)
1110 (14)
0010 (2)
1101 (13) 0011 (3)
Increment
1100 (12) 0100 (4)
0101 (5)
1011 (11)
0110 (6)
1010 (10)
0111 (7)
1001 (9)
1000 (8)
Clockwise: increment
Anti-clockwise: decrement
20
Number Circle with Negative Numbers
0000 (0)
1111 (-1)
0001 (1)
1110 (-2)
0010 (2)
1101 (-3) 0011 (3)
Increment
1100 (-4) 0100 (4)
0101 (5)
1011 (-5)
0110 (6)
1010 (-6)
0111 (7)
1001 (-7)
1000 (-8)
break point
21
Using the Number Circle
To add M to a number, N
locate N on the number circle
If M is +ve
Move M steps clockwise
If M is -ve
Move M steps anti-clockwise, or 2n – M steps
clockwise
If we cross the break-point
We have an overflow
The number is too large/ too small to be represented
22
2's Complement Notation
ìï
u, 0 £ u £ 2 n-1 -1
F(u) = í n n-1
ïî 2 - | u |, -2 £u<0
F(u) is the index of a point on the number
circle. It varies from 0 to 2n - 1
Examples
4 → 0100
-4 → 1100
5 → 0101
-3 → 1101
23
Properties of the 2's Complement Notation
25
Floating-Point Numbers
26
Generic Form for Positive Numbers
Example :
3.29 = 3 * 100 + 2*10-1 + 9*10-2
27
Generic Form in Base 2
Generic form of a number in base 2
n
A = å xi 2 i
i=-n
Number Expansion
0.375 2–2 +2 –3
1 20
1.5 20 +2 –1
2.75 21 +2 –1 +2 –2
17.625 24 +2 0 +2 –1 +2 –3
28
Binary Representation
29
Normalized Form
Let us create a standard form of all
floating point numbers
A = (-1)S *P *2 X , (P = 1+ M, 0 £ M <1, X Î Z)
30
Examples (in decimal)
1.3827 * 1e-23
Significand (P) = 1.3827
Mantissa (M) = 0.3827
Exponent (X) = -23
Sign (S) = 0
-1.2*1e+5
P = 1.2 , M = 0.2
S = 1, X = 5
31
IEEE 754 Format
General Principles
The significand is of the form : 1.xxxxx
32
IEEE 754 Format - II
1 8 23
33
Representation of the Exponent
Biased representation
bias = 127
E = X + bias
Range of the exponent
0 – 255 ⟷ -127 to +128
Examples :
X = 0, E = 127
X = -23, E = 104
X = 30 , E = 157
34
Memories
• A memory is just like a human brain. It is used to store
data and instructions.
• Computer memory is the storage space in the computer,
where data is to be processed and instructions required
for processing are stored.
• The memory is divided into large number of small parts
called cells.
• Each location or cell has a unique address, which varies
from zero to memory size minus one. For example, if
the computer has 64k , then this memory unit has 64 *
1024 = 65536 memory locations. The address of these
locations varies from 0 to 65535.
35
Types of Memory
• Memory is primarily of three types −
– Cache Memory
– Primary Memory/Main Memory
– Secondary Memory
36
Cache Memory
• Cache memory is a very high speed
semiconductor memory which can speed up the
CPU.
• It is used to hold those parts of data and program
which are most frequently used by the CPU.
• The parts of data and programs are transferred
from the disk to cache memory by the operating
system, from where the CPU can access them.
37
Continued…
Advantages
• Cache memory is faster than main memory.
• It consumes less access time as compared to main
memory.
• It stores the program that can be executed within
a short period of time.
• It stores data for temporary use.
Disadvantages
• Cache memory has limited capacity.
• It is very expensive.
38
Primary Memory
• Primary memory holds only those data and
instructions on which the computer is currently
working.
• It has a limited capacity and data is lost when
power is switched off.
• It is generally made up of semiconductor
device. The data and instruction required to be
processed resides in the main memory. It is
divided into two subcategories RAM and
ROM.
39
Continued..
• These are semiconductor memories.
• It is known as the main memory.
• Usually volatile memory.
• Data is lost in case power is switched off.
• It is the working memory of the computer.
• Faster than secondary memories.
• A computer cannot run without the primary
memory.
40
Secondary Memory
• This type of memory is also known as external
memory or non-volatile.
• It is slower than the main memory.
• These are used for storing data/information
permanently.
• CPU directly does not access these memories,
instead they are accessed via input-output
routines. The contents of secondary memories are
first transferred to the main memory, and then the
CPU can access it.
• For example, disk, CD-ROM, DVD, etc
41
Continued…
• These are magnetic and optical memories.
• It is known as the backup memory.
• It is a non-volatile memory.
• Data is permanently stored even if power is
switched off.
• It is used for storage of data in a computer.
• Computer may run without the secondary
memory.
• Slower than primary memories.
42
RAM (Random Access Memory)
• RAM (Random Access Memory) is the internal
memory of the CPU for storing data, program,
and program result.
• It is a read/write memory which stores data until
the machine is working.
• As soon as the machine is switched off, data is
erased.
• RAM is of two types −
– Static RAM (SRAM)
– Dynamic RAM (DRAM)
43
Static RAM
• The word static indicates that the memory retains its
contents as long as power is being supplied. However, data
is lost when the power gets down due to volatile nature.
• SRAM chips use a matrix of 6-transistors and no capacitors.
Transistors do not require power to prevent leakage, so
SRAM need not be refreshed on a regular basis.
• There is extra space in the matrix, hence SRAM uses more
chips than DRAM for the same amount of storage space,
making the manufacturing costs higher.
• SRAM is thus used as cache memory and has very fast
access.
44
Characteristics of SRAM
• Long life
• No need to refresh
• Faster
• Used as cache memory
• Large size
• Expensive
• High power consumption
45
Dyanamic RAM (DRAM)
• DRAM, unlike SRAM, must be
continually refreshed in order to maintain the
data.
• This is done by placing the memory on a
refresh circuit that rewrites the data several
hundred times per second.
• DRAM is used for most system memory as it
is cheap and small. All DRAMs are made up
of memory cells, which are composed of one
capacitor and one transistor.
46
Continued…
Characteristics of Dynamic RAM
• Short data lifetime
• Needs to be refreshed continuously
• Slower as compared to SRAM
• Used as RAM
• Smaller in size
• Less expensive
• Less power consumption
47
Read Only Memory (ROM)
• The memory from which we can only read but
cannot write on it.
• This type of memory is non-volatile.
• The information is stored permanently in such
memories during manufacture.
• A ROM stores such instructions that are
required to start a computer.
• ROM chips are not only used in the computer
but also in other electronic items like washing
machine and microwave oven.
48
MROM (Masked ROM)
• The very first ROMs were hard-wired devices
that contained a pre-programmed set of data
or instructions.
• These kind of ROMs are known as masked
ROMs, which are inexpensive.
49
PROM (Programmable Read Only
Memory)
• PROM is read-only memory that can be
modified only once by a user.
• The user buys a blank PROM and enters the
desired contents using a PROM program.
• Inside the PROM chip, there are small fuses
which are burnt open during programming.
• It can be programmed only once and is not
erasable
50
EPROM (Erasable and Programmable
Read Only Memory)
• EPROM can be erased by exposing it to ultra-violet
light for a duration of up to 40 minutes.
• Usually, an EPROM eraser achieves this function.
During programming, an electrical charge is trapped in
an insulated gate region.
• The charge is retained for more than 10 years because
the charge has no leakage path.
• For erasing this charge, ultra-violet light is passed
through a quartz crystal window (lid).
• This exposure to ultra-violet light dissipates the charge.
During normal use, the quartz lid is sealed with a
sticker
51
Characteristics of ROM
Advantages of ROM
• The advantages of ROM are as follows −
• Non-volatile in nature
• Cannot be accidentally changed
• Cheaper than RAMs
• Easy to test
• More reliable than RAMs
• Static and do not require refreshing
• Contents are always known and can be verified
52
EEPROM (Electrically Erasable and
Programmable Read Only Memory)
• EEPROM is programmed and erased electrically.
• It can be erased and reprogrammed about ten
thousand times.
• Both erasing and programming take about 4 to 10
ms (millisecond).
• In EEPROM, any location can be selectively
erased and programmed.
• EEPROMs can be erased one byte at a time,
rather than erasing the entire chip. Hence, the
process of reprogramming is flexible but slow.
53
Flip-flops
• Consider the following circuit:
55
Hexadecimal
• A numerical range from
0-15
– Where A is 10, B is 11, …
and F is 15
• Often written with a ‘0x’
prefix
• So 0x10 is 10 hex, or 16
– 0x100 is 100 hex, or 256
• Binary numbers easily
translate:
56