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

Essentials of Computer Science-Week1-5

db e to execute as it requires translation It executes faster as it requires only to machine code.y D compilation and not translation. Portability Not portable, as it is machine dependent. It is portable across different machines and operating systems.r. K. R Maintenance Difficult to maintain due to dependence on It is easy to maintain and modify as it is hardware.a j b a independent of hardware.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Essentials of Computer Science-Week1-5

db e to execute as it requires translation It executes faster as it requires only to machine code.y D compilation and not translation. Portability Not portable, as it is machine dependent. It is portable across different machines and operating systems.r. K. R Maintenance Difficult to maintain due to dependence on It is easy to maintain and modify as it is hardware.a j b a independent of hardware.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 329

@

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

Natural language have grammar and d vocabulary


by
Programming language has syntax, keywordsD and constants
r.
K.
Ra
jba
bu
@
co
p
WHY SO yri MANY?
gh
t
Continuous evolutionre
se
Optimization
r ve
New requirements & approaches
db
yD
r.
K.
Ra
jba
bu
@
co
p yriOF PROGRAMMING
LEVELS
gh
tr
es
er
ve
db
yD
r.K
.R
ajb
ab
u
@
co
p
LOW LEVEL yri LANGUAGE
gh
tr
es abstraction from the hardware
Low-level languages provide
er
Represented in the binary formv
ed
i.e. 0 or 1

They are machine instructions. by


Dr language & Assembly
Classification of Low-level languages : Machine-level
level language.
. K.
Ra
jba
bu
@
co
MACHINEp yri LANGUAGE
gh
tr
es
First generation programming
e rvand
Operation Code – such as addition
ed subtraction

by
Operands – to identify the data to be processed

Machine language is a machine dependent language. DrE.g. IBM vs Apple varies


with architecture .K
Only language that can be understandable be computer
. Ra
Very efficient code but difficult to write
jba
bu
@
co
p
ASSEMBLY yri LANGUAGE
gh
tr
es
Second Generation Language

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.

Some of the most prominent functional programming languages are aHaskell,


j ba SML,
Scala, F#, ML, Scheme, and More.
bu
@
co
py
OBJECT-ORIENTED PROGRAMMING
rig
LANGUAGE
ht
re
se
This programming paradigm is based on the “objects” i.e. it contains data in the form of
fields and the code in the form of procedures.
rve
db
OOPs, offer many features like abstraction, encapsulation, polymorphism, inheritance,
classes, and Objects.
yD
Encapsulation is the main principle as it ensures secure code.
r.
K.
It also emphasizes code reusability with the concept of inheritance and polymorphism
allows the spreading of current implementations without changing much of the code.
Ra
jba
Most multi-paradigm languages are OOPs languages such as Java, C++, C#, Python,
Javascript, and more.
b u
@
co
p
SCRIPTING yri PROGRAMMING LANGUAGES
gh
programming languages that
t reare not compiled but are rather interpreted.
The instructions are written for a s etime
run environment.
majorly used in web applications, System
rvadministration,
e games and multimedia.
It is used to create plugins and extensions for d
b
existing applications.
y PERL.
Server Side Scripting Languages: Javascript, PHP, and
Client-Side Scripting Languages: Javascript, AJAX, Jquery r
D
System Administration: Shell, PERL, Python
. K.
Linux Interface: BASH Ra
Web Development: Ruby jba
bu
@
co
p
LOGICyrPROGRAMMING
igh
tr
The programming paradigm es is largely based on formal logic.
e rve how to do something but employs
The language does not tell the machine
db
restrictions on what it must consider doing.

PROLOG, ASAP(Answer Set programming), and y Datalog


D are major logic
programming languages, rules are written in the formrof
. classes.
K.
Ra
jba
bu
PROCEDURAL VS FUNCTIONAL
VS OOP
PROCEDURAL VS FUNCTIONAL
VS OOP
PROCEDURAL VS FUNCTIONAL
VS OOP
ABSTRACTION
PROGRAM DEVELOPMENT
PROGRAM
C++ PROGRAM

// Your First C++ Program

#include <iostream>

int main() {

std::cout << "Hello World!";

return 0;

}
JAVA PROGRAM

* This is a simple Java program. public static void main(String args[

FileName : "HelloWorld.java". */ {

lass HelloWorld System.out.println("Hello, World");

/ Your program begins with a call to main(). }

/ Prints "Hello, World" to the terminal

window.
DEVELOPMENT CYCLE (PDLC)

Define
Scope, objective
Analyze
Input – process - output
Assumptions, deliverables, exceptions
Algorithm development
Coding and Documentation
Testing and Debugging
Maintenance
ALGORITHM

An algorithm is a sequence of unambiguous instructions for solving a problem,


i.e., for obtaining a required output for any legitimate input in a finite amount of
time
ALGORITHMIC ANALYSIS

Space complexity
How much space is required

Time complexity
How much time does it take to run the algorithm
GENERAL ANALYSIS

Depends on the machine and platform.

However, the analysis should be independent of machine and platform.

Exact value cannot be arrived.

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

Sometimes we need two or more parameters


13
GENERAL ANALYSIS

Complexity is measured as a function of size of input

Time is measured as T(n) and Space as S(n) for ‘n’ inputs

Rate of growth - Exponential


2n, nn,n!

Polynomial Growth – n2, n3, log(n)

Better execution time is through algorithm with linear growth for large amount
of data
TIME ANALYSIS

Active or Characteristic Operations alone to be considered


What a “characteristic operation” is depends on the particular problem
If searching, it might be comparing two values
If sorting an array, it might be:
comparing two values
swapping the contents of two array locations
both of the above
Sometimes we just look at how many times the innermost loop is executed
TIME ANALYSIS

Bookkeeping operations shall be ignored.

Count the number of active operations

Ignore the constants and arrive at a common notation with respect to ‘n’ with the
highest value.
IS IT POSSIBLE TO FIND EXACT VALUES?

It is sometimes possible, in assembly language, to compute exact time and space


requirements

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

However, often the exact sequence of steps cannot be known in advance

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

A Java statement takes constant time if:


It does not include a loop

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;; }

This loop takes time k*n + c, for some constants k and c

k : How long it takes to go through the loop once


(the time for j = j * i, plus loop overhead)

n : The number of times through the loop (we


( can use this as the “size” of the problem)

c : The time it takes to initialize the loop

The total time k*n + c is linear in n


CONSTANT TIME IS (USUALLY)
USUALLY) BETTER THAN LINEAR TIME

Suppose we have two algorithms to solve a task:


Algorithm A takes 5000 time units
Algorithm B takes 100*n time units

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

We usually care most about very large problems


But not always!
THE ARRAY SUBSET PROBLEM

Suppose you have two sets, represented as unsorted arrays:


int[] sub = { 7, 1, 3, 2, 5 };
int[] super = { 8, 4, 7, 1, 2, 3, 9 };

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

We go through the loop in member n times

If m and n are similar, this is roughly quadratic

25
WHAT ABOUT THE CONSTANTS?

Forget the constants!

An added constant, f(n)+c, becomes less and less important as n gets larger

A constant multiplier, k*f(n), does not get less important, but...


Improving k gives a linear speedup (cutting k in half cuts the time required in half)
Improving k is usually accomplished by careful code optimization, not by better algorithms
We aren’t that concerned with only linear speedups!
SIMPLIFYING THE FORMULAE

Throwing out the constants is one of two things we do in analysis of algorithms


By throwing out constants, we simplify 12n2 + 35 to just n2

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

When we have a polynomial that describes the time requirements of an algorithm, we


simplify it by:
Throwing out all but the highest-order
order term
Throwing out all the constants

If an algorithm takes 12n3+4n2+8n+35 time, we simplify this formula to just n3

We say the algorithm requires O(n3) time


We call this Big O notation
(More accurately, it’s Big Ω,, but we’ll talk about that later)
BIG O FOR SUBSET ALGORITHM

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

We go through the loop in member n times

Hence, the actual running time should be k*(m*n) + c, for some constants k and c

We say that subset takes O(m*n) time


CAN WE JUSTIFY BIG O NOTATION?

Big O notation is a huge simplification; can we justify it?


It only makes sense for large problem sizes
For sufficiently large problem sizes, the highest-order
highest term swamps all the rest!
Consider R = x2 + 3x + 5 as x varies:
x=0 x2 = 0 3x = 0 5=5 R=5
x = 10 x2 = 100 3x = 30 5=5 R = 135
x = 100 x2 = 10000 3x = 300 5 = 5 R = 10,305
x = 1000 x2 = 1000000 3x = 3000 5 = 5 R = 1,003,005
x = 10,000 x2 = 108 3x = 3*104 5 = 5 R = 100,030,005
x = 100,000 x2 = 1010 3x = 3*105 5 = 5 R = 10,000,300,005
30
Y = X2 + 3X + 5, FOR X=1..10

31
Y = X2 + 3X + 5, FOR X=1..20

32
COMMON TIME COMPLEXITIES

BETTER O(1) constant time


O(log n) log time
O(n) linear time
O(n log n) log linear time
O(n2) quadratic time
O(n3) cubic time
O(2n) exponential time
WORSE

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

The Big-O notation:

the running time of an algorithm as a function of the size of its input

worst case estimate

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

iven functions f(n) and g(n), we say that 80


70 3n
n) is O(g(n)) if there are positive constants
60 2n+10
and n0 such that
50
n
n) ≤ cg(n) for n ≥ n0 40
30
xample: 2n + 10 is O(n) 20
2n + 10 ≤ cn 10
0
(c − 2) n ≥ 10 0 10 20
n
n ≥ 10/(c − 2)
Pick c = 3 and n0 = 10
More Big-Oh
Oh Examples
7n-2
7n-2 is O(n)
need c > 0 and n0 ≥ 1 such that 7n-2 ≤ c•n for n ≥ n0
this is true for c = 7 and n0 = 1
3n3 + 20n2 + 5
3n3 + 20n2 + 5 is O(n3)
need c > 0 and n0 ≥ 1 such that 3n3 + 20n2 + 5 ≤ c•n3 for n ≥ n0
this is true for c = 4 and n0 = 21
3 log n + 5
3 log n + 5 is O(log n)
need c > 0 and n0 ≥ 1 such that 3 log n + 5 ≤ c•log n for n ≥ n0
this is true for c = 8 and n0 = 2
BIG-OH
OH AND GROWTH RATE

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)

We can use the big-Oh


Oh notation to rank functions according to their growth rate

f(n)) is O(g(n)) g(n) is O(f(n))


g(n) grows more Yes No
f(n) grows more No Yes
Same growth Yes Yes
BIG-OH RULES

f (n ) = a 0 + a 1 n + a 2 n 2 + ... + a d n d

If is f(n) a polynomial of degree d, then f(n) is O(nd), i.e.,


1. Drop lower-order terms
2. Drop constant factors

Use the smallest possible class of functions


Say “2n is O(n)” instead of “2n
2n is O(n2)”

Use the simplest expression of the class


Say “3n + 5 is O(n)” instead of “3n
3n + 5 is O(3n)”
ASYMPTOTIC ALGORITHM ANALYSIS

The asymptotic analysis of an algorithm determines the running time in big-Oh


big notation

To perform the asymptotic analysis


We find the worst-case
case number of primitive operations executed as a function of the input size
We express this function with big-Oh
Oh notation

Example:
We determine that algorithm arrayMax executes at most 7n − 1 primitive operations

We say that algorithm arrayMax “runs in O(n) time”

Since constant factors and lower-order


order terms are eventually dropped anyhow, we can disregard them
when counting primitive operations
IMPORTANT FUNCTIONS GROWTH RATES

n log(n) n nlog(n) n2 n3 2n
8 3 8 24 64 512 256

16 4 16 64 256 4096 65536

32 5 32 160 1024 32768 4.3x109

64 6 64 384 4096 262144 1.8x1019

128 7 128 896 16384 2097152 3.4x1038

256 8 256 2048 65536 16777218 1.2x1077


TYPES OF ANALYSIS

Best Case Analysis

Average Case Analysis

Worst Case Analysis


TYPES OF ANALYSIS

Best case running time is usually useless

Average case time is very useful but often difficult to determine

We focus on the worst case running time


Easier to analyze

Crucial to applications such as games, finance and robotics


SPACE COMPLEXITY

Space complexity = The amount of memory required by an algorithm to run to


completion
[Core dumps = the most often encountered cause is “dangling pointers”]

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

Fixed part: The size required to store certain data/variables, that is


independent of the size of the problem:
- e.g. name of the data collection
same size for classifying 2GB or 1MB of texts

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.

Sometime Auxiliary Space is confused with Space Complexity. But Auxiliary


Space is the extra space or the temporary space used by the algorithm during it's
execution.

Space Complexity = Auxiliary Space + Input space


MEMORY DURING EXECUTION

Instruction Space: It's the amount of memory used to save the compiled version of

instructions.

Environmental Stack: Sometimes an algorithm(function) may be called inside another

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

and executed inside the funciton A().

Data Space: Amount of space used by the variables and constants.

But while calculating the Space Complexity of any algorithm, we usually consider only Data

Space and we neglect the Instruction Space and Environmental Stack.


SPACE COMPLEXITY

S(P) = c + S(instance characteristics) for(i = 0; i<n; i++) {


c = constant
s+= a[i];
Example: }
float summation(const float (&a)[10], int n )
return s;
{
}
float s = 0;
Space? one for n, one for a [passed b
int i;
reference!], one for i constant sp
EXAMPLE

int square(int a) { return a*a; }

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(n): Going and asking each student individually is O(N).

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

Opcode(e.g. CA, 4C, etc) in the rve


bytecode above, each of them has a db
corresponding mnemonic code (e.g., yD
aload_0 in the example below). The
r.
opcode is not readable, but we can use K.
javap to see the mnemonic form of a
Ra
.class file.
jba
bu
@
co
p
JAVA BYTE yri CODE
gh
t re code for each method in the class.
"javap -c" prints out disassembled
Disassembled code means the seinstructions that comprise the Java bytecodes.
r e
javap -classpath . -c HelloWorld v
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
JAVA PREPROCESSOR
gh
t re HelloWorld
javap -classpath . -verbose
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
PREPROCESSOR
gh
tr
Step before compiler e
se
rvein the source code
Processes the preprocessor commands

Eg. # define MAX_ROWS 10


db
yD
r.
K.
Ra
jba
bu
@
co
p yri
COMPILER
gh
t re
s
It is a computer program that reads source code and converts into assembly
er
code or executable code
ve
High level language to object code db
yD
r.
K.
Ra
jba
b u
@
co
p yri
ASSEMBLER
gh
t re
se
Assembler creates object code by translating assembly language instruction into
OPCODE rve
db
yD
r.
K.
Ra
jba
b u
@
co
p
INTERPRETER yri
gh
tr
es the source code into machine code one line at a
It is a translator which translates
er
time
ve
Whereas compiler translates all lines atd
a same time
by
Dr
.K
.R
ajb
ab
u
@
co
p yri INTERPRETER
PYTHON
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri CODE
PYTHON
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
LINKER
g ht
recreated by the compiler
Linker uses the object files
se
rveto create the executable code
Links the predefined library objects
db
yD
r.
K.
Ra
jba
bu
@
co
LOADERp yri
gh
tr
esin the main memory
Loads the executable code
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
py
rig
ht
re
s
FUNDAMETALS
er OF
ve
OPERATING d b SYSTEM
yD
r.
K.
Ra
jba
bu
@
co
p
OPERATINGyri SYSTEM
gh
tr
Operating System acts asea communication bridge (interface) between the user
s er
and computer hardware
ve
Resource Manager db
yD
Allocates memory and CPU for running the program
r.
K.
Ra
jba
bu
@
co
p
OPERATINGyri SYSTEM
gh
tr
es
Central Processing Unit (CPU)

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.

Main memory is made up of capacitors.d


b ybeD1, or ON.
If a capacitor is charged, then its state is said to

We could also say the bit is set.


r .K
.
If a capacitor does not have a charge, then its state is said to beR
ajb
0, or OFF.

We could also say that the bit is reset or cleared. ab


u
@
co
p
MAINyMEMORY rig
ht
re where each cell contains 8 bits (a 1 or a 0). Eight bits
Memory is divided into cells,
s er
is called a byte.
ve
db
Each of these cells is uniquely numbered.

The number associated with a cell is known asy


Dr
its address.

. 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)

CDs (random access)


e rve
• DVDs (random access) db
Secondary storage media store files that contain y

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.

Dr by the instruction given


Let's us consider an example of addition of two operands
as Add LOCA, RO. .K
.R
ajb
ab
u
@
co
CENTRAL p yri PROCESSING UNIT (CPU)
gh
tr
esare stored in computer memory
Executing instructions that
e
ALU, Control Unit, Registers andrspecial
ve function registers are involved
db
The special function registers include program counters (PC), instruction registers
y Dand memory data registers
(IR), memory address registers (MAR) and memory
(MDR). r.
K.
Ra
jba
bu
@
co
CENTRAL p yri PROCESSING UNIT (CPU)
gh
tr
es devices are (i) polling routine and (ii) interrupt
Two possible ways of servicing
handler er
v etodcheck each of the input and output
Polling enables the processor software
by tests to see if any devices need
devices frequently. During this check, the processor
servicing or not. Dr
.
Interrupt method provides an external asynchronous inputK that informs the
. R being
processor that it should complete whatever instruction that is currently
ajb
executed and fetch a new routine that will service the requesting device
ab
u
@
co
p
ARITHMETIC yri LOGIC UNIT (ALU)
gh
tr
Most of all the arithmeticeand logical operations of a computer are executed in
s erUnit) of the processor.
the ALU (Arithmetic and Logical
ve
d b subtraction, multiplication,
It performs arithmetic operations like addition,
y OR,
division and also the logical operations like AND,
Dr
NOT operations

.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 Program counter monitors the rvexecution


e of instructions. It keeps track on
which instruction is being executed andd what the next instruction will be.
b y D that is currently being
The instruction register IR is used to hold the instruction
executed. r.
K.
Ra
jba
bu
@
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
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.

It is used in personal computers and small


computers. jba It is used in micro controllers and signal processing.

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

Termed as Processor registers. db


A processor register may hold an instruction, ay
sequence or individual characters).
D
storage address, or any data (such as bit
r.
K.
Ra
jba
bu
@
co
p yri
REGISTERS
gh
t re COMMONLY USED REGISTERS

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

Input register INPR 8 jba


Carries input character

Output register OUTR 8 b


Carries output character
u
@
co
p yri
REGISTER
gh
t re
A Register is a group of flip-flops with each flip-flop capable of storing one
s er
bit of information.
ve
d by used to store data taken out
Accumulator: This is the most common register,

from the memory. Dr


.K
. R results
General Purpose Registers: This is used to store data intermediate
ajb
during program execution. It can be accessed via assembly programming.
ab
u
@
co
p yri
REGISTER
gh
t re
Special Purpose Registers: Users do not access these registers. These registers are for
se
Computer system,
rve
db
MAR: Memory Address Register are those registers that holds the address for
memory unit. yD
MBR: Memory Buffer Register stores instruction and data r. received from the
memory and sent from the memory.
K.
R
PC: Program Counter points to the next instruction to be executed.ajb
IR: Instruction Register holds the instruction to be executed.
ab
u
@
co
p yri
REGISTERS
gh
t re
The Memory unit has a capacity of 4096 words, and each word contains 16 bits.
se
The Data Register (DR) contains 16 bits which hold the operand read from the memory
location.
rve
db
The Memory Address Register (MAR) contains 12 bits which hold the address for the memory
location.

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.

NOT, AND, OR and XOR


r .K
Inverse gates - NAND, NOR and XNOR
. Ra
jba
bu
@
co
p
LOGICyGATES rig
ht
re system.
Main structural part of a digital
s erinput logic requirements are satisfied.
Produces signals of binary 1 or 0 when
ve
dbebdescribed by means of algebraic
Distinct graphic symbol, and its operation can
expressions. yD
r. NOR, and XNOR.
The seven basic logic gates includes: AND, OR, XOR, NOT, NAND,
K.
Rvariables
Truth Table: Depicts the relationship between the input-output binary
ajb
in tabular
form.
a bu(X).
One or two binary input (A, B) variables designated and one binary output variable
@
co
p yri
AND GATE
gh
t re
se
High output only if all its inputs are high

Represented by a dot (.) sign rv


ed
by
D r.
K.
Ra
jba
bu
@
co
p
OR GATE yri
gh
tr
High output only if any e
se
of its inputs are high

Represented by a dot (+) sign rv


ed
by
Dr.
K.
Ra
jba
bu
@
co
p yri
NOT GATE
gh
t re
se
Inverted version of the input at its output.

Also known as an Inverter rve


db
yD
r.
K.
Ra
jba
bu
@
co
p
NANDyGATE
rig
ht
re
se
Equal to an AND gate followed by a NOT gate

rvlowe
Gives a high output if any of the inputs are
db
Represented by a AND gate with a small circle on the output

Small circle represents inversion


y Dr
.K
.R
ajb
ab
u
@
co
p yri
NOR GATE
gh
t re
se
Equal to an OR gate followed by a NOT gate

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

Represented by an encircled plus sign


db
yD
r.
K.
Ra
jba
bu
@
co
p
XNORyGATE
rig
ht
re
Exclusive NOR Gate
se
Inverse operation to the XOR gate rve
db
Low output if one of its inputs is high but not both of them
yD
r.
K.
Ra
jba
bu
@
co
BOOLEAN p yri ALGEBRA
gh
t revariables and logic operations
Algebra that deals with binary
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
COMBINATIONAL CIRCUIT
gh
t
Comprises of logic gates whosereoutputs at any time are determined directly from the
se any regard to previous inputs.
present combination of inputs without
rve
db
Information-processing operation fully specified logically by a set of Boolean functions

Input variables, logic gates, and output variables y


Dr
.K
.R
ajb
ab
u
@
co
p yri
COMBINATIONAL CIRCUIT
gh
Design Procedure: tr
es
The problem is stated. er
v edand required output variables is determined.
The total number of available input variables
b y Dsymbols.
The input and output variables are allocated with letter

r.between inputs and outputs is


The exact truth table that defines the required relationships
derived.
K .R
The simplified Boolean function is obtained from each output. (K-Map) aj
ba
The logic diagram is drawn. bu
@
co
p
HALF yADDER rig
ht
Two binary inputs (augend r
es
and addend bits) and two binary outputs ( sum and carry).

erexpressions is: S = x'y+xy', C = xy


The simplified sum of products (SOP)
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p
FULL ADDERyri
gh
t readdend , carry from the previous lower significant position
Three binary inputs (augend,
seand carry).
bits) and two binary outputs ( sum
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
FULL ADDER
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
LATCHESp yri
gh
tr
es changes its output based on the applied input.
Electronic device that instantly
e
We use latch to store either 0 orr1 v
ed
at any specified time.

complement to each other.


b
The "SET" and "RESET" are two inputs in a latch, and there are two outputs that are
yD
Used to store one bit of data and it is a memory device..
r
K.
Ra
A latch is just like a flip-flop, but latch is not a synchronous device.

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

er stable states of Flip-Flop, which are represented as


A Latch is a bistable device, and the state of the Flip-Flop is also a bistable device and there are two
latch is represented as 0 and 1.
ve0 and 1.
A Latch is a level triggered device.
d b
Flip-flop is an edge triggered device.
We can y
We cannot classify the Latch.
Dflipflops.
classify the flip-flop as synchronous or
asynchronous
r
To form sequential circuits, latches are
. K Flip-Flop is constructed
To form sequential circuits,
from latches along with. an additional clock signal.
constructed from logic gates.
Latches are fast as compared to the Flip-Flop. Flip-Flops are slow as compared
R ajtobthe latches.
Less power is consumed by the Latches.
ab
More power is consumed by the 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

J stands for SET, and 'K' stands for CLEAR.


D r.
K.
When both the inputs J and K have a HIGH state, the flip-flop switches Rtoathe complement
jba
state, so, for a value of Q = 1, it switches to Q=0, and for a value of Q = 0, it switches to Q=1.

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

Larger memories can be builte


s byr
v ed(i) “Horizontal” expansion to increase
Using a 2D array of these 1-bit devices
word size by
Dr
(ii) “Vertical” expansion to increase number of words

Dynamic RAMs use a tiny capacitor to store a bit


. K.
R ajtobstore a
Design concepts are mostly independent of the actual technique used
bit of data ab
u
@
co
p
BUILDING yri A SIMPLE MEMORY
gh
4X3 memory design re
t
s er
Uses 12 D flip flops in a 2D array
ve
d abword)
Uses a 2-to-4 decoder to select a row (i.e.
yD
Multiplexers are used to gate the appropriate output
r . signal
A single WRITE (WR) is used to serve as a write and read K. – zero is used to
indicate write operation – one is used for read operation Ra
Two address lines are needed to select one of four words of 3 bits eachjb
ab
u
@
co
p yri A SIMPLE MEMORY
BUILDING
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
py
rig
ht
re
se
NUMBER rve SYSTEM
db
yD
r.
K.
Ra
jba
bu
@
co
p yri REPRESENTATION
STORAGE
gh
tr
es
er
ve
db
yD
r.K
.R
ajb
ab
u
@
co
BIT AND p yri BYTE
gh
t r stored in a computer and it has a value of 0 or 1
A bit is the smallest unit of data
es
It’s like a switch, on (1) or off (0) e
r v in RAM and auxiliary storage devices by two-
In computers, bits are stored electronicallye

state digital circuits


d by
Drrepresents, but software
The storage device itself doesn’t know what the bit pattern
. K stores and interprets the
(application software, operating system, and I/O device firmware)

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.

Why is the base 10 for decimal numbers? e


v

db
o
yD
Because we use 10 digits, the digits 0 through 9.

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,

Example of a binary number and thee


v
• d bof the positions:
values

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.

• y DTherefore, we sometimes use the


Memory addresses and other data can be quite large.
hexadecimal number system. r.
K.
Ra
jba
14 bu
@
co
p yri
THE HEXADECIMAL NUMBER SYSTEM
gh
tr
•The hexadecimal number essystem is also known as base 16. The values of the
er 16 to some power.
v
positions are calculated by taking

Why is the base 16 for hexadecimale


• d b?
numbers

•Because we use 16 symbols, the digits 0 and 1y


and the letters A through F.
Dr
.K
.R
ajb
ab
15
u
@
co
py
THE HEXADECIMAL NUMBER SYSTEM (CON’T)
rig
ht
• Binary
re
Decimal Hexadecimal Binary Decimal Hexadecimal
• 0 0 0
se 1010 10 A

• 10
1 1
2
1
2
rve
1011
1100
11
12
B
C
• 11 3 3 db
1101 13 D


100
101
4
5
4
5
yD
1110
1111
14
15
E
F
110 6 6 r.

• 111 7 7 K.
• 1000 8 8 Ra
• 1001 9 9
jba
16 bu
@
co
THE HEXADECIMAL NUMBER SYSTEM (CON’T)
py
rig
ht
re number and the values of the positions:
Example of a hexadecimal
se
3 C 8 B 0 5 v1
r e
166 165 164 163 162 161 160d
by
Dr
.K
.R
ajb
ab
17
u
@
co
EXAMPLE p yri OF EQUIVALENT NUMBERS
gh
t
Binary: 1 0 1 0 0 0 0 1 0 1 0r0e1 1 12
se
Decimal: 2064710
rve
db
Hexadecimal: 50A716 yD
r.
K.
Notice how the number of digits gets smaller as the base increases.
Ra
jba
18 bu
@
co
BINARYp yriREPRESENTATION
gh
tr
es(as suppose to decimal or octal, etc..)?
Why binary representation
e
Because the devices that storerand manage the digital data are far less
v
expensive and complex for binary e db
representation.

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

133 = 1 X 10^2 + 3 X 10^1 + 3 * 10^0 r.


K.
Binary Number System Ra
10011 = 1 * 2^4 + 0 * 2^3 + 0 * 2^2 + 1*2^1 + 1*2^0 = 19 jba
bu
@
co
p
DATAyREPRESENTATION
rig
ht
Octal
r es
5378
e rve= 351 (base 10)
5 * 8^2 + 3 * 8^1 + 7 * 8^0

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

The remaining bits represent the value


db
yD
r
So, in 1-byte of storage the maximum number storable is not 255 as it was for the unsigned
.
integer representation, but 127: K.
Ra
jba
bu
@
co
SIGNED p yriPOSITIVE INTEGER
gh
t re
To determine what the sign-and-magnitude representation of a positive decimal
number is: se
r
Convert the decimal number to binaryve
d blocation
If needed add leading zeros to fill the storage
yD
r.
For example, decimal 12 is represented in 1-byte as 00001100 because 8 + 4 = 12:
K.
Ra
jba
bu
@
co
SIGNED p yriPOSITIVE INTEGER
gh
t
Going the other way, given rea sign-and-magnitude representation for a positive
se
r
number, one can interpret it as follows:
ve
Leftmost bit will be 0 indicating positive
d by
Convert the remaining bits to a decimal number

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

Flip all the bits


r.
Add 1 to the result of the last step K.
Make the sign bit 1 Ra
Some people find this easier
j b ab
u
@
co
p yri
CONCERNS
gh
t re
Only addition and complement operation sufficient for all operations.
seto overflow.
Adding 7 + 7 or -7 -7 will lead
rve
db
yD
r.
K.
Ra
jba
b u
@
co
p yri
CONCERNS
gh
t re
Addition: 5 + 3 = 5 + (+3)
Subtraction : 5 - 3 = 5 + (-3)se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p
DIMINISHED yri RADIX-COMPLEMENT
gh
t re
Also called as “1’s complement”.
se
n
DRCOMP(X) = R – 1 – X
rve
Rn =Modulo representation db
E.g. X = 6 is represented in modulo 16 bit is 16 –y1 – 6 = 9
Dr
.K
.R
ajb
ab
u
@
co
p yri RADIX-COMPLEMENT
DIMINISHED
gh
tr
Integer es
1’s Complement Integer 1’s Complement
0 0000 er -1(16-1-1) 1110
1 0001 ve -2(16-1-2) 1101
2 0010 db -3(16-1-3) 1100
3
4
0011
0100
yD
-4(16-1-4)
-5(16-1-5)
1011
1010
5 0101 r.
-6(16-1-6) 1001
6 0110 -7(16-1-7) K. 1000
7 0111 -0(16-1-0)
Ra 1111

The range of values defined using 4-bit is -7 to 7 jba


b u
@
co
p yri
CONCERNS
gh
t re
Only addition and complement operation sufficient for all operations.
Available of both -0 and +0 swhich
er may lead to computational issues.
3+4 = 7, 3 -4 = -1, -3 + 4 result in ‘0’.v
7+7 = -1, -7 – 7 = 0
edb
Error due to overflow. yD
r.
K.
Ra
jba
bu
@
co
OVERFLOW p yri RULES
gh
t re can never cause overflow
Addition of +ve and –ve number
s
Addition of 2 +ve or 2 –ve numberse rvnotecause overflow if the resulting sum has the
does
same sign as the two operands.
db
Exception: in 2’s complement adding 2 n bit negative ynumbers
D
(n+1)
such that |a| + |b| < 2

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

In 2’s complement, 2 <= N <= 2rv-1


ed
n-1 n-1

In 1’s complement, 2 +1 <= N <= 2 -1


n-1 n-1
by
Dr
.K
.R
ajb
ab
u
@
co
BINARY p yriCODED DECIMAL (BCD)
gh
tr
escomputers adopt BCD format to represent integer
Recent computers and large
53 in a 4 bit representation ise rv0011
0101 0
Mainly used in IBM mainframes ed
Last bit is used for negative. by
-53 = 0101 0010 1 Dr
.K
.R
ajb
ab
u
@
co
BINARY p yriCODED DECIMAL (BCD)
gh
tr
es of BCD have different rules.
The addition and subtraction
e
The BCD arithmetic is little morercomplicated.
ve
db
BCD needs more number of bits than binary to represent the decimal number. So
BCD is less efficient than binary. yD
r.
K.
Ra
jba
bu
@
co
p
REAL yNUMBERS rig
ht
re
Fixed Point Representation
se
In the floating-point notation a r venumber is represented by a 32-bit string.
real
d b of Mantissa and remaining 8-bit
Including in 32-bit, 24-bit use for representation
y D and the exponent are twos
use for representation of Exponent .Both the mantissa
complement binary Integers.
r.
K.
Ra
jba
bu
@
co
p
REAL yNUMBERS rig
ht
refrom distance of sun to earth (16,800,000,000,000) and
To assign values ranging
s er
energy emission (0.000000000000832).
v edof the computer.
Precision is directly affected in the cost

The general form of a real number in radix Ry


b is
Dr
F-1 f-2… f-M X RE
.K
Where F f … f is the fractional part or mantissa
-1 -2 -M .R
And E is the exponent which is always integer ajb
ab
u
@
co
p
REAL yNUMBERrig
ht
re Vs Accurate measurement
se
Round off Error - Approximation

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

In excess notation the MSB also known as the signD


r.
bit of 1 represents the non-
negative (+) sign and a 0 indicates a negative (-) number.K
.R
ajb
ab
u
@
co
p
REAL yNUMBER - EXCESS NOTATION
rig
h t r for example: 0110 the digit/column value of the most
In the case of a 4-bit pattern,
es are referred to as an excess (8) notation.
significant bit is 8, so 4 bit patterns
er
To convert this example find the sum valueveof the entire pattern as though a standard
binary number: db
(0x8) + (1x4) + (1x2) + (0x1) = 6
yD
Then subtract the excess value,8, from the sum, (6 - 8)
r .K
.R
The result is a signed value, -2.
ajb
ab
u
@
co
p
REAL yNUMBER - EXCESS NOTATION
rig
ht
re 11110, the digit/column value of the most significant bit is 16,
In the case of a 5-bit pattern example,
so 5-bit patterns are referred to as s ane excess (16) notation.
rve
number:
d
To convert this example find the sum value of the entire pattern as though a standard binary
by
(1x16) + (1x8) + (1x4) + (1x2) + (0x1) = 16 + 8 + 4 + 2 + 0 = 30 D
r.
K. result is a signed value, + 14.
Then subtract the current excess value, 16, from the sum, (30 - 16). The
R anegative
Therefore, it is evident that in excess notation, the sign bit of 0 represents the
represents the non-negative sign to denote a signed value.
j bab
sign and 1

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

Numbers come before letters db


The special characters are spread around yD
r. groupings, so that their
codes increment by one
K
The numbers and upper and lowercase characters are in adjacent
.R
ajb
ab
u
@
co
ASCII y p CHART
rig
h t r the binary codes for the upper and lowercase characters is the
The only difference between
e sefor a lowercase character is 32 greater than the
sixth bit, that is, the decimal code
uppercase character’s decimal code rv
ed
by (nonprintable) like bell, backspace,
ASCII codes before decimal 32 are control characters
and carriage return Dr
. DEL
The final ASCII code in the 7-bit chart is the control character K.with decimal code 127
Ra
jba
bu
@
co
EXTENDED p yri ASCII & UNICODE
gh
The eight-bit ASCII charttis rsometimes called Extended ASCII
es
The seven-bit ASCII codes are the e
rve
same in eight-bit chart except have a zero at the left

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:

Arithmetic, logical and shift instructions db


y Dmemory and processor registers.
A set of instructions for moving information to and from
r . Kthat check status conditions.
Instructions which controls the program together with instructions

Input and Output instructions


. Ra
jba
bu
@
co
p yri
CLASSIFICATION OF INSTRUCTION
gh
t redata between register or between register and memory
Data Transfer – transfer
MOV B, A MVI A Data se
Arithmetic rve
Logical db
Branching yD
Control
r.
K.
Ra
jba
bu
@
co
p
DATAyTRANSFERrig
ht
re from Address
LDA <Addr> – Load accumulator
se from Register
LDAX <Register> Load accumulator
LXI <Register> <Address>
rve
LHLD <Address> - Load to Register ‘L’ d
STA, STAX – Store Accumulator Direct
byD
r.
K.
Ra
jba
bu
@
co
p yri
INSTRUCTION TYPES
gh
Data transfer
t re
Data operation se
Program control
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p
DATAyTYPES
rig
ht
re
Numeric (integer, floating point)
Boolean (true, false) se
Character (ASCII, Unicode)
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ADDRESSING MODES - DIRECT
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ADDRESSING MODES - INDIRECT
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ADDRESSING MODES - REGISTER DIRECT
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ADDRESSING MODES - REGISTER INDIRECT
gh
tr
e
@ R se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ADDRESSING MODES - IMMEDIATE
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ADDRESSING MODES - IMPLICIT
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ADDRESSING MODES - RELATIVE
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ADDRESSING MODES - INDEXED
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
INSTRUCTION FORMATS
gh
t re
More operands = less instructions
se
More operands = larger words
rve
db
yD
r.
K.
Ra
jba
bu
@
c op
3-OPERAND INSTRUCTIONS
yri
gh
tr
es
er
ve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri INSTRUCTIONS
2-OPERAND
gh
tr
es
er
ve
db
yD
r.K
.R
ajb
ab
u
@
co
p yri INSTRUCTIONS
1-OPERAND
gh
tr
es
er
ve
db
yD
r.K
.R
ajb
ab
u
@
co
p yri INSTRUCTIONS
0-OPERAND
gh
tr
es
er
ve
db
yD
r.K
.R
ajb
ab
u
@
co
p
INSTRUCTIONyri SET ARCHITECTURE
gh
Instruction set
t re
Register set se
Memory access information
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ISA ATTRIBUTES
gh
Completeness
t re
Orthogonality se
Register set design
rve
db
yD
r.
K.
Ra
jba
bu
@
co
p yri
ISA REQUIREMENTS
gh
t
Backward compatibility re
Data types/sizes se
Interrupts
rve
Conditional instructions db
yD
r.
K.
Ra
jba
bu
@
co
p yri
A RELATIVELY SIMPLE ISA - REGISTERS
gh
Accumulator AC
t re
General purpose register R se
Flag Z
rve
db
yD
r.
K.
Ra
jba
bu
@
co
py
A RELATIVELY SIMPLE ISA - INSTRUCTION
SET rig
ht
re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
py
A RELATIVELY SIMPLE ISA - INSTRUCTION SET
rig
(CONTINUED)
ht
re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
co
py
A RELATIVELY SIMPLE ISA - INSTRUCTION
FORMATSrig
ht
re
se
rve
db
yD
r.
K.
Ra
jba
bu
@
c
EXAMPLE op RELATIVELY SIMPLE PROGRAM
yri
gh
1 + 2 + ... + n , o r
t re∑s i
n

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

Address Bus Size 16-bit ve 20-bit


db
Clock Speed 3MHz
y DVaries in range 5.8 – 10 MHz
Duty Cycle for clock 50% r.
33%

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

Memory Size 64KB


d by 1MB
No multiplication and division D Multiplication and Division
Instruction
instruction roperations
. K are present
Instruction Queue Does not support
.
Supports R
Support ajb
ab
u
@
co
py
rig
ht
re
HARDWARE s er DESCRIPTION
ve
LANGUAGEdb
yD
r.
K.
Ra
jba
bu
@
co
HARDWAREp yri DESCRIPTION LANGUAGE
gh
t
HDL is a language thatre describes the hardware of digital systems in a textual
form. se
rveand operation of electronic circuits
Used to program the structure, design
It resembles a programming language,d but is specific oriented to describing
hardware structures and behaviors by
Dr
Traditional programming represents serial instructions whereas HDL represents
parallel instructions
Provides alternative to schematics
. K.
Ra
jba
bu
@
co
HARDWAREp yri DESCRIPTION LANGUAGE
gh
t r
The principal feature of ea hardware description language is that it contains the
s
implementation. er
capability to describe the function of a piece of hardware independently of the

ve was the recognition that a single language


The great advance with modern HDLs
could be used to describe the function ofdthebdesign and also to describe the
implementation.
y
This allows the entire design process to take place D
in a single language, and thus
a single representation of the design. r.
K.
Ra
jba
bu
@
co
HARDWAREp yri DESCRIPTION LANGUAGE
gh
t r
The principal feature of ea hardware description language is that it contains the
s
implementation. er
capability to describe the function of a piece of hardware independently of the

ve was the recognition that a single language


The great advance with modern HDLs
could be used to describe the function ofdthebdesign and also to describe the
implementation.
y
This allows the entire design process to take place D
in a single language, and thus
a single representation of the design. r.
K.
Ra
jba
bu
@
co
VERILOG p yri
gh
t re Language, usually just called Verilog, was designed and
The Verilog Hardware Description
first implemented by Phil Moorby sateGateway Design Automation in 1984 and 1985.
rve
d
Verilog simulators are available for most computers at a variety of prices, and which have a
by
variety of performance characteristics and features.

Verilog is more heavily used than ever, and it is growingD


r
faster than any other hardware
.
description language. K.
It has truly become the standard hardware description language. R
ajb
ab
5/23/2021

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.

2. Integer Integers are 32 bit signed values. Arithmetic ydone


D on integers is 2's complement.

3. Time Registers declared with the time keyword are 64-bitrunsigned


. K integers.
4. Real (and Realtime) Real registers are 64-bit IEEE floating point..Not Rallaoperators can be
used with real operands. Real and realtime are synonymous. jba
5/23/2021 bu
117
@
co
p yri
EXAMPLE
gh
t re
Primitives are instantiated in a module like any other module instance. For example, the
se
module represented by this diagram would be instantiated:
module test; rve
wire n1, n2; db ain n2
reg ain, bin;
and and_prim(n1, ain, bin);
y D bin
n1

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 */

/* start of a block comment er // Equivalent...

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);

and (a, s1_, s0_);


and (b, s1_, s0);
yD
and (c, s1, s0_); r.
and (d, s1, s0); K.
endmodule Ra
jba
5/23/2021
bu
123
@
co
p yri MODULE EXAMPLE
VERILOG
gh
tr
module shift (shiftOut, dataIn, shiftCount);
es
parameter width = 4;
output [width-1:0]
er
ve
shiftOut; input [width-1:0] dataIn;
input [31:0] shiftCount;
db
assign shiftOut = dataIn << shiftCount;
endmodule yD
r .K
This module can now be used for shifters of various sizes, simply by changing the width parameter.
Parameters can be changed per instance.
.R
ajb
shift sh1 (shiftedVal, inVal, 7); //instantiation of shift module defparam sh1.width = 16; // parameter
redefinition
ab
5/23/2021
u124
@
co
p yri
NET COMPONENT (CONNECTORS)
gh
tr
es
Nets are the things that connect model components together. They are usually thought of as wires in a
circuit. Nets are declared in statements like this:
er
net_type [range] [delay3] list_of_net_identifiers ;
ve
or
db
net_type [drive_strength] [range] [delay3]
yD
list_of_net_decl_assignments ;

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

You might also like