CSIR Merged 1
CSIR Merged 1
SCIENCE
Dr. K. Rajbabu M.E. Ph.D
Manager, Controls & Instrumentation
BHEL, Trichy
CONCEPT – PROGRAM – INPUT –
PROCESSING - OUTPUT
LANGUAGE
Human Language
Commonly used to express feelings and communication of messages
It can be oral or gestural communication
Computer Language
Computer language are the languages by which a user command a
computer to work on the algorithm for the desired input and expected
output
PROGRAM
Continuous evolution
Optimization
New requirements & approaches
LEVELS OF PROGRAMMING
LOW LEVEL LANGUAGE
Low-level
level languages provide abstraction from the hardware
Comparatively easier
High-level
level language allows us to write programs that are independent of the type of
computer.
The high-level
level language is easy to learn & maintain.
The high-level
level languages are portable i.e. they are machine-independent.
machine
COMPARISON
Parameters Low-Level
Level Language High-Level Language
It is machine friendly i.e. easily It is user friendly, as it is writt
vel of Understanding
understood by computers. in simple English.
me of Execution Takes time to execute. Executes at a faster pace.
Various Programming editors or IDEs help users develop programming code using one or
more programming languages.
Some of them are Adobe Dreamweaver, Eclipse or Microsoft visual studio, BASIC, C, Java,
PASCAL, FORTRAN are examples of Procedural Programming Language.
FUNCTIONAL PROGRAMMING
LANGUAGES
Declarative programming paradigm constructed by applying and composing functions
It does not support iteration like loop statements & conditional statements like if-else.
if
Some of the most prominent functional programming languages are Haskell, SML,
Scala, F#, ML, Scheme, and More.
OBJECT-ORIENTED
ORIENTED PROGRAMMING
LANGUAGE
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.
It also emphasizes code reusability with the concept of inheritance and polymorphism
allows the spreading of current implementations without changing much of the code.
Most multi-paradigm
paradigm languages are OOPs languages such as Java, C++, C#, Python,
Javascript, and more.
SCRIPTING PROGRAMMING LANGUAGES
programming languages that are not compiled but are rather interpreted.
The instructions are written for a run time environment.
majorly used in web applications, System administration, games and multimedia.
It is used to create plugins and extensions for existing applications.
Server Side Scripting Languages: Javascript,, PHP, and PERL.
Client-Side Scripting Languages: Javascript,, AJAX, Jquery
System Administration: Shell, PERL, Python
Linux Interface: BASH
Web Development: Ruby
LOGIC PROGRAMMING
The language does not tell the machine how to do something but employs
restrictions on what it must consider doing.
#include <iostream>
int main() {
return 0;
}
JAVA PROGRAM
FileName : "HelloWorld.java". */ {
window.
DEVELOPMENT CYCLE (PDLC)
Define
Scope, objective
Analyze
Input – process - output
Assumptions, deliverables, exceptions
Algorithm development
Coding and Documentation
Testing and Debugging
Maintenance
ALGORITHM
Space complexity
How much space is required
Time complexity
How much time does it take to run the algorithm
GENERAL ANALYSIS
Further, dependency on
amount of input
Sequence of input
WHAT DOES “SIZE OF THE INPUT” MEAN?
If we are searching an array, the “size” of the input could be the size of the array
If we are merging two arrays, the “size” could be the sum of the two array sizes
If we are computing the nth Fibonacci number, or the nth factorial, the “size” is n
We choose the “size” to be the parameter that most influences the actual
time/space required
It is usually obvious what this parameter is
Better execution time is through algorithm with linear growth for large amount
of data
TIME ANALYSIS
Ignore the constants and arrive at a common notation with respect to ‘n’ with the
highest value.
IS IT POSSIBLE TO FIND EXACT VALUES?
We know exactly how many bytes and how many cycles each machine instruction takes
For a problem with a known sequence of steps (factorial, Fibonacci), we can determine
how many instructions of each type are required
The steps required to sort an array depend on the actual numbers in the array (which
we do not know in advance)
HIGH LEVEL LANGUAGES
n a higher-level
level language (such as Java), we do not know how long each operation
akes
Which is faster, x < 10 or x <= 9 ?
We don’t know exactly what the compiler does with this
The compiler probably optimizes the test anyway (replacing the slower version with the
faster one)
n a higher-level
level language we cannot do an exact analysis
Our timing analyses will use major oversimplifications
Nevertheless, we can get some very useful results
CONSTANT TIME
Constant time means there is some constant k such that this operation always takes k
nanoseconds
It does not include calling a method whose time is unknown or is not a constant
f a statement involves a choice (if or switch) among operations, each of which takes constant
ime, we consider the statement to take constant time
This is consistent with worst-case analysis
LINEAR TIME
We may not be able to predict to the nanosecond how long a Java program will take, but
do know some things about timing:
for (i = 0, j = 1; i < n; i++) { j = j * i;; }
Which is better?
Clearly, algorithm B is better if our problem size is small, that is, if n < 50
Algorithm A is better for larger problems, with n > 50
So B is better on small problems that are quick anyway
But A is better for large problems, where it matters more
and you want to test whether every element of the first set (sub) also occurs in the second set (super):
System.out.println(subset(sub, super));
(The answer in this case should be false, because sub contains the integer 5, and super doesn’t)
We are going to write method subset and compute its time complexity (how fast it is)
Let’s start with a helper function, member, to test whether one number is in an array
22
MEMBER
static boolean member(int x, int[] a) {
int n = a.length;
for (int i = 0; i < n; i++) {
if (x == a[i]) return true;
}
return false;
}
If x is not in a, the loop executes n times, where n = a.length
This is the worst case
If x is in a, the loop executes n/2 times on average
Either way, linear time is required: k*n+c
SUBSET
static boolean subset(int[] sub, int[] super) {
int m = sub.length;
for (int i = 0; i < m; i++)
if (!member(sub[i], super) return false;
return true;
}
The loop (and the call to member) will execute:
m = sub.length times, if sub is a subset of super
This is the worst case, and therefore the one we are most interested in
Fewer than sub.length times (but we don’t know how few)
We would need to figure this out in order to compute average time complexity
The worst case is a linear number of times through the loop
But the loop body doesn’t take constant time, since it calls member, which takes linear time
ANALYSIS OF ARRAY SUBSET ALGORITHM
We’ve seen that the loop in subset executes m = sub.length times (in the worst case)
Also, the loop in subset calls member, which executes in time linear in n = super.length
Hence, the execution time of the array subset method is m*n, along with assorted
constants
We go through the loop in subset m times, calling member each time
25
WHAT ABOUT THE CONSTANTS?
An added constant, f(n)+c, becomes less and less important as n gets larger
Our timing formula is a polynomial, and may have terms of various orders (constant,
linear, quadratic, cubic, etc.)
We usually discard all but the highest-order
order term
We simplify n2 + 3n + 5 to just n2
BIG O NOTATION
Recall that, if n is the size of the set, and m is the size of the (possible) subset:
We go through the loop in subset m times, calling member each time
Hence, the actual running time should be k*(m*n) + c, for some constants k and c
31
Y = X2 + 3X + 5, FOR X=1..20
32
COMMON TIME COMPLEXITIES
33
ALGORITHM
Repeat for I = 1 to N
Repeat for J = 1 to N
SUM 0
Repeat for K = 1 to N
SUM SUM + A[I, K] * B[K, J]
End Repeat K
C[I,J] SUM
End Repeat J
End Repeat I
ORDER NOTATION
asymptotic behavior
O(n2) means that the running time of the algorithm on an input of size n is
limited by the quadratic function of n
BIG-OH
OH NOTATION DEFINITION
The big-Oh
Oh notation gives an upper bound on the growth rate of a function
The statement “f(n) is O(g(n))”” means that the growth rate of f(n) is no more than the
growth rate of g(n)
f (n ) = a 0 + a 1 n + a 2 n 2 + ... + a d n d
Example:
We determine that algorithm arrayMax executes at most 7n − 1 primitive operations
n log(n) n nlog(n) n2 n3 2n
8 3 8 24 64 512 256
Some algorithms may be more efficient if data completely loaded into memory
Need to look also at system limitations
E.g. Classify 2GB of text in various categories [politics, tourism, sport, natural
disasters, etc.] – can I afford to load the entire collection?
SPACE COMPLEXITY
Variable part: Space needed by variables, whose size is dependent on the size
of the problem:
- e.g. actual text
- load 2GB of text VS. load 1MB of text
SPACE COMPLEXITY
Space complexity is the amount of memory used by the algorithm (including the
input values to the algorithm) to execute and produce the result.
Instruction Space: It's the amount of memory used to save the compiled version of
instructions.
algorithm(function). In such a situation, the current variables are pushed onto the system
stack, where they wait for further execution and then the call to the inside
algorithm(function) is made.
MEMORY DURING EXECUTION
For example, If a function A() calls function B() inside it, then all th variables of the
function A()will get stored on the system stack temporarily, while the function B() is called
But while calculating the Space Complexity of any algorithm, we usually consider only Data
Linear: int sum(int A[], int n) { int sum = 0, i; for(i = 0; i < n; i++) sum = sum + A[i];
return sum; }
RELATIVES OF BIG-OH
big-Omega
f(n) is Ω(g(n))
(g(n)) if there is a constant c > 0 and an integer constant n0 ≥ 1 such that
f(n) ≥ c•g(n) for n ≥ n0
big-Theta
f(n) is Θ(g(n))
(g(n)) if there are constants c’ > 0 and c’’ > 0 and an integer constant n0 ≥
1 such that c’•g(n) ≤ f(n) ≤ c’’•g(n) for n ≥ n0
EXAMPLES
You go and ask the first person of the class, if he has the pen. Also, you ask this person about
other 99 people in the classroom if they have that pen & So on.
O(log n): Now I divide the class in two groups, then ask: “Is it on the left side, or the right
side of the classroom?” Then I take that group and divide it into two and ask again, and so
on. Repeat the process till you are left with one student who has your pen. This is what you
mean by O(log n).
PROBLEM
int i, j, k = 0;
for (i = n / 2; i <= n; i++) {
for (j = 2; j <= n; j = j * 2) {
k = k + n / 2;
}
}
Output:
O(nLogn)
PROBLEM
int a = 0, i = N;
while (i > 0) {
a += i;
i /= 2;
}
PROGRAM EXECUTION
PROGRAM
Plain text
Parsing
Text to command
"javap -c"
c" prints out disassembled code for each method in the class.
Disassembled code means the instructions that comprise the Java bytecodes.
javap -classpath . -c HelloWorld
JAVA PREPROCESSOR
It is a computer program that reads source code and converts into assembly
code or executable code
It is a translator which translates the source code into machine code one line at a
time
Resource Manager
Bus
I / O Devices
CENTRAL PROCESSING UNIT
A bus is a group of parallel wires that carry control signals and data between
components.
MAIN MEMORY
If a capacitor does not have a charge, then its state is said to be 0, or OFF.
Memory is divided into cells, where each cell contains 8 bits (a 1 or a 0). Eight bits
is called a byte.
Main memory is volatile storage. That is, if power is lost, the information in main
memory is lost.
MAIN MEMORY
We do not have to start at address 0 and read everything until we get to the address we
really want (sequential access).
We can go directly to the address we want and access the data (direct or random access).
26
SECONDARY STORAGE MEDIA
Disks -- floppy, hard, removable (random access)
• Tapes (sequential access)
• computer programs
• data
• This
27 type of storage is called persistent (permanent) storage because it is non-volatile.
non
I/O (INPUT/OUTPUT)) DEVICES
28
COMPUTER LEVEL HIERARCHY
DIGITAL SYSTEM
ELEMENTS OF DIGITAL SYSTEM
GENERAL ARCHITECTURE
DETAILED ARCHITECTURE
CENTRAL PROCESSING UNIT (CPU)
(
ALU, Control Unit, Registers and special function registers are involved
The special function registers include program counters (PC), instruction registers
(IR), memory address registers (MAR) and memory and memory data registers
(MDR).
CENTRAL PROCESSING UNIT (CPU)
(
Polling enables the processor software to check each of the input and output
devices frequently. During this check, the processor tests to see if any devices need
servicing or not.
Most of all the arithmetic and logical operations of a computer are executed in
the ALU (Arithmetic and Logical Unit) of the processor.
The instruction register IR is used to hold the instruction that is currently being
executed.
REGISTERS
The two registers MAR and MDR are used to handle the data transfer between
the main memory and the processor.
The MAR holds the address of the main memory to or from which data is to be
transferred.
The MDR contains the data to be written into or read from the addressed word
of the main memory.
REGISTERS
The two registers MAR and MDR are used to handle the data transfer between
the main memory and the processor.
The MAR holds the address of the main memory to or from which data is to be
transferred.
The MDR contains the data to be written into or read from the addressed word
of the main memory.
REGISTERS
Program Counter (PC): Keeps track of the memory location of the next
instructions to be dealt with. The PC then passes this next address to Memory
Address Register (MAR).
Memory Data Register (MDR): It stores instructions fetched from memory or any
data that is to be transferred to, and stored in, memory.
Current Instruction Register (CIR): It stores the most recently fetched instructions
while it is waiting to be coded and executed.
Fixed Program Computers – Their function is very specific and they couldn’t be
programmed, e.g. Calculators.
ame physical memory address is used for Separate physical memory address is used for
nstructions and data. instructions and data.
here is common bus for data and instruction Separate buses are used for transferring data and
ransfer. instruction.
PU can not access instructions and read/write at CPU can access instructions and read/write at the
he same time. same time.
It coordinates the sequence of data movements into, out of, and between a processor’s many su
units.
It interprets instructions.
It controls many execution units(i.e. ALU, data buffers and registers) contained within a CPU.
It also handles multiple tasks, such as fetching, decoding, execution handling and storing results.
CLASSIFICATION OF CONTROL UNIT
Hardwired Control
Microprogrammed Control
CONTROL UNIT
INPUT OUTPUT
Two decoders, I flip-flop and bits 0 through 11 The control of the inputs of the nine register
of IR.
The control of the read and write inputs of
AC (bits 0 through 15), DR (bits 0 through 15), memory
and the value of the seven flip-flops.
To set, clear, or complement the flip-flops
A Hard-wired
wired Control consists of two decoders, a sequence counter, and a number of
logic gates.
An instruction fetched from the memory unit is placed in the instruction register (IR).
The component of an instruction register includes; I bit, the operation code, and bits 0
through 11.
The operation code in bits 12 through 14 are coded with a 3 x 8 decoder.
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
flip designated 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.
MICRO PROGRAMMED CONTROL UNIT
t from some sort of ROM. The desired control signals are simply stored in the ROM, and retriev
uence to drive the micro operations needed by a particular instruction.
micro-operations
operations are performed by executing a program consisting of micro-instructions.
micro
Control memory address register specifies the address of the micro-instruction.
micro
Control memory is assumed to be a ROM, within which all control information is permanently
ed. The control register holds the microinstruction fetched from the memory. control memory.
MICRO PROGRAMMED CONTROL UNIT
The micro-instruction
instruction contains a control word that specifies one or more micro-
micro
operations for the data processor.
Registers are a type of computer memory used to quickly accept, store, and transfer
data and instructions that are being used immediately by the CPU.
A processor register may hold an instruction, a storage address, or any data (such as bit
sequence or individual characters).
REGISTERS
COMMONLY USED REGISTERS
Commonly
Register used Registers
Symbol Number of bits Function
bit of information.
Accumulator:: This is the most common register, used to store data taken out
Special Purpose Registers: Users do not access these registers. These registers are for
Computer system,
MAR: Memory Address Register are those registers that holds the address for
memory unit.
MBR: Memory Buffer Register stores instruction and data received from the
memory and sent from the memory.
The Memory unit has a capacity of 4096 words, and each word contains 16 bits.
The Data Register (DR) contains 16 bits which hold the operand read from the memory
location.
The Memory Address Register (MAR) contains 12 bits which hold the address for the memory
location.
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.
The Accumulator (AC) register is a general purpose processing register.
The instruction read from memory is placed in the Instruction register (IR).
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.
The Output Registers (OR) holds the output after processing the input data.
STORAGE UNIT – CACHE MEMORY
Part of CPU
Lesser access time than the main memory and is faster than the main memory
Stores the program (or its part) currently being executed or which may be executed within a
short period of time
Stores temporary data that the CPU may frequently require for manipulation
STORAGE UNIT – CACHE MEMORY
STORAGE UNIT – PHYSICAL MEMORY
RAM
SRAM, DRAM
ROM
PROM, EPROM, EEPROM
MAIN MEMORY
It is a large and fast memory used to store data during computer operations. RAM: Random
Access Memory
DRAM: Dynamic RAM, is made of capacitors and transistors, and must be refreshed every
10~100 ms. It is slower and cheaper than SRAM.
SRAM: Static RAM, has a six transistor circuit in each cell and retains data, until powered off
MAIN MEMORY
SRAM is a type of semiconductor memory that uses Bistable latching circuitry to store each b
In this type of RAM, data is stored using the six transistor memory cell. Static RAM is mostly
used as a cache memory for the processor (CPU).
DRAM is a type of RAM which allows you to stores each bit of data in a separate capacitor
within a particular integrated circuit.
MAIN MEMORY
SRAM DRAM
SRAM has lower access time, which is faster DRAM has a higher access time. It is slower
compared to DRAM. than SRAM.
SRAM is costlier than DRAM. DRAM cost is lesser compared to SRAM.
SRAM needs a constant power supply, which DRAM requires reduced power consumption
means it consumes more power. the information stored in the capacitor.
SRAM offers low packaging density. DRAM offers a high packaging density.
Uses transistors and latches. Uses capacitors and very few transistors.
L2 and L3 CPU cache units are some general The DRAM is mostly found as the main
application of an SRAM. memory in computers.
The storage capacity of SRAM is 1MB to 16MB. The storage capacity of DRAM is 1 GB to 16G
MAIN MEMORY
SRAM DRAM
SRAM is in the form of on-chip memory. DRAM has the characteristics of off-chip
memory.
The SRAM is widely used on the processor or The DRAM is placed on the motherboard.
lodged between the main memory and
processor of your computer.
SRAM is of a smaller size. DRAM is available in larger storage capacity
This type of RAM works on the principle of This type of RAM works on holding the charg
changing the direction of current through
switches.
MAIN MEMORY
NVRAM: Non-Volatile
Volatile RAM, retains its data, even when turned off. Example: Flash memory.
It also stores the bootstrap loader program, to load and start the operating system when
The internal clock rate is the frequency needed to match the external clock rate.
Bus clock speed, is the speed at which the connection between CPU & memory operates at.
Higher bus speed means you can send more data more quickly
Data rate is how many bits a module can transfer in a given time, and speed is how many bytes
it can transfer.
SECONDARY MEMORY
External memory or non-volatile.
E.g. disk, CD-ROM, DVD, etc
These are magnetic and optical memories.
It is known as the backup memory.. Not connected to CPU directly.
It is a non-volatile memory.
Data is permanently stored even if power is switched off.
It is used for storage of data in a computer.
Computer may run without the secondary memory.
Slower than primary memories.
CONTROL LOGIC GATES
LOGIC GATES
using vacuum tubes, electromagnetic relays (relay logic), fluidic logic, pneumatic
logic, optics, molecules, or even mechanical elements.
Distinct graphic symbol, and its operation can be described by means of algebraic
expressions.
The seven basic logic gates includes: AND, OR, XOR, NOT, NAND, NOR, and XNOR.
One or two binary input (A, B) variables designated and one binary output variable (X).
AND GATE
Exclusive OR
Give a high output if one of its inputs is high but not both of them
Low output if one of its inputs is high but not both of them
BOOLEAN ALGEBRA
Comprises of logic gates whose outputs at any time are determined directly from the
present combination of inputs without any regard to previous inputs.
Information-processing
processing operation fully specified logically by a set of Boolean functions
The total number of available input variables and required output variables is determined.
The input and output variables are allocated with letter symbols.
The exact truth table that defines the required relationships between inputs and outputs is
derived.
Two binary inputs (augend and addend bits) and two binary outputs ( sum and carry).
Three binary inputs (augend,, addend , carry from the previous lower significant position
bits) and two binary outputs ( sum and carry).
FULL ADDER
LATCHES
Electronic device that instantly changes its output based on the applied input.
The "SET" and "RESET" are two inputs in a latch, and there are two outputs that are
complement to each other.
The Latch does not work on the clock edges like the flipflop.
LATCHES
LATCH FLIP-FLOP
atch is a bistable device, and the state of the Flip
Flip-Flop is also a bistable device and there are tw
h is represented as 0 and 1. stable states of Flip-Flop,
Flip which are represented a
0 and 1.
atch is a level triggered device. Flip
Flip-flop is an edge triggered device.
cannot classify the Latch. We can classify the flip-flop
flip as synchronous or
asynchronous flipflops.
orm sequential circuits, latches are To form sequential circuits, Flip-Flop
Flip is constructe
structed from logic gates. from latches along with an additional clock signa
ches are fast as compared to the Flip-Flop. Flip
Flip-Flops are slow as compared to the latches.
s power is consumed by the Latches. More power is consumed by the Flip-Flop.
Flip
LATCHES
LATCH FLIP-FLOP
latches can be clocked or clockless. For all the time, Flip-Flops
Flip are clocked.
y binary inputs can be used to operate the By the clock signal and binary input, the Flip-Flop
Flip
hes. works.
latch is sensitive to the input and as longFlip--Flop is sensitive to the clock signals and until
t is 'On', we can transmit the data. there is a change in the input clock signal, it never
changes the output.
latch cannot be used as a register because Flip--Flop can work as a register because it contains
register requires more advanced clock signals in its input.
ctronic circuits where time plays an
ential role.
LATCHES
LATCH FLIP-FLOP
latch is asynchronous because latch does Flip--Flop is synchronous because flip-flop work on
work on the basis of the time signal. the basis of the clock signal.
latch cannot be built from the gates. Flip--Flop cannot be built from the latches.
ches are responsive towards faults on Flip--Flops are protected toward fault.
ble pin.
FLIP-FLOPS
Asynchronous or transparent are called Latch. Synchronous are called Flip Flop
A flip-flop
flop circuit can remain in a binary state indefinitely (as long as power is delivered to
the circuit) until directed by an input signal to switch states.
Counters, Frequency Dividers, Shift Registers. Storage Registers, Bounce elimination switch
FLIP-FLOPS
A pulse start from the initial value of '0', goes momentarily to '1', and after a short while,
returns to its initial '0' value.
A positive clock source remains at '0' during the interval between pulses and goes to 1
during the occurrence of a pulse.
The pulse goes through two signal transition: from '0' to '1' and return from '1' to '0'.
FLIP-FLOPS
S-R FLIP-FLOPS
Additional control input that determines when the state of the circuit is to be changed
If the value of the clock pulse is '0', the outputs of both the AND Gates remain '0'.
CLOCKED S-R FLIP-FLOPS
FLOPS
D FLIP-FLOPS
D flip-flop
flop is a slight modification of clocked SR flip-flop.
flip
D input is connected to the S input and the complement of the D input is connected to the
R input.
J-K flip-flop
flop can be considered as a modification of the S-R
S flip-flop.
The main difference is that the intermediate state is more refined and precise than that of
an S-R flip-flop.
The characteristics of inputs 'J' and 'K' is same as the 'S' and 'R' inputs of the S-R
S flip-flop.
When both the inputs J and K have a HIGH state, the flip-flop
flip switches to the complement
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.
J-K FLIP-FLOPS
T FLIP-FLOPS
Combinational circuit that converts binary information from the 'n' coded inputs to a
maximum of 2^n different outputs
DECODERS
ENCODERS
Combinational circuit that has 2n input lines and a single output line
The binary information is received from the input lines and directed to the output line. On
the basis of the values of the selection lines, one of these data inputs will be connected to the
output.
Unlike encoder and decoder, there are n selection lines and 2n input lines. So, there is a total
of 2N possible combinations of inputs. A multiplexer is also treated as Mux.
MULTIPLEXER
DEMULTIPLEXER
A De-multiplexer
multiplexer is a combinational circuit that has only 1 input line and 2N output lines.
D Flip-Flop: When the clock triggers, the value remembered by the flip-flop
flip becomes the
value of the D input (Data) at that instant.
T Flip-Flop: When the clock triggers, the value remembered by the flip-flop
flip either toggles or
remains the same depending on whether the T input (Toggle) is 1 or 0.
J-K Flip-Flop: When the clock triggers, the value remembered by the flip-flop
flip toggles if
the J and K inputs are both 1 and the value remains the same if both are 0; if they are
different, then the value becomes 1 if the J (Jump) input is 1 and 0 if the K (Kill) input is 1.
COMPARISON
S-R Flip-Flop: When the clock triggers, the value remembered by the flip-flop
flip remains
unchanged if R and S are both 0, becomes 0 if the R input (Reset) is 1, and becomes 1 if
the S input (Set) is 1. The behavior in unspecified if both inputs are 1. (In Logisim, the value in
the flip-flop remains unchanged.)
BUILDING A SIMPLE MEMORY
BUILDING A SIMPLE MEMORY
Design concepts are mostly independent of the actual technique used to store a
bit of data
BUILDING A SIMPLE MEMORY
A single WRITE (WR) is used to serve as a write and read signal – zero is used to
indicate write operation – one is used for read operation
Two address lines are needed to select one of four words of 3 bits each
BUILDING A SIMPLE MEMORY
NUMBER SYSTEM
STORAGE REPRESENTATION
BIT AND BYTE
A bit is the smallest unit of data stored in a computer and it has a value of 0 or 1
In computers, bits are stored electronically in RAM and auxiliary storage devices by two-
two
The storage device itself doesn’t know what the bit pattern represents, but software
(application software, operating system, and I/O device firmware) stores and interprets the
pattern
That is, data is coded then stored and when retrieved it is decoded
A byte is a string of 8 bits and is called a character when the data is text
BITS, BYTES, AND WORDS
4
NUMBER SYSTEMS
The on and off states of the capacitors in RAM can be thought of as the values 1 and 0,
respectively.
Therefore, thinking about how information is stored in RAM requires knowledge of the
binary (base 2) number system.
5
THE DECIMAL NUMBER SYSTEM
6
THE DECIMAL NUMBER SYSTEM (CON’T)
The decimal number system is also known as base 10. The values of the positions are
calculated by taking 10 to some power.
7
THE BINARY NUMBER SYSTEM
• The binary number system is also known as base 2. The values of the positions are
calculated by taking 2 to some power.
8
THE BINARY NUMBER SYSTEM (CON’T)
• Instead of using ten digits, 0 - 9, the binary system uses only two digits, 0 and 1.
1 0 0 1 1 0 1
26 25 24 23 22 21 20
9
CONVERTING FROM BINARY TO DECIMAL
1 0 0 1 1 0 1 1 X 20 = 1
26 25 24 23 22 21 20 0 X 21 = 0
1 X 22 = 4
20 = 1 24 = 16 1 X 23 = 8
21 = 2 25 = 32 0 X 24 = 0
22 = 4 26 = 64 0 X 25 = 0
23 = 8 1 X 26 = 64
7710
10
CONVERTING FROM BINARY TO DECIMAL (CON’T)
Practice conversions:
Binary Decimal
11101
1010101
100111
11
CONVERTING FROM DECIMAL TO BINARY (CON’T)
• Make a list of the binary place values up to the number being converted.
• Perform successive divisions by 2, placing the remainder of 0 or 1 in each of the positions
from right to left.
• Continue until the quotient is zero.
• Example: 4210
25 24 23 22 21 20
32 16 8 4 2 1
1 0 1 0 1 0
12
CONVERTING FROM DECIMAL TO BINARY (CON’T)
• Practice conversions:
• Decimal Binary
• 59
• 82
• 175
13
WORKING WITH LARGE NUMBERS
0101000010100111 = ?
Humans can’t work well with binary numbers; there are too many digits to deal with.
Memory addresses and other data can be quite large. Therefore, we sometimes use the
hexadecimal number system.
14
THE HEXADECIMAL NUMBER SYSTEM
• The hexadecimal number system is also known as base 16. The values of the
positions are calculated by taking 16 to some power.
• Because we use 16 symbols, the digits 0 and 1 and the letters A through F.
15
THE HEXADECIMAL NUMBER SYSTEM (CON’T)
16
HE HEXADECIMAL NUMBER SYSTEM (CON’T)
3 C 8 B 0 5 1
166 165 164 163 162 161 160
17
EXAMPLE OF EQUIVALENT NUMBERS
Binary: 1 0 1 0 0 0 0 1 0 1 0 0 1 1 12
Decimal: 2064710
Hexadecimal: 50A716
Notice how the number of digits gets smaller as the base increases.
18
BINARY REPRESENTATION
They are also far more reliable when they have to represent one out of two
possible values.
Because the electronic signals are easier to maintain if they carry only binary
data.
BINARY REPRESENTATION
One bit can be either 0 or 1. Therefore, one bit can represent only two things.
To represent more than two things, we need multiple bits. Two bits can represent
four things because there are four combinations of 0 and 1 that can be made from
two bits: 00, 01, 10,11.
Symbols
Roman Numbers
Octal
HexaDecimal
Ranges from 0 to F
PRIMITIVE DATA STRUCTURE
CREATE
Declare n, a, b as integer
DESTROY
SELECTION
UPDATE
N a+b
INTEGER
Signed numbers
UNSIGNED INTEGER
They range from zero to infinity, but no computer can store all the integers in that range
The length of storage is set by the data type the programmer specifies for a variable
UNSIGNED INTEGER
For example, the decimal number 9 is represented as 00001001 when stored in 1-byte
1 becaus
000010012 = 910
One may use the following table to work with binary numbers:
One may use the same table to go the other way, that is, given the decimal number 13,
what is its binary representation?
Find the largest power of 2 that doesn’t exceed the number and place a 1 in that cell:
Subtract that power of 2 from the number and use this as the new number: 13 – 8 = 5
UNSIGNED INTEGER
Then continue in this way until the sum of the powers of two equals the number:
Note that 8 + 4 + 1 = 13
UNSIGNED INTEGER
So, the unsigned integer representation of decimal 13 is 00001101 when stored in 1-byte
1
UNSIGNED INTEGER
If one tries to store a number in a memory location that is not large enough we have what i
called overflow
In this case, depending on the system, one may or may not receive an error message
So, one must not store a number that is larger than the maximum for a given length of
storage
A sign-and-magnitude
magnitude format is used to allow for positive and negative numbers (and zero
The leading bit is designated as the sign bit: 0 for positive or zero, 1 for negative
So, in 1-byte
byte of storage the maximum number storable is not 255 as it was for the unsigned
Because 16 + 1 = 17
CONCERNS
Not economical
Extra Effort required to perform operation (+7+ (-6))
( or (-7+ 6)
Additional operation required to find the sign of the operand.
This is because arithmetic operations are simple to implement when integers are stored thi
way
Although on the surface it seems complicated, at a deeper level it allows for simplicity of
operations
2’S COMPLEMENT
An alternative but equivalent method for converting a negative number to its two’s
complement representation is:
Ignore the sign and convert the decimal number to binary
DRCOMP(X) = Rn – 1 – X
Rn =Modulo representation
E.g. X = 6 is represented in modulo 16 bit is 16 – 1 – 6 = 9
DIMINISHED RADIX-COMPLEMENT
COMPLEMENT
Addition of 2 +ve or 2 –ve numbers does not cause overflow if the resulting sum has the
same sign as the two operands.
Exception: in 2’s complement adding 2 n bit negative numbers such that |a| + |b| < 2(n+1)
Recent computers and large computers adopt BCD format to represent integer
53 in a 4 bit representation is 0101 0011 0
Mainly used in IBM mainframes
Last bit is used for negative.
-53 = 0101 0010 1
BINARY CODED DECIMAL (BCD)
BCD needs more number of bits than binary to represent the decimal number. So
BCD is less efficient than binary.
REAL NUMBERS
In the floating-point
point notation a real number is represented by a 32-bit
32 string.
Including in 32-bit, 24-bit
bit use for representation of Mantissa and remaining 8-bit
8
use for representation of Exponent .Both the mantissa and the exponent are twos
complement binary Integers.
REAL NUMBERS
General Format
This fixed length notation (i.e., the length of the bit pattern used can not be
altered once set at the beginning) makes it possible to store negative (-)
( and
non-negative
negative (+ including zero) values by treating the right-most
right digits referred
to as the Most Significant Bit (MSB) as representing the sign of the number.
In excess notation the MSB also known as the sign bit of 1 represents the non-
negative (+) sign and a 0 indicates a negative (-)
( number.
REAL NUMBER - EXCESS NOTATION
In the case of a 4-bit pattern, for example: 0110 the digit/column value of the most
significant bit is 8, so 4 bit patterns are referred to as an excess (8) notation.
To convert this example find the sum value of the entire pattern as though a standard
binary number:
n the case of a 5-bit pattern example, 11110, the digit/column value of the most significant bit is
o 5-bit
bit patterns are referred to as an excess (16) notation.
o convert this example find the sum value of the entire pattern as though a standard binary
umber:
hen subtract the current excess value, 16, from the sum, (30 - 16). The result is a signed value,
herefore, it is evident that in excess notation, the sign bit of 0 represents the negative sign and
epresents the non-negative
negative sign to denote a signed value.
REAL NUMBER - FRACTIONAL PART OR
MANTISSA
F must lie in the interval R-1 <= F < 1
DATA INTERPRETATION IN COMPUTER
Character String
For example, in some computers, the eight bits 11000000 is used to represent
the character "A" and 11000001 for character "B" and another for each
The numbers and upper and lowercase characters are in adjacent groupings, so that their
codes increment by one
ASCII CHART
The only difference between the binary codes for the upper and lowercase characters is the
sixth bit, that is, the decimal code for a lowercase character is 32 greater than the
uppercase character’s decimal code
ASCII codes before decimal 32 are control characters (nonprintable) like bell, backspace,
and carriage return
The seven-bit
bit ASCII codes are the same in eight-bit
eight chart except have a zero at the left
Some manufactures use the extra bit to create additional special characters, these
however are nonstandard, e.g., using decimal 171 for ½, or 246 for ÷
Unicode is another scheme developed so that the many symbols in international languages
may be represented. It also uses bit patterns. UTF-32
UTF uses 32 bits.
EBCDIC
ASCII code is more commonly used worldwide while EBCDIC is used primarily in
large IBM computers.
LOW LEVEL LANGUAGE
INSTRUCTION SET
Computer instructions are a set of machine language instructions that a particular processor
understands and executes. A computer performs tasks on the basis of the instruction provided
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.
INSTRUCTION CODE FORMAT
A set of instructions for moving information to and from memory and processor registers.
Instructions which controls the program together with instructions that check status condition
Data Transfer – transfer data between register or between register and memory
MOV B, A MVI A Data
Arithmetic
Logical
Branching
Control
DATA TRANSFER
Data transfer
Data operation
Program control
DATA TYPES
@R
ADDRESSING MODES - IMMEDIATE
ADDRESSING MODES - IMPLICIT
ADDRESSING MODES - RELATIVE
ADDRESSING MODES - INDEXED
INSTRUCTION FORMATS
Instruction set
Register set
Memory access information
ISA ATTRIBUTES
Completeness
Orthogonality
Register set design
ISA REQUIREMENTS
Backward compatibility
Data types/sizes
Interrupts
Conditional instructions
A RELATIVELY SIMPLE ISA - REGISTERS
Accumulator AC
General purpose register R
Flag Z
A RELATIVELY SIMPLE ISA - INSTRUCTION
SET
A RELATIVELY SIMPLE ISA - INSTRUCTION SET
(CONTINUED)
A RELATIVELY SIMPLE ISA - INSTRUCTION
FORMATS
EXAMPLE RELATIVELY SIMPLE PROGRAM
n
1 + 2 + ... + n , o r ∑ i
i=1
T h is c o u ld b e w r itte n a s a h ig h -le v e l la n g u a g e
c o d e s n ip p e t a s f o llo w s .
to ta l= 0 ;
F O R i= 1 to n D O { to ta l = to ta l + i} ;
1 . to ta l = 0 , i = 0
2. i = i + 1
3 . to ta l = to ta l + i
4 . IF i ≠ n THEN GOTO 2
EXAMPLE RELATIVELY SIMPLE PROGRAM
CODE
EXAMPLE RELATIVELY SIMPLE PROGRAM
TRACE
THE 8085 ISA - INSTRUCTION SET
Data movement instructions
THE 8085 ISA - INSTRUCTION SET
Data operation instructions
THE 8085 ISA - INSTRUCTION SET
Program control instructions
THE 8085 ISA - INSTRUCTION FORMATS
EXAMPLE 8085 PROGRAM
n
1 + 2 + ... + n , o r ∑ i
i =1
1. i = n, sum = 0
2 . s u m = s u m + i, i = i - 1
3 . IF i ≠ 0 T H E N G O T O 2
4 . to ta l = s u m
EXAMPLE 8085 PROGRAM CODE
EXAMPLE 8085 PROGRAM TRACE
COMPARISON
Property 8085 Microprocessor 8086 Microprocessor
ags It has 5 flags (Sign, Zero, Auxiliary It has 9 flags (Overflow, Direction,
Carry, Parity, Carry) Interrupt. Trap, Sign, Zero,
Auxiliary Carry, Parity, Carry)
COMPARISON
Property 8085 Microprocessor 8086 Microprocessor
Number of processors Only one processor is used More than one processor is used.
Additional processor (external) ca
also be employed
The Verilog Hardware Description Language, usually just called Verilog, was designed and
first implemented by Phil Moorby at Gateway Design Automation in 1984 and 1985.
Verilog simulators are available for most computers at a variety of prices, and which have a
variety of performance characteristics and features.
Verilog is more heavily used than ever, and it is growing faster than any other hardware
description language.
5/6/2021 111
VERILOG
A Verilog model is composed of modules. A module is the basic unit of the model, and it may
be composed of instances of other modules.
A module which is composed of other module instances is called a parent module, and the
instances are called child modules.
comp1
comp2 system
sub3
5/6/2021 112
VERILOG DESIGN CONCEPT
comp1 comp2
sub3
5/6/2021 113
PRIMITIVES
The Verilog primitives are sometimes called gates, because for the most part, they are simple
logical primitives.
5/6/2021 114
REGISTER
Registers are storage elements. Values are stored in registers in procedural assignment
tatements.
Reg This is the generic register data type. A reg declaration can specify registers which are 1
bit wide to 1 million bits wide. A register declared as a reg is always unsigned.
Integer Integers are 32 bit signed values. Arithmetic done on integers is 2's complement.
5/6/2021 116
EXAMPLE
Primitives are instantiated in a module like any other module instance. For example, the
module represented by this diagram would be instantiated:
module test;
wire n1, n2;
ain n2
reg ain, bin; n1
bin
and and_prim(n1, ain, bin);
not not_prim(n2, n1);
ndmodule
5/6/2021 117
ASSIGN
Continuous assignments are sometimes known as data flow statements because they describe
how data moves from one place, either a net or register, to another. They are usually thought
of as representing combinational logic.
Example:
5/6/2021 118
LETS GET THE VERILOG MODULE FOR THIS
CIRCUIT
http://www.doulos.com/knowhow/verilog_designers_guide
re_assignments/
5/6/2021 119
SOLUTIONS USING “ASSIGN” AND “WIRE”
module AOI (input A, B, C, D, end of a block comment */
output F);
// Equivalent...
/* start of a block comment
wire AB = A & B;
wire F;
wire CD = C & D;
wire AB, CD, O;
wire O = AB | CD;
assign AB = A & B;
wire F = ~O;
assign CD = C & D;
endmodule // end of Verilog code
assign O = AB | CD;
assign F = ~O;
end of a block comment */
5/6/2021 120
MODULE ABC IN VABC
ndmodule
5/6/2021 121
MODULE DEFINITION + GATE LEVEL DIAGRAM
module abc (a, b, c, d, s1, s0);
input s1, s0;
output a, b, c,d;
ndmodule
5/6/2021 122
VERILOG MODULE EXAMPLE
module shift (shiftOut, dataIn, shiftCount);
parameter width = 4;
output [width-1:0]
shiftOut; input [width-1:0] dataIn;
input [31:0] shiftCount;
assign shiftOut = dataIn << shiftCount;
ndmodule
his module can now be used for shifters of various sizes, simply by changing the width parameter.
Parameters can be changed per instance.
hift sh1 (shiftedVal, inVal,, 7); //instantiation of shift module defparam sh1.width = 16; // parameter
redefinition
5/6/2021 123
NET COMPONENT (CONNECTORS)
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:
net_type [range] [delay3] list_of_net_identifiers ;
or
net_type [drive_strength] [range] [delay3]
list_of_net_decl_assignments ;
Example:
wire w1, w2;
tri [31:0] bus32;
wire wire_number_5 = wire_number_2 & wire_number_3;
here represents AND operation (AND gate)
5/6/2021 124
4-BIT
BIT ADDER : LETS WRITE VERILOG SOURCE
5/6/2021 125