Essentials of Computer Science-Week1-5
Essentials of Computer Science-Week1-5
co
py
rig
ht
re
ESSENTIALSs er OF COMPUTER
ve
SCIENCE db
Dr. K. Rajbabu M.E.y Ph.D
D r.
Manager, Controls & Instrumentation
BHEL, Trichy
K.
Ra
jba
bu
@
co
py
rig
ht
re
s er
CONCEPT – PROGRAM – INPUT –
ve
PROCESSING d b - OUTPUT
yD
r.
K.
Ra
jba
bu
@
co
p yri
LANGUAGE
gh
t re
Human Language
se
rve and communication of messages
Commonly used to express feelings
db
It can be oral or gestural communication
Computer Language yD
Computer language are the languages by which r.a user command a
K . Rand expected
computer to work on the algorithm for the desired input
output ajb
ab
u
@
co
p yri
PROGRAM
gh
t re
se
A program is a series of organized instructions that directs a computer to
perform task rve
db
yD
r.
K.
Ra
jba
b u
@
co
p yri
PROGRAMMING LANGUAGE
gh
tr
Programming languageesis a set of words, symbols and codes that enables
er with computer
ve
humans to communicate effectively
by
Operands – to identify the data to be processed
Comparatively easier
e rve
db
Symbolic Operation codes replaced binary codes
y D
Code is translated to object code using ASSEMBLER
r.
K.
Ra
jba
bu
@
co
p yri LANGUAGE
ASSEMBLY
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri LANGUAGE
ASSEMBLY
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p
COMPARISONyri
gh
Parameters tMachine
re Level Language It is above Assembly Level Language
selevel in the hierarchy language inthethemachine
It is at the lowest
level
Hierarchy Level r
and has zero abstraction
ve level from the
hierarchy and so has
less abstraction level from the
hardware.
d b hardware.
Learning Curve It is hard to understand by Humans.
y D It is easy to learn and maintain.
Written as It is written in binary that is 0 or 1. reasy. to understand.
It is written in simple English and is
It is a first-generation programming
K
It is the .second-generation
Generation
language. programming Ralanguage.
Requirement for
Translator/Assembler
The machine code is executed directly It requires an assembler j b amachine
to convert
so no translator is required. assembly language to bu code.
@
co
p yri
HIGH-LEVEL LANGUAGE
gh
tr
esus to write programs that are independent of the type of
High-level language allows
er
computer.
ve
Focus only on attention towards Logic. d
b
The language needs a compiler to translate a y
language.
D
high-level language into a low-level
r.
The high-level language is easy to learn & maintain.
K .R
a jba
The high-level languages are portable i.e. they are machine-independent.
bu
@
co
p
COMPARISONyri
gh
Parameters
t re Low-Level Language High-Level Language
s e
understood byrcomputers.
It is machine friendly i.e. easily It is user friendly, as it is written
Level of Understanding
ve in simple English.
Time of Execution Takes time to execute.db Executes at a faster pace.
y D
It requires the assembler to convert
It requires the compiler to
assembly code to machine code. r
Tool Required convert the high-level language
. KIt is. portable.
to machine instructions.
Portability
Memory Efficiency
It is not portable.
It is memory efficient.
R ajb efficient.
It is less memory
Debugging and
Not easy Easy
ab
Maintenance u
@
co
p yrLLL
HLL VS
igh
t re
Low Level Language (LLL) High Level Language (HLL)
Direct memory Management se Interpreted
More memory efficient rve Less memory efficient
Strictly hardware dependent d Mostly
byperformance
independent of hardware
Faster than high level language Poor
Dr
Complex in nature
Statements corresponds to clock cycles
.
Easy to maintain
K.
Codes are concise
Needs assembler Ra
Needs compiler or interpreter
Machine code and Assembly language Python, Java, C++ etc jba
bu
@
co
p yriLEVEL PROGRAMMING LANGUAGE
HIGHER
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
PROCEDURAL LANGUAGE
gh
tr
es
This programming paradigm, derived from structured programming specifies a series of
er
well-structured procedures and steps to compose a program.
ve
It provides a set of commands by segregating the program into variables, functions,
db
statements & conditional operators.
yD
Various Programming editors or IDEs help users develop programming code using one or
r.
more programming languages.
K.
Ra
Some of them are Adobe Dreamweaver, Eclipse or Microsoft visual studio, BASIC, C, Java,
PASCAL, FORTRAN are examples of Procedural Programming Language.
jba
b u
@
co
py
FUNCTIONAL PROGRAMMING
rig
LANGUAGES
ht
reparadigm constructed by applying and composing functions.
Declarative programming
se
rveand declarations than on the execution of
The language emphasizes expressions
statements. db
The foundation of functional programming is y lambda calculus which uses conditional
D
expressions and recursion to perform the calculations. r
.K
. statements
It does not support iteration like loop statements & conditional
R like if-else.
#include <iostream>
int main() {
return 0;
}
JAVA PROGRAM
FileName : "HelloWorld.java". */ {
window.
DEVELOPMENT CYCLE (PDLC)
Define
Scope, objective
Analyze
Input – process - output
Assumptions, deliverables, exceptions
Algorithm development
Coding and Documentation
Testing and Debugging
Maintenance
ALGORITHM
Space complexity
How much space is required
Time complexity
How much time does it take to run the algorithm
GENERAL ANALYSIS
Further, dependency on
amount of input
Sequence of input
WHAT DOES “SIZE OF THE INPUT” MEAN?
If we are searching an array, the “size” of the input could be the size of the array
If we are merging two arrays, the “size” could be the sum of the two array sizes
If we are computing the nth Fibonacci number, or the nth factorial, the “size” is n
We choose the “size” to be the parameter that most influences the actual
time/space required
It is usually obvious what this parameter is
Better execution time is through algorithm with linear growth for large amount
of data
TIME ANALYSIS
Ignore the constants and arrive at a common notation with respect to ‘n’ with the
highest value.
IS IT POSSIBLE TO FIND EXACT VALUES?
We know exactly how many bytes and how many cycles each machine instruction takes
For a problem with a known sequence of steps (factorial, Fibonacci), we can determine
how many instructions of each type are required
The steps required to sort an array depend on the actual numbers in the array (which
we do not know in advance)
HIGH LEVEL LANGUAGES
n a higher-level
level language (such as Java), we do not know how long each operation
akes
Which is faster, x < 10 or x <= 9 ?
We don’t know exactly what the compiler does with this
The compiler probably optimizes the test anyway (replacing the slower version with the
faster one)
n a higher-level
level language we cannot do an exact analysis
Our timing analyses will use major oversimplifications
Nevertheless, we can get some very useful results
CONSTANT TIME
Constant time means there is some constant k such that this operation always takes k
nanoseconds
It does not include calling a method whose time is unknown or is not a constant
f a statement involves a choice (if or switch) among operations, each of which takes constant
ime, we consider the statement to take constant time
This is consistent with worst-case analysis
LINEAR TIME
We may not be able to predict to the nanosecond how long a Java program will take, but
do know some things about timing:
for (i = 0, j = 1; i < n; i++) { j = j * i;; }
Which is better?
Clearly, algorithm B is better if our problem size is small, that is, if n < 50
Algorithm A is better for larger problems, with n > 50
So B is better on small problems that are quick anyway
But A is better for large problems, where it matters more
and you want to test whether every element of the first set (sub) also occurs in the second set (super):
System.out.println(subset(sub, super));
(The answer in this case should be false, because sub contains the integer 5, and super doesn’t)
We are going to write method subset and compute its time complexity (how fast it is)
Let’s start with a helper function, member, to test whether one number is in an array
22
MEMBER
static boolean member(int x, int[] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
if (x == a[i]) return true;
}
return false;
}
If x is not in a, the loop executes n times, where n = a.length
This is the worst case
If x is in a, the loop executes n/2 times on average
Either way, linear time is required: k*n+c
SUBSET
static boolean subset(int[] sub, int[] super) {
int m = sub.length;
for (int i = 0; i < m; i++)
if (!member(sub[i], super) return false;
return true;
}
The loop (and the call to member) will execute:
m = sub.length times, if sub is a subset of super
This is the worst case, and therefore the one we are most interested in
Fewer than sub.length times (but we don’t know how few)
We would need to figure this out in order to compute average time complexity
The worst case is a linear number of times through the loop
But the loop body doesn’t take constant time, since it calls member, which takes linear time
ANALYSIS OF ARRAY SUBSET ALGORITHM
We’ve seen that the loop in subset executes m = sub.length times (in the worst case)
Also, the loop in subset calls member, which executes in time linear in n = super.length
Hence, the execution time of the array subset method is m*n, along with assorted
constants
We go through the loop in subset m times, calling member each time
25
WHAT ABOUT THE CONSTANTS?
An added constant, f(n)+c, becomes less and less important as n gets larger
Our timing formula is a polynomial, and may have terms of various orders (constant,
linear, quadratic, cubic, etc.)
We usually discard all but the highest-order
order term
We simplify n2 + 3n + 5 to just n2
BIG O NOTATION
Recall that, if n is the size of the set, and m is the size of the (possible) subset:
We go through the loop in subset m times, calling member each time
Hence, the actual running time should be k*(m*n) + c, for some constants k and c
31
Y = X2 + 3X + 5, FOR X=1..20
32
COMMON TIME COMPLEXITIES
33
ALGORITHM
Repeat for I = 1 to N
Repeat for J = 1 to N
SUM 0
Repeat for K = 1 to N
SUM SUM + A[I, K] * B[K, J]
End Repeat K
C[I,J] SUM
End Repeat J
End Repeat I
ORDER NOTATION
asymptotic behavior
O(n2) means that the running time of the algorithm on an input of size n is
limited by the quadratic function of n
BIG-OH
OH NOTATION DEFINITION
The big-Oh
Oh notation gives an upper bound on the growth rate of a function
The statement “f(n) is O(g(n))”” means that the growth rate of f(n) is no more than the
growth rate of g(n)
f (n ) = a 0 + a 1 n + a 2 n 2 + ... + a d n d
Example:
We determine that algorithm arrayMax executes at most 7n − 1 primitive operations
n log(n) n nlog(n) n2 n3 2n
8 3 8 24 64 512 256
Some algorithms may be more efficient if data completely loaded into memory
Need to look also at system limitations
E.g. Classify 2GB of text in various categories [politics, tourism, sport, natural
disasters, etc.] – can I afford to load the entire collection?
SPACE COMPLEXITY
Variable part: Space needed by variables, whose size is dependent on the size
of the problem:
- e.g. actual text
- load 2GB of text VS. load 1MB of text
SPACE COMPLEXITY
Space complexity is the amount of memory used by the algorithm (including the
input values to the algorithm) to execute and produce the result.
Instruction Space: It's the amount of memory used to save the compiled version of
instructions.
algorithm(function). In such a situation, the current variables are pushed onto the system
stack, where they wait for further execution and then the call to the inside
algorithm(function) is made.
MEMORY DURING EXECUTION
For example, If a function A() calls function B() inside it, then all th variables of the
function A()will get stored on the system stack temporarily, while the function B() is called
But while calculating the Space Complexity of any algorithm, we usually consider only Data
Linear: int sum(int A[], int n) { int sum = 0, i; for(i = 0; i < n; i++) sum = sum + A[i];
return sum; }
RELATIVES OF BIG-OH
big-Omega
f(n) is Ω(g(n))
(g(n)) if there is a constant c > 0 and an integer constant n0 ≥ 1 such that
f(n) ≥ c•g(n) for n ≥ n0
big-Theta
f(n) is Θ(g(n))
(g(n)) if there are constants c’ > 0 and c’’ > 0 and an integer constant n0 ≥
1 such that c’•g(n) ≤ f(n) ≤ c’’•g(n) for n ≥ n0
EXAMPLES
You go and ask the first person of the class, if he has the pen. Also, you ask this person about
other 99 people in the classroom if they have that pen & So on.
O(log n): Now I divide the class in two groups, then ask: “Is it on the left side, or the right
side of the classroom?” Then I take that group and divide it into two and ask again, and so
on. Repeat the process till you are left with one student who has your pen. This is what you
mean by O(log n).
PROBLEM
int i, j, k = 0;
for (i = n / 2; i <= n; i++) {
for (j = 2; j <= n; j = j * 2) {
k = k + n / 2;
}
}
Output:
O(nLogn)
PROBLEM
int a = 0, i = N;
while (i > 0) {
a += i;
i /= 2;
}
@
co
py
rig
ht
re
se
PROGRAM rveEXECUTION
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
PROGRAM
gh
t re
Plain text
se
Parsing rve
Text to command
db
Command to low level language
y Dr.
K.
Ra
jba
bu
@
co
p yri
C COMPILER
gh
t re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
C COMPILER
gh
t re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
C COMPILER
gh
t re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
JAVA COMPILER
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p
JAVA BYTEyri CODE
gh
tr
View compiled class file in texte
se
editor
Bus
e rve
Main Memory (RAM)
db
Secondary Storage Media
y Dr.
I / O Devices K.
Ra
jba
bu
@
co
CENTRALp yri PROCESSING UNIT
gh
tr
Central Processing Unit e
se
The “brain” of the computer rve
Controls all other computer functions
db
y Dr or simply processor.
In PCs (personal computers) also called the microprocessor
.K
.R
ajb
ab
u
@
co
p
BUS y rig
ht
re connected by a bus.
Computer components are
se
A bus is a group of parallel wiresrthat
vecarry control signals and data between
components. db
yD
r.
K.
Ra
jba
bu
@
co
p
MAINyMEMORY rig
ht
re such as computer programs, numeric data, or
Main memory holds information
documents created by a worde
s
rve
processor.
. theKinformation in main
Main memory is volatile storage. That is, if power is lost,
memory is lost. .R
ajb
ab
u
@
co
p
MAINyMEMORY rig
ht
re can
Other computer components
se
rve
get the information held at a particular address in memory, known as a READ,
db
or store information at a particular address in memory, known as a WRITE.
y
Writing to a memory location alters its contents. D
r .K
Reading from a memory location does not alter its contents.
.R
ajb
ab
u
@
co
p
MAINyMEMORY (CON’T)
rig
ht
r eaccessed
• All addresses in memory can be se in the same amount of time.
• rveread everything until we get to the address we
We do not have to start at address 0 and
really want (sequential access). db
• y theDdata (direct or random access).
We can go directly to the address we want and access
• r.
That is why we call main memory RAM (Random Access Memory).
K.
Ra
jba
26 bu
@
co
SECONDARYp yri STORAGE MEDIA
gh
t r (random access)
Disks -- floppy, hard, removable
es
•
•
Tapes (sequential access)
computer programs
D r.
•
• data
K .R
• other types of information ajb
ab
This type of storage is called persistent (permanent) storage because it is non-volatile.
• 27
u
@
co
p yri
I/O (INPUT/OUTPUT) DEVICES
gh
t
Information input and outputrise handled by I/O (input/output) devices.
se as peripheral devices.
More generally, these devices are known
Examples:
rve
monitor db
keyboard
mouse
yD
disk drive (floppy, hard, removable) r .
CD or DVD drive K.
printer
scanner
Rajb
ab
28
u
@
co
p yri LEVEL HIERARCHY
COMPUTER
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
py
rig
ht
re
se
DIGITALrve SYSTEM
db
yD
r.
K.
Ra
jba
bu
@
co
p yri OF DIGITAL SYSTEM
ELEMENTS
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri ARCHITECTURE
GENERAL
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri ARCHITECTURE
DETAILED
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
CENTRAL p yri PROCESSING UNIT (CPU)
gh
tr
esof the processor. Also called as Control Unit
Coordinates the operation
e rvunit
Manages memory, arithmetic/logic
ed and input and output devices
by
Also known as the nerve center of a computer system.
.K
.R
ajb
ab
u
@
co
p yri
REGISTERS
gh
t re
se
The Program counter is one of the most critical registers in CPU.
The MAR holds the address of the maindmemory to or from which data is to be
transferred.
by
D
The MDR contains the data to be written into or readrfrom
. Kthe addressed word
of the main memory. .R
ajb
ab
u
@
co
p yri
REGISTERS
gh
t re
s
The two registers MAR and MDR are used to handle the data transfer between
er
ve
the main memory and the processor.
The MAR holds the address of the maindmemory to or from which data is to be
transferred.
by
D
The MDR contains the data to be written into or readrfrom
. Kthe addressed word
of the main memory. .R
ajb
ab
u
@
co
p yri
REGISTERS
gh
t re
se
Accumulator: Stores the results of calculations made by ALU.
Program Counter (PC): Keeps trackrveof the memory location of the next
d passes
instructions to be dealt with. The PC then
by this next address to Memory
Address Register (MAR).
D
Memory Address Register (MAR): It stores the memoryr. locations of instructions
that need to be fetched from memory or stored into memory..
K
Ra
jba
bu
@
co
p yri
REGISTERS
gh
t re
s
Memory Data Register (MDR): It stores instructions fetched from memory or any
data that is to be transferred e
to,rand stored in, memory.
ve
d theb most recently fetched instructions
Current Instruction Register (CIR): It stores
while it is waiting to be coded and executed. y
D
Instruction Buffer Register (IBR): The instruction that isr.
not to be executed
K
immediately is placed in the instruction buffer register IBR. .
Ra
jba
bu
@
co
p yri PURPOSE VS SPECIAL PURPOSE
GENERAL
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
REGISTERS
gh
t re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p
COMPUTERS yri
gh
tr
Fixed Program Computers es– Their function is very specific and they couldn’t be
programmed, e.g. Calculators.er
ve
Stored Program Computers – These can dbebprogrammed to carry out many
yhence
different tasks, applications are stored on them,
Dr
the name.
.K
.R
ajb
ab
u
@
co
p yri PROGRAM CONCEPT
STORED
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
STOREDp yri PROGRAM CONCEPT
gh
tr
Van Neumann – Common esstorage for both data and instruction
e rve
Harvard - Separate data and instruction
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
VON NEUMANN ARCHITECTURE
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri ARCHITECTURE
HARVARD
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
c
VONo
p
NEUMANN ARCHITECTURE
yri
COMPARISON
HARVARD ARCHITECTURE
It is ancient computer architecture based on stored It is modern computer architecture based on
gh
program computer concept. Harvard Mark I relay based model.
tr
Same physical memory address is used for Separate physical memory address is used for
es
instructions and data. instructions and data.
er
transfer. ve
There is common bus for data and instruction Separate buses are used for transferring data and
instruction.
db
Two clock cycles are required to execute single
instruction.
yD An instruction is executed in a single cycle.
It is cheaper in cost.
r. It is costly than van neumann architecture.
K.
CPU can not access instructions and read/write at CPU can access instructions and read/write at the
the same time.
Ra same time.
bu
@
co
FLYNN’S p yri CLASSIFICATION OF COMPUTERS
gh
t re of instructions read from memory
Instruction Stream: Sequence
se on the data in the processor
Data Stream: Operations performed
rve
db
yD
r.
K.
Ra
jba
bu
@
co
py
rig
ht
re
se
CONTROLrve UNIT
db
yD
r.
K.
Ra
jba
bu
@
co
p yri UNIT
CONTROL
gh
tr
es
Fetches internal instructions of the programs from the
er
main memory to the processor instruction register, and
ve
based on this register contents, the control unit generates
db
a control signal that supervises the execution of these
instructions. yD
A control unit works by receiving input information to r.
which it converts into control signals, which are then sent K.
to the central processor. The computer’s processor then Ra
tells the attached hardware what operations to perform.
jba
bu
@
co
p yri UNIT
CONTROL
gh
tr
es
It coordinates the sequence of data movements into, out of, and between a processor’s many sub-
units. er
ve
db
It interprets instructions.
yD
It controls data flow inside the processor.
r.
It receives external instructions or commands to which it converts to sequence of control signals.
K.
Ra
It controls many execution units(i.e. ALU, data buffers and registers) contained within a CPU.
jba
It also handles multiple tasks, such as fetching, decoding, execution handling and storing results.
b u
@
co
p yri
CLASSIFICATION OF CONTROL UNIT
gh
t
Hardwired Control re
Microprogrammed Controlse
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri UNIT
CONTROL
gh
tr
es
Two types – Hardwired
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
CONTROL p yri UNIT – INPUT & OUTPUT
gh
tr
INPUT es OUTPUT
e rve11 The control of the inputs of the nine registers
Two decoders, I flip-flop and bits 0 through
of IR. d bThe control of the read and write inputs of
AC (bits 0 through 15), DR (bits 0 through 15), yD
memory
and the value of the seven flip-flops. r. or complement the flip-flops
To set, clear,
K.
Raaregister for the bus
S2, S1, and SO to select
j anda logic circuit.
The control of the AC adderb
bu
@
co
py
HARDWIRED
rig UNIT
CONTROL
ht
re
se
Control logic to be implemented with
gates, flip-flops, decoders, and other
digital circuits rve
db
designed from scratch using traditional
yD
digital logic design techniques to
produce a minimal, optimized circuit.
r.
The control unit is like an ASIC K.
(application-specific integrated
Ra
circuit).
jba
bu
@
co
p
HARDWIRED yri CONTROL UNIT
gh
t
A Hard-wired Control r
logic gates. es
consists of two decoders, a sequence counter, and a number of
ememory
An instruction fetched from the rve unit is placed in the instruction register (IR).
db
The component of an instruction register includes; I bit, the operation code, and bits 0
through 11.
y Dwith a 3 x 8 decoder.
The operation code in bits 12 through 14 are coded
r
The outputs of the decoder are designated by the symbols D0 through D7.
The operation code at bit 15 is transferred to a flip-flop.designated
K by the symbol I.
The operation codes from Bits 0 through 11 are applied to the.control logic gates.
The Sequence counter (SC) can count in binary from 0 through 15. a
R
jba
bu
@
co
MICRO p yrPROGRAMMED CONTROL UNIT
igh
t
Built from some sort of ROM. Therdesired
e control signals are simply stored in the ROM, and retrieved in
sneeded
sequence to drive the micro operations
e by a particular instruction.
rve a program consisting of micro-instructions.
The micro-operations are performed by executing
The Control memory address register specifies thed
The Control memory is assumed to be a ROM, within which
b
address of the micro-instruction.
y allDcontrol information is permanently
r.
stored. The control register holds the microinstruction fetched from the memory. control memory.
K.
Ra
jba
bu
@
co
MICRO p yrPROGRAMMED CONTROL UNIT
igh
tr
es a control word that specifies one or more micro-
The micro-instruction contains
er
operations for the data processor.
ve
d b the next address is computed in the
While the micro-operations are being executed,
y Dinto the control address register to
next address generator circuit and then transferred
read the next microinstruction.
r.
K. sequencer, as it
The next address generator is often referred to as a micro-program
R
determines the address sequence that is read from control memory.a
jba
bu
@
co
p yri
INSTRUCTION CYCLE
gh
t
The process involved inrexecuting
es a single instruction
Each instruction cycle consists e
of the following phases:
Fetch instruction from memory. v
r e
Decode the instruction. db
Read the effective address from memory. yD
Execute the instruction. r.K
.R
ajb
ab
u
@
co
p
INPUTy-r OUTPUT
igh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
DESIGN p yriOF COMPUTER
gh
A memory unit with 4096
t rewords of 16 bits each
Registers: AC (Accumulator), seDR (Data register), AR (Address register), IR
(Instruction register), PC (Programr vcounter), TR (Temporary register), SC
ed and OUTR (Output register).
(Sequence Counter), INPR (Input register),
Flip-Flops: I, S, E, R, IEN, FGI and FGO by
A 16-bit common bus
D
Two decoders: a 3 x 8 operation decoder and 4 x 16 timing decoder
r.
Control Logic Gates
K.
The Logic and Adder circuits connected to the input of AC.
Ra
jba
bu
@
co
py
rig
ht
re
se
rve
MEMORY ORGANIZATION
db
yD
r.
K.
Ra
jba
bu
@
co
p yri UNIT
STORAGE
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri OF INFORMATION
STORAGE
gh
tr
es
er
ve
db
yD
r.K
.R
ajb
ab
u
@
co
STORAGEp yri UNIT - REGISTERS
gh
tr
es memory used to quickly accept, store, and transfer
Registers are a type of computer
data and instructions that aree rveused immediately by the CPU.
being
Commonly
Register
se
used Registers
Symbol Number of bits Function
Data register DR
rve 16 Holds memory operand
Address register AR
db 12 Holds address for the memory
Accumulator AC
yD16 Processor register
Instruction register IR 16
r.
Holds instruction code
Program counter PC 12
K.
Holds address of the instruction
Temporary register TR 16 Ra
Holds temporary data
yD
The Program Counter (PC) also contains 12 bits which hold the address of the next instruction to
be read from memory after the current instruction is executed.
r.
The Accumulator (AC) register is a general purpose processing register.
K.
The instruction read from memory is placed in the Instruction register (IR).
Ra
The Temporary Register (TR) is used for holding the temporary data during the processing.
The Input Registers (IR) holds the input characters given by the user.
jba
The Output Registers (OR) holds the output after processing the input data.
b u
@
co
p yri UNIT – CACHE MEMORY
STORAGE
gh
tr
Part of CPUes
er
ve
Path between the processor and the main memory
db
Lesser access time than the main memory and is faster than the main memory
yD
Bridge the speeds of the main memory and the CPU
r.
K.
Stores the program (or its part) currently being executed or which may be executed within a
short period of time
Ra
jba
Stores temporary data that the CPU may frequently require for manipulation
b u
@
co
p yri UNIT – CACHE MEMORY
STORAGE
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
STORAGEp yri UNIT – PHYSICAL MEMORY
gh
tr
Categorization : Volatile,e
se
Non-Volatile, Semi-Volatile, Protected
rvRate,
Access Mode, Access Time, Transfer
ed Capacity and Cost
RAM
by
SRAM, DRAM
Dr
ROM .K
PROM, EPROM, EEPROM .R
ajb
ab
u
@
co
p
MAINyMEMORY rig
ht
Communicates directly with r esSecondary memory and Cache memory.
CPU,
er system.
ve
It is the central storage unit of the computer
d during
It is a large and fast memory used to store data
by computer operations. RAM: Random
Access Memory
D
DRAM: Dynamic RAM, is made of capacitors and transistors,r. and must be refreshed every
10~100 ms. It is slower and cheaper than SRAM.
K .R
SRAM: Static RAM, has a six transistor circuit in each cell and retains data,a jbpowered
until off
ab
u
@
co
p
MAINyMEMORY rig
ht
re memory that uses Bistable latching circuitry to store each bit.
SRAM is a type of semiconductor
se the six transistor memory cell. Static RAM is mostly
rve(CPU).
In this type of RAM, data is stored using
used as a cache memory for the processor
d beach
DRAM is a type of RAM which allows you to stores
within a particular integrated circuit.
y bit of data in a separate capacitor
Dr
.K
.R
ajb
ab
u
@
co
p
MAINyMEMORY rig
ht
SRAM re DRAM
SRAM has lower access time, whichseis faster DRAM has a higher access time. It is slower
compared to DRAM. rve than SRAM.
SRAM is costlier than DRAM.
SRAM needs a constant power supply, which
d DRAM cost is lesser compared to SRAM.
b
DRAM requires reduced power consumption as
means it consumes more power. the y
information stored in the capacitor.
SRAM offers low packaging density. Dr a high packaging density.
DRAM offers
Uses transistors and latches. . Kand very few transistors.
Uses capacitors
L2 and L3 CPU cache units are some general
application of an SRAM.
The DRAM is mostly
memory in computers.
. Ra
found as the main
The storage capacity of SRAM is 1MB to 16MB. The storage capacity of DRAM jbisa1 GB to 16GB.
bu
@
co
p
MAINyMEMORY rig
ht
SRAM re DRAM
se
SRAM is in the form of on-chip memory. DRAM has the characteristics of off-chip
rve memory.
The SRAM is widely used on the processor or
lodged between the main memory and
d The DRAM is placed on the motherboard.
by
processor of your computer.
DRAM isD
This type ofrRAM
SRAM is of a smaller size. available in larger storage capacity.
This type of RAM works on the principle of
changing the direction of current through
. K.works on holding the charges.
switches. Ra
jba
bu
@
co
p
MAINyMEMORY
rig
ht
re
se
NVRAM: Non-Volatile RAM, retains its data, even when turned off. Example: Flash memory.
rve
ROM: Read Only Memory, is non-volatile and is more like a permanent storage for information.
db
It also stores the bootstrap loader program, to load and start the operating system when
yD
computer is turned on. PROM(Programmable ROM), EPROM(Erasable PROM)
r.
K.
and EEPROM(Electrically Erasable PROM) are some commonly used ROMs.
Ra
jba
b u
@
co
p
MAINyMEMORY
rig
ht
re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p
MAINyMEMORY
rig
ht
re
The internal clock rate is the frequency needed to match the external clock rate.
se
rve
Bus clock speed, is the speed at which the connection between CPU & memory operates at.
db
Higher bus speed means you can send more data more quickly
yD
Data rate is how many bits a module can transfer in a given time, and speed is how many bytes
it can transfer.
r.
K.
Ra
jba
b u
@
co
p
SECONDARY yri MEMORY
gh
tr
e
External memory or non-volatile.
E.g. disk, CD-ROM, DVD, etc s
er
ve
These are magnetic and optical memories.
d b to CPU directly.
It is known as the backup memory. Not connected
It is a non-volatile memory. yD
Data is permanently stored even if power is switched off.r.
It is used for storage of data in a computer.
K.
Computer may run without the secondary memory.
Rajb
Slower than primary memories. ab
u
@
co
py
rig
ht
re
se
CONTROLrvLOGIC
ed GATES
by
Dr
.K
.R
ajb
abu
@
co
p
LOGICyGATES rig
ht
r
Fundamental element ofecomputer
se
using diodes or transistors actingrasvelectronic switches
ed
b
using vacuum tubes, electromagnetic relays (relay logic), fluidic logic, pneumatic
yD
logic, optics, molecules, or even mechanical elements.
rvlowe
Gives a high output if any of the inputs are
db
Represented by a AND gate with a small circle on the output
rvhigh
Low output if any of the inputs are
ed
output
b
Represented by an OR gate with a small circle on the
yD
r.K
.R
ajb
ab
u
@
co
p yri
XOR GATE
gh
t re
Exclusive OR
se
rveis high but not both of them
Give a high output if one of its inputs
The Latch does not work on the clock edges like the flipflop.
jba
bu
@
co
LATCHES p yri
gh
tr
LATCH
e s
FLIP-FLOP
u
@
co
LATCHES p yri
gh
tr
LATCH
e s
FLIP-FLOP
The latches can be clocked or clockless.
ether By the clock signal and binary input, the Flip-Flop
For all the time, Flip-Flops are clocked.
Only binary inputs can be used to operate
latches. veworks.
d bis sensitive to the clock signals and until
The latch is sensitive to the input and as long Flip-Flop
as it is 'On', we can transmit the data.
yD
there is a change in the input clock signal, it never
changes the output.
The latch cannot be used as a register because Flip-Flop can work r .as a register because it contains
the register requires more advanced K
clock signals in its input.
.
electronic circuits where time plays an
essential role. Ra
jba
bu
@
co
LATCHES p yri
gh
tr
LATCH
e s
FLIP-FLOP
not work on the basis of the time signal.er the basis of the clock signal.
The latch is asynchronous because latch does Flip-Flop is synchronous because flip-flop work on
The latch cannot be built from the gates. ve Flip-Flop cannot be built from the latches.
Latches are responsive towards faults on d b are protected toward fault.
Flip-Flops
enable pin.
yD
r.
K.
Ra
jba
bu
@
co
p yri
FLIP-FLOPS
gh
t re
Flip flops are an application of logic gates under sequential circuit.
s er Latch. Synchronous are called Flip Flop
Asynchronous or transparent are called
ve
dindefinitely
A flip-flop circuit can remain in a binary state
bystates.(as long as power is delivered to
the circuit) until directed by an input signal to switch
Dr Bounce elimination switch
.K
Counters, Frequency Dividers, Shift Registers. Storage Registers,
.R
ajb
ab
u
@
co
p yri
FLIP-FLOPS
gh
t re
Trigger: state of the flip-flop is changed by a momentary change in the input signal.
s er pulse is either positive or negative.
Pulses trigger clocked flip-flops. A clock
ve
A pulse start from the initial value of '0', goesdmomentarily to '1', and after a short while,
returns to its initial '0' value.
by
D r. pulses and goes to 1
A positive clock source remains at '0' during the interval between
during the occurrence of a pulse.
K.
Ra
jba
The pulse goes through two signal transition: from '0' to '1' and return from '1' to '0'.
bu
@
co
p yri
FLIP-FLOPS
gh
t re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
S-R FLIP-FLOPS
gh
t re flip-flops.
Basic Flip flops stands for SET-RESET
s erNAND gates
Consists of two NOR gates or also two
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
S-R FLIP-FLOPS
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
CLOCKEDp yri S-R FLIP-FLOPS
gh
t
Additional control input thatredetermines when the state of the circuit is to be changed
s er NOR and NAND gate is the invalid state. This
The limitation with a S-R flip-flop using
problem can be overcome by using a stable
v edSR flip-flop that can change outputs when
by of either the Set or the Reset
certain invalid states are met, regardless of the condition
inputs. Dr
A clock pulse is given to the inputs of the AND Gate.
. K.
Ra '0'.
If the value of the clock pulse is '0', the outputs of both the AND Gates remain
jba
bu
@
co
p yri S-R FLIP-FLOPS
CLOCKED
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
D FLIP-FLOPS
gh
t re of clocked SR flip-flop.
D flip-flop is a slight modification
s
D input is connected to the S inpute rvtheecomplement of the D input is connected to the
and
R input.
db
y toDthe SET state if it is '0' (LOW), the
When the value of CP is '1' (HIGH), the flip-flop moves
flip-flop switches to the CLEAR state.
r.
K.
Ra
jba
bu
@
co
p yri
D FLIP-FLOPS
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
J-K FLIP-FLOPS
gh
t
J-K flip-flop can be consideredreas a modification of the S-R flip-flop.
s er state is more refined and precise than that of
The main difference is that the intermediate
an S-R flip-flop.
v ed
b 'S' and 'R' inputs of the S-R flip-flop.
The characteristics of inputs 'J' and 'K' is same as they
bu
@
co
p yri
J-K FLIP-FLOPS
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p
T FLIP-FLOPSyri
gh
t
T flip-flop is a much simplerr
es
version of the J-K flip-flop. er
Both the J and K inputs are
v ed
connected and are also called as by
a single input J-K Flip-flop. Dr.
K.
Ra
jba
bu
@
co
p yri
DECODERS
gh
t re
Combinational circuit that converts binary information from the 'n' coded inputs to a
se
maximum of 2^n different outputs
rve
db
yD
r.
K.
Ra
jba
b u
@
co
p yri
DECODERS
gh
t re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ENCODERS
gh
t re
Maximum of 2^n (or less) input lines and n output lines
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p
MULTIPLEXERyri
gh
t re2n input lines and a single output line
Combinational circuit that has
s er circuit
Multi-input and single-output combinational
ve
The binary information is received from the inputd blines and directed to the output line. On
y Ddata inputs will be connected to the
the basis of the values of the selection lines, one of these
output.
r.
K. lines. So, there is a total
Unlike encoder and decoder, there are n selection lines and 2n input
Ra
of 2N possible combinations of inputs. A multiplexer is also treated as Mux.
jba
bu
@
co
p yri
MULTIPLEXER
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
DEMULTIPLEXER
gh
t re circuit that has only 1 input line and 2N output lines.
A De-multiplexer is a combinational
s
Total of 2n possible combinations ofeinputs.
rveDe-multiplexer is also treated as De-mux.
db
yD
r.
K.
Ra
jba
bu
@
co
p
COMPARISON yri
gh
t
D Flip-Flop: When the clockrtriggers, the value remembered by the flip-flop becomes the
es
value of the D input (Data) at thate instant.
rve
d
T Flip-Flop: When the clock triggers, the value remembered by the flip-flop either toggles or
remains the same depending on whether the T input by(Toggle) is 1 or 0.
Dr
.
J-K Flip-Flop: When the clock triggers, the value remembered by the flip-flop toggles if
the J and K inputs are both 1 and the value remains the same ifK
.
both are 0; if they are
RKa(Kill) input is 1.
different, then the value becomes 1 if the J (Jump) input is 1 and 0 if the
jba
bu
@
co
p
COMPARISON yri
gh
t
S-R Flip-Flop: When the clock retriggers, the value remembered by the flip-flop remains
unchanged if R and S are both 0, sbecomes
er 0 if the R input (Reset) is 1, and becomes 1 if
ve if both inputs are 1. (In Logisim, the value in
the S input (Set) is 1. The behavior in unspecified
the flip-flop remains unchanged.)
db
yD
r.
K.
Ra
jba
bu
@
co
py
rig
ht
re
se
BUILDING A rSIMPLE
ve MEMORY
db
yD
r.
K.
Ra
jba
bu
@
co
BUILDING p yri A SIMPLE MEMORY
gh
t
To store a single bit, were
can use Flip flops or latches
pattern
. Ra
That is, data is coded then stored and when retrieved it is decoded jba
A byte is a string of 8 bits and is called a character when the data is text bu
@
co
BITS, y p BYTES, AND WORDS
rig
ht
re(a 1 or 0).
A bit is a single binary digit
A byte is 8 bits
s er
ve
A word is 32 bits or 4 bytes
Long word = 8 bytes = 64 bits
d by
Quad word = 16 bytes = 128 bits
D r.
Programming languages use these standard number of bits when organizing data
storage and access. K.
What do you call 4 bits? Ra
(hint: it is a small byte)
jba
4 b u
@
co
NUMBER p yri SYSTEMS
gh
tr
es in RAM can be thought of as the values 1 and 0,
respectively.
e
The on and off states of the capacitors
rve
Therefore, thinking about how informationd
binary (base 2) number system.
b
is stored in RAM requires knowledge of the
yD
r.
Let’s review the decimal (base 10) number system first.
K.
Ra
jba
5 bu
@
co
p yri
THE DECIMAL NUMBER SYSTEM
gh
t re is a positional number system.
• The decimal number system
Example: se
2 1 rv
•
Value
Position
5 6
4 3 2 1
ed 1 X 100 = 1
2 X 101 = 20
Address 103 102 101 100 by 6 X 102 = 600
D5rX 103 = 5000
.K
.R
ajb
ab
6
u
@
co
p yri
THE DECIMAL NUMBER SYSTEM (CON’T)
gh
t
The decimal number systemrisealso known as base 10. The values of the positions are
•
s er
calculated by taking 10 to some power.
r.
K.
Ra
jba
7 bu
@
co
p
THE BINARYyri NUMBER SYSTEM
gh
•
t
The binary number system reis also known as base 2. The values of the positions are
calculated by taking 2 to somesepower.
rv
Why is the base 2 for binary numbers?e
•
d
Because we use 2 digits, the digits 0 and 1.b
o
yD
r.
K.
Ra
jba
8 bu
@
co
p
THE BINARYyri NUMBER SYSTEM (CON’T)
gh
t reis also a positional numbering system.
• The binary number system
s ether binary system uses only two digits, 0 and 1.
• Instead of using ten digits, 0 - 9,
1 0 0 1 1 0 1 yD
26 25 24 23 22 21 20
r.
K.
Ra
jba
9 bu
@
co
p
CONVERTINGyri FROM BINARY TO DECIMAL
gh
tr
1 0 0 1 1 0 1 es 1 X 20 = 1
0e r
1 X 22 v
26 25 24 23 22 21 20 X 21 = 0
= e
4
1 X 23 = 8 d
20 = 1 24 = 16
21 = 2 25 = 32 0 X 24 = 0
by
22 = 4 26 = 64 0 X 25 = 0 Dr
23 = 8 1 X 26 = 64 .K
7710 .R
ajb
ab
10
u
@
co
CONVERTING FROM BINARY TO DECIMAL (CON’T)
py
rig
ht
Practice conversions: re
se
Decimal rv
Binary
ed
11101
by
1010101 Dr
100111
. K.
Ra
jba
11 bu
@
co
py
CONVERTING FROM DECIMAL TO BINARY (CON’T)
rig
ht
• re values up to the number being converted.
Make a list of the binary place
Perform successive divisions bys
•
er
2, placing the remainder of 0 or 1 in each of the positions
•
from right to left.
Continue until the quotient is zero.
v ed
• Example: 4210
by
25 24 23 22 21 20 Dr
32 16 8 4 2 1 .K
1 0 1 0 1 0 .R
ajb
ab
12
u
@
co
py
CONVERTING FROM DECIMAL TO BINARY (CON’T)
rig
ht
• Practice conversions: re
se
• Decimal rve
Binary
• 59
d b
• 82 yD
• 175 r.
K.
Ra
jba
13 bu
@
co
WORKING p yri WITH LARGE NUMBERS
gh
tr
0 1 0 1 0 0 0 0 1 0 1 0 0 1 1 1e
•
se
= ?
rve
• d there
Humans can’t work well with binary numbers;
b are too many digits to deal with.
yD
They are also far more reliable when they have to represent one out of two
possible values.
r.
K.carry only binary
Because the electronic signals are easier to maintain if they
data. Ra
jba
bu
@
co
BINARY p yriREPRESENTATION
gh
t
One bit can be either 0 orr1.eTherefore, one bit can represent only two things.
se
To represent more than two things,r we need multiple bits. Two bits can represent
ve
d b of 0 and 1 that can be made from
four things because there are four combinations
two bits: 00, 01, 10,11. yD
In general, n bits can represent 2n things because therer.are 2n combinations of 0
K
and 1 that can be made from n bits. Note that every time we.increase the number
of bits by 1, we double the number of things we can represent.
R ajb
ab
u
@
co
py
rig
ht
re
s
DATA REPRESENTATION
er IN
ve
MEMORYdb
yD
r.
K.
Ra
jba
bu
@
co
p
DATAyREPRESENTATION
rig
ht
Symbols
res
er
Roman Numbers ve
db
yD
Positional system – radix ten or decimal system
HexaDecimal
d by
Ranges from 0 to F Dr
.K
.R
ajb
ab
u
@
co
p
PRIMITIVE yri DATA STRUCTURE
gh
t
Basic representation of any r es
data.
Integer er
A natural number, the negative of av ed number, and 0.
natural
way
b
So an integer number system is a system for ‘counting’
yD things in a simple systematic
Real Numbers r.
Integer + floating decimal values K.
Character Ra
jba
bu
@
co
p
BASICyOPERATIONS ON PRIMITIVE DS
rig
ht
re
CREATE
se
rve
Declare n, a, b as integer
DESTROY
db
SELECTION
yD
r.
UPDATE K.
N a+b
Ra
jba
bu
@
co
p yri
INTEGER
gh
tr
es
Represent the quantity and discrete in nature
er
ve
E.g. No of flights arriving at an airport
db
{…-(n+1), -n,…,-2,-1,0, 1, 2, …., n, (n+1),..}
yD
r.
K.
Ra
jba
bu
@
co
p yri
REPRESENTATION OF INTEGER
gh
tr
epositive
Unsigned number – (only se values)
Signed numbers
rve
db
yD
r.
K.
Ra
jba
bu
@
co
UNSIGNED p yri INTEGER
gh
t
An unsigned integer is an r es without a sign, that is, a non-negative integer
integer
e
They range from zero to infinity, butrvnoecomputer can store all the integers in that range
So, a maximum unsigned integer is defined b
d
yD
This maximum is based on the number of bits used to store r.an integer
K .R
Let’s use 8 and 16-bit (1 and 2 bytes) storage locations in our examples
a
The length of storage is set by the data type the programmer specifies forjabvariable
ab
u
@
co
p
UNSIGNED yri INTEGER
gh
t
An unsigned integer is storedras its value when represented as a binary number
es
erstorage location
Leading zeros are added to fill out the
ve
d bas 00001001 when stored in 1-byte because
For example, the decimal number 9 is represented
000010012 = 910 yD
When stored in a 2-byte location, 9 would be represented asr0000000000001001
.K
.R
ajb
ab
u
@
co
p
UNSIGNED yri INTEGER
gh
t table
One may use the following re to work with binary numbers:
se
rve
db
yD
For example, given 00001001, what decimal number does it represent?
r.
K.
Add the non-negative powers of two, that is, 8 + 1 = 9
R ajb
ab
u
@
co
UNSIGNED p yri INTEGER
gh
t
One may use the same tablereto go the other way, that is, given the decimal number 13,
s
what is its binary representation?e
rve
db
Find the largest power of 2 that doesn’t exceed the number and place a 1 in that cell:
yD
r.
K.
Subtract that power of 2 from the number and use this as the newR number: 13 – 8 = 5
ajb
ab
u
@
co
p
UNSIGNED yri INTEGER
gh
t re the sum of the powers of two equals the number:
Then continue in this way until
se
rve
db
Now, 5 – 4 = 1, and so finally:
yD
r.
K.
Ra
Note that 8 + 4 + 1 = 13
j bab
u
@
co
UNSIGNED p yri INTEGER
gh
t cells with zeros:
Then fill in the remaining r
es
er
ve
db
y13Dis 00001101 when stored in 1-byte
So, the unsigned integer representation of decimal
r.
K.
Ra
jba
bu
@
co
UNSIGNED p yri INTEGER
gh
t rein a memory location that is not large enough we have what is
If one tries to store a number
called overflow
s er
v
In this case, depending on the system, onee d orbmay not receive an error message
may
So, one must not store a number that is larger thanythe maximum for a given length of
storage
D r.
The maximum number storable in 1-byte is 255
K .R
ajb
ab
u
@
co
UNSIGNEDp yri INTEGER
gh
t
For example, if one tries torestore 256 in 1-byte there is overflow because the largest value
storable in 8 bits is 255 as one s eseer from the following table:
can
ve
db
yD
Note that 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255 r.
K.
Ra
jba
bu
@
co
SIGNED p yriINTEGER
gh
t
A sign-and-magnitude format reis used to allow for positive and negative numbers (and zero)
se
rvbit:e 0 for positive or zero, 1 for negative
The leading bit is designated as the sign
Dr
For example, 00010001 is decimal 17:
.K
.R
ajb
Because 16 + 1 = 17
a bu
@
co
p yri
CONCERNS
gh
t
Not economical re
se operation (+7+ (-6)) or (-7+ 6)
Extra Effort required to perform
rvethe sign of the operand.
Additional operation required to find
db
y representation
Hence, it is proposed to have radix complement
Dr
.K
.R
ajb
ab
u
@
co
p yri
2’S COMPLEMENT
gh
Two’s complement is tstillra sign-and-magnitude format
e s
In two’s complement, some of
er
the magnitude bits are flipped from 0 to 1 or 1 to
0
Modulo M = R N
v ed
binythe modulo M.
R is the radix, N is the number of bits required
-x = M – x Dr
.K
.R
ajb
ab
u
@
co
p yri
2’S COMPLEMENT
Integer
gh 2’s Complement Integer 2’s Complement
0
tr
0000 -1 (16-1=15) 1111
1
es
0001 -2 (16-2=14) 1110
2 0010
er -3 (16-3=13) 1101
3 0011
ve -4 (16-4=12) 1100
4
5
0100
0101 db -5 (16-5=11)
-6 (16-6=10)
1011
1010
6 0110 yD -7 (16-7=9) 1001
7 0111 -8 (16-8=8)
r. 1000
K.
The range of values defined using 4-bit is -8 to 7 Ra
jba
b u
@
co
p yri
2’S COMPLEMENT
gh
t re representation for negative integers in modern
Two’s complement is the standard
se
computers
rve
d bto implement when integers are stored this
This is because arithmetic operations are simple
way
yD
r.level it allows for simplicity of
Although on the surface it seems complicated, at a deeper
operations K.
Ra
jba
bu
@
co
p yri
2’S COMPLEMENT
gh
t re method for converting a negative number to its two’s
An alternative but equivalent
complement representation is: e
s
rve
db
Ignore the sign and convert the decimal number to binary
yD
If needed add leading zeros to fill the storage location
r.
Above rules are violated in case of -7 – 7 and +7 +7 in 2’s complement
K.
Ra
jba
bu
@
co
INTEGER p yri REPRESENTATION
gh
tr
Range of values for n-bitestorage representation is 2 -1
se n
14 rve
168 X 10 vs 168,817,210,391,704 kms
General Format
db
yD
r.
Sign Charateristic Fraction
K.
Ra
jba
bu
@
co
p
REAL yNUMBER - EXCESS NOTATION
rig
ht
re(i.e., the length of the bit pattern used can not be
This fixed length notation
s er makes it possible to store negative (-) and
altered once set at the beginning)
v
non-negative (+ including zero) valuesedby treating the right-most digits referred
by the sign of the number.
to as the Most Significant Bit (MSB) as representing
u
@
co
pyNUMBER - FRACTIONAL PART OR
REAL
rig
MANTISSA
ht
reR <= F < 1
F must lie in the interval
-1
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p
DATAyINTERPRETATION IN COMPUTER
rig
ht
Character String
r es
e rvthee eight bits 11000000 is used to represent
For example, in some computers,
d b "B" and another for each
the character "A" and 11000001 for character
y Dmachine. So, the character
character that has a representation in a particular
r.
string "AB" would be represented by the bit string 1100000011000001.
K.
Ra
jba
bu
@
co
p
CHARACTER yri REPRESENTATION
gh
t Code
r
The American Standard
esof the characters
to assign a bit pattern to each
for Information Interchange (ASCII) is the scheme used
er
ASCII charts come in different flavors:
ve
Some have 7 bit strings, some 8 or more
db
Some show the binary code for the various characters as well as the code
y Dhex, octal
represented in other number systems, e.g., decimal,
For example, the letter A has the ASCII code:
1000001 in binary for a 7-bit chart
r
Note:. AllKfour of these numbers
65 in decimal .
represent the
R same value but using
41 in hex
different number
ajb
systems
101 in octal
ab
u
@
co
p yri OF ASCII CHART
SUBSET
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
ASCII y p CHART
rig
h t rdifferent ASCII codes than lowercase
Uppercase characters have
es
Uppercase characters come beforee
rve
lowercase
Some manufactures use the extra bit to created additional special characters, these
bfory½, or 246 for ÷
however are nonstandard, e.g., using decimal 171
D
Unicode is another scheme developed so that the many symbolsr. in international languages
may be represented. It also uses bit patterns. UTF-32 uses 32 K bits.
.R
ajb
ab
u
@
co
p yri
EBCDIC
g ht
re decimal interchange code (EBCDIC) is an 8-
The extended binary coded
s
bit alphanumeric code which e hasr been extensively used by IBM in its mainframe
applications.
v ed
by8-bit code.
ASCII code is a 7-bit code whereas EBCDIC is an
D r. is used primarily in
ASCII code is more commonly used worldwide while EBCDIC
large IBM computers.
K.
Ra
jba
bu
@
co
py
rig
ht
re
se
LOW LEVEL rve LANGUAGE
db
yD
r.
K.
Ra
jba
bu
@
co
p
INSTRUCTIONyri SET
gh
tr
eofsmachine language instructions that a particular processor
Computer instructions are a set
er performs tasks on the basis of the instruction provided.
understands and executes. A computer
ve
dThese
An instruction comprises of groups called fields.
by fields include:
The Operation code (Opcode) field which specifies the operation to be performed.
Dr
.K
The Address field which contains the location of the operand, i.e., register or memory location.
The Mode field which specifies how the operand will be located.
.R
ajb
ab
u
@
co
p yri
INSTRUCTION CODE FORMAT
gh
t
Each microprocessor has respecific set of instructions
seby 8-bit byte called OPCODE or instruction byte
Each instruction is represented
Memory - reference instruction v
r e
Register - reference instruction db
Input-Output instruction yD
r.
K.
Ra
jba
bu
@
co
p
INSTRUCTION yri SET
gh
tr
A set of instructions is said to bee
s
complete if the computer includes a sufficient number of
instructions in each of the followinge rve
categories:
e
i=1
T h i s c o u l d b e w r i t t e rnva s a h i g h - l e v e l l a n g u a g e
c o d e s n ip p e t a s fo llo w e s .d
t o t a l = 0 ; by
F O R i = 1 t o n D O { t o t aD
1 . to ta l = 0 , i = 0
r
l = to ta l + i} ;
.K
2. i = i + 1 .R
3 . to ta l = to ta l + i ajb
4 . IF i ≠ n T H E N G O T O 2 ab
u
@
co
EXAMPLE RELATIVELY SIMPLE PROGRAM
CODEpyr
igh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
EXAMPLE RELATIVELY SIMPLE PROGRAM
p
TRACEyr
igh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
THEco8085 ISA - INSTRUCTION SET
p yri instructions
Data movement
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
THEco8085 ISA - INSTRUCTION SET
py instructions
rig
Data operation
ht
re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
THE co8085 ISA - INSTRUCTION SET
p yri instructions
Program control
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
THE c8085
op ISA - INSTRUCTION FORMATS
yri
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
py 8085 PROGRAM
EXAMPLE
rig
ht
re n
1 + 2 + ... + ns,e o r ∑ i
rve i = 1
d
1 . i = n , s u m = 0 by
D
2 . s u m = s u m + i, i = ri. - 1
K.
3 . IF i ≠ 0 T H E N G O T ORa2
jba
4 . to ta l = s u m bu
@
co
p yri 8085 PROGRAM CODE
EXAMPLE
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri 8085 PROGRAM TRACE
EXAMPLE
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p
COMPARISON yri
Property
g ht 8085 Microprocessor 8086 Microprocessor
r es
Data Bus Size 8-Bit
er 16-Bit
Flags
K . R(Overflow, Direction,
It has 5 flags (Sign, Zero, Auxiliary It has 9 flags
Carry, Parity, Carry) Interrupt. Trap,aSign, Zero,
jbaCarry)
Auxiliary Carry, Parity,
bu
@
co
p
COMPARISONyri
Property gh 8085 Microprocessor 8086 Microprocessor
tr
Pipelining Support esupport
Does not
se Supports
rve
Memory Segmentation Does not support Supports
supports db
Number of transistors Nearly 6500 y DNearly 29000
Processor type Accumulator based
rGeneral
. K Purpose register based
.
Present R
Presence of Minimum Not present
and Maximum mode ajb
ab
u
@
co
p
COMPARISONyri
Property gh 8085 Microprocessor 8086 Microprocessor
tr
esprocessor is used
Number of processors Only one More than one processor is used.
er Additional processor (external) can
ve also be employed
u
112
@
co
VERILOG p yri
gh
tr
A Verilog model is composed ofe
s
modules. A module is the basic unit of the model, and it may
er
ve
be composed of instances of other modules.
A module which is composed of other moduled instances is called a parent module, and the
instances are called child modules.
by
Dr
.K
comp1
comp2 system
sub3 .R
ajb
ab
5/23/2021
u113
@
co
VERILOG p yri DESIGN CONCEPT
gh
tr
comp2 instantiates sub3
e
System instantiates comp1,comp2
se
rve
System
db
comp1
yD
comp2
r .K
.R
ajb
sub3
ab
5/23/2021
u 114
@
co
p yri
PRIMITIVES
gh
t re
type.
s
Primitives are pre-defined module types. They can be instantiated just like any other module
er
v ed because for the most part, they are simple
The Verilog primitives are sometimes called gates,
logical primitives. by
1-output and,nand or,nor
D r.
1-input buf, not Etc.
K .R
ajb
ab
5/23/2021
u 115
@
co
p yri
REGISTER
gh
t re
Registers are storage elements. Values are stored in registers in procedural assignment
statements. se
rve
Typical register declarations would be:
db
reg r1, r2; y D
reg [31:0] bus32;
r.
integer i;
K.
real fx1, fx2;
Ra
Register can take 0, 1, x (unknown) and z (high impedence) jba
5/23/2021 b u
116
@
co
REGISTERp yri TYPES
gh
t re
There are four types of registers:
s etype.
1. Reg This is the generic register data rveA reg declaration can specify registers which are 1
db
bit wide to 1 million bits wide. A register declared as a reg is always unsigned.
r.
not not_prim(n2, n1);
K.
endmodule
Ra
jba
5/23/2021 b u
118
@
co
ASSIGN p yri
gh
t re known as data flow statements because they describe
Continuous assignments are sometimes
how data moves from one place, s era net or register, to another. They are usually thought
either
of as representing combinational logic. ve
Example:
d by
assign w1 = w2 & w3; Dr
.K
.R
ajb
ab
5/23/2021
u
119
@
co
LETSpGET THE VERILOG MODULE FOR THIS
y
CIRCUITrig
ht
re
se
rve
db
yD
r.
K.
Ra
jba
http://www.doulos.com/knowhow/verilog_designers_guide/wi
re_assignments/
5/23/2021 b u 120
@
co
SOLUTIONSp yri USING “ASSIGN” AND “WIRE”
gh
module AOI (input A, B, C,tD,
output F);
res end of a block comment */
wire F;
v wire AB = A & B;
ed wire CD = C & D;
wire AB, CD, O; bwirey O = AB | CD;
wire FD
assign AB = A & B;
assign CD = C & D; r
= ~O;
endmodule. //K end of Verilog code
assign O = AB | CD; .R
assign F = ~O; ajb
end of a block comment */
ab
5/23/2021
u
121
@
co
MODULE p yri ABC IN VABC
gh
module vabc (d, s);
t re
se
input [1:0] s;
r ved[0], s[1], s[0]);
output [3:0] d; abc a1 (d[3], d[2], d[1],
db
endmodule
yD
r.K
.R
ajb
ab
5/23/2021
u 122
@
co
p
MODULEyDEFINITION + GATE LEVEL DIAGRAM
rig
ht
re
module abc (a, b, c, d, s1, s0);
se
input s1, s0;
rve
output a, b, c,d;
db
not (s1_, s1), (s0_, s0);
r.
Example:
K.
wire w1, w2;
tri [31:0] bus32; Ra
jba
wire wire_number_5 = wire_number_2 & wire_number_3;
& here represents AND operation (AND gate)
5/23/2021 b u125
@
co
p
4-BIT y
ADDER : LETS WRITE VERILOG SOURCE
rig
ht
re
se
rve
db
yD
r.
K.
Ra
jba
5/23/2021
bu
126