Demp QB
Demp QB
UNIT 2
A Mul plexer (MUX) is a combina onal circuit that selects one of many inputs and forwards the
selected input to a single output line based on control or select lines. The number of select lines
determines how many inputs the MUX can handle.
Theory: A 2:1 MUX has two input lines (I0, I1), one output (Y), and one select line (S). The
select line determines which input is passed to the output. If the select line (S) is 0, the first
input (I0) is selected. If the select line is 1, the second input (I1) is selected.
Truth Table:
Logic Diagram:
Theory: A 4:1 MUX has four input lines (I0, I1, I2, I3), one output (Y), and two select lines (S1,
S0). The select lines choose one of the four inputs based on their binary combina on.
Truth Table:
Logic Diagram:
Theory: A 8:1 MUX has eight input lines (I0 to I7), one output (Y), and three select lines (S2,
S1, S0). The three select lines allow selec ng one of the eight inputs based on their binary
values
Truth table
Logical circuit :
3. Demul plexer Designs
A Demul plexer (DEMUX) is the reverse of a mul plexer. It takes a single input and routes it to one
of several outputs based on select lines.
Theory: A 1:2 Demul plexer takes a single input and routes it to one of two outputs. It has
one select line (S). When S = 0, the input is routed to output O0, and when S = 1, the input is
routed to output O1.
Truth Table:
Logic Diagram:
Theory: A 1:4 Demul plexer takes a single input and routes it to one of four outputs. It has
two select lines (S1, S0). Each combina on of select lines directs the input to one of the four
outputs.
Truth Table:
Logic Diagram:
A 1 to 8 demul plexer consists of one input line, 8 output lines and 3 select lines. Let the input be D,
S1 and S2 are two select lines and eight outputs from YO to Y7. It is also called as 3 to 8 demux
because of the 3 selec on lines.
Truth Table
Logical Circuit
4. Subtractors Designs
A Subtractor is a combina onal circuit that subtracts one binary number (minuend) from another
(subtrahend). It produces a difference and, in some cases, a borrow.
a) Half Subtractor:
Theory: A Half Subtractor subtracts two single-bit binary numbers. It produces a difference
(D) and a borrow output (B_out). The borrow is produced when the minuend bit is smaller
than the subtrahend bit.
Truth Table:
b) Full Subtractor:
Theory: A Full Subtractor subtracts two bits along with a borrow input. It gives a difference
and a borrow output. It’s used for mul -bit binary subtrac on where a borrow input might
be present from the previous lower significant bit.
Truth Table:
5. Adders Designs
a) Half Adder:
Theory: A Half Adder adds two single-bit binary numbers. It produces a sum and a carry
output.
Truth Table:
A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
b) Full Adder:
Theory: A Full Adder adds three bits: two operand bits and a carry-in from a lower-order bit.
It produces a sum and a carry-out for higher-order addi on.
Truth Table:
Boolean Equa ons:
UNIT 3
A Latch and a Flip-Flop are both bistable devices used to store a single bit of data. The key difference
lies in how they operate with respect to ming (clocking).
Can change output any me when Changes state only at clock transi ons
Timing
control signal is ac ve (posi ve or nega ve edge)
Can con nuously change state as long as State change occurs only on the clock
Opera on
the enable is ac ve edge
Used for simple memory elements in Used for more reliable state changes in
Applica ons
combina onal circuits sequen al circuits
A 1-bit memory cell can be constructed using logic gates, such as an SR latch. The SR latch can store a
single bit of data, where:
o The circuit consists of two NOR gates cross-coupled, with inputs for Set (S) and Reset
(R), and outputs Q and Q‾\overline{Q}Q.
Diagram:
b) Clocked SR Flip-Flop:
A Clocked SR Flip-Flop is similar to an SR latch, but with an added clock signal that enables the latch
to change its state only when the clock signal is ac ve.
The output changes based on the S and R inputs, but only when the clock (CLK) is high.
This prevents the flip-flop from changing its state at arbitrary mes, providing more
predictable behavior.
a) JK Flip-Flop:
Theory: The JK flip-flop is a refinement of the SR flip-flop. It overcomes the invalid state
when both inputs are 1 by toggling the output.
Logic Circuit: It uses a combina on of AND gates, OR gates, and a clock input to control the
toggling ac on.
Working: When both inputs J and K are 1, the output toggles. Otherwise, the output is set or
reset based on the values of J and K.
b) SR Flip-Flop:
Theory: The SR flip-flop has two inputs: Set (S) and Reset (R). It stores a binary value, and its
output changes based on the input signals.
Working: When the S input is high, the output is set to 1, and when R is high, the output is
reset to 0.
c) T Flip-Flop:
Theory: The T flip-flop is a modifica on of the JK flip-flop where both inputs are ed
together. It toggles its state on every clock cycle when the T input is 1.
Working: If T = 1, the output toggles on every clock pulse. If T = 0, the output remains
unchanged.
Theory: The D flip-flop has a single data input (D) and is designed to store the input on the
rising edge of the clock signal. It eliminates the race condi on present in the SR flip-flop.
4. Conver ng Flip-Flops
You can convert between different types of flip-flops using logic gates. For example:
Clocking All flip-flops do not receive the clock at the same All flip-flops are triggered by
me; flip-flops change states at different mes. the same clock signal.
Speed Slower due to propaga on delay through flip- Faster as all flip-flops change
flops. states simultaneously.
Design Simpler design, but slower opera on. More complex design, but
Complexity faster.
Example Ripple Counter Parallel Counter
6. Ring Counters
Theory: A Ring Counter is a type of counter where only one flip-flop is high at any given me.
The output of the last flip-flop is fed back to the input of the first flip-flop, crea ng a ring-like
structure.
Working: The flip-flops in the ring shi their states in a circular fashion. A 4-bit ring counter
will cycle through 4 states.
Diagram:
Theory:
An Asynchronous Up Counter, also known as a Ripple Counter, is a type of counter where each flip-
flop is triggered by the previous flip-flop’s output rather than by a common clock signal. This results
in a delay, or ripple effect, as each flip-flop is triggered one a er the other. The counter "counts up"
as it progresses through binary states in increasing order.
Characteris cs:
Each flip-flop toggles on the falling edge (or rising edge, depending on design) of the
previous flip-flop’s output.
In a 3-bit asynchronous up counter, the output of the first flip-flop serves as the clock for the
second flip-flop, and so on.
It is called asynchronous because the flip-flops do not all change states at exactly the same
me.
Logic Diagram:
Q0, Q1, and Q2 are the outputs of the flip-flops, represen ng the count in binary.
Opera on:
The second flip-flop (FF2) toggles when Q0 transi ons from high to low (i.e., on the falling
edge).
The third flip-flop (FF3) toggles when Q1 transi ons from high to low.
Each flip-flop in this counter is in toggle mode, meaning that it changes its state on every falling edge
of the input.
Q2, Q1, and Q0 show the binary count values from 000 to 111.
This asynchronous counter resets a er reaching the binary count of 111 (or 7 in decimal) and starts
from 000 again.
Disadvantages: Propaga on delay due to the ripple effect, making it less suitable for high-
frequency applica ons.
Theory:
An Asynchronous Down Counter is a sequen al counter circuit where each flip-flop is triggered by
the previous flip-flop’s output. However, in a down counter, the flip-flops are designed to count
downwards, meaning they progress in descending binary order from a maximum value to zero. Like
other asynchronous counters, the output of each flip-flop serves as the clock signal for the next flip-
flop, crea ng a ripple effect.
Characteris cs:
It "counts down" in binary sequence, such as from 111 (7 in decimal) down to 000 (0 in
decimal).
Each flip-flop toggles on the falling edge of the output from the previous flip-flop.
This type of counter has cumula ve propaga on delay because each flip-flop waits for the
previous one to change state.
In a 3-bit asynchronous down counter, the counter will decrement from 111 (7 in decimal) down to
000 (0 in decimal) on each clock pulse.
Logic Diagram:
Q0, Q1, and Q2: Output from each flip-flop represen ng the count in binary.
Each flip-flop is configured in toggle mode, meaning that it changes its state on every falling edge of
the signal from the previous flip-flop.
0 1 1 1
1 1 1 0
2 1 0 1
3 1 0 0
4 0 1 1
5 0 1 0
6 0 0 1
7 0 0 0
The Clock Pulse column shows the pulse number, with each pulse decremen ng the counter
by 1.
Q2, Q1, and Q0 show the binary count values, which decrement with each clock pulse from
111 down to 000.
When the counter reaches 000, the next clock pulse will reset it back to the maximum count of 111,
allowing the down count to start again.
Theory: An Asynchronous Up-Down Counter is a sequen al circuit that can count both upwards and
downwards. This counter combines the func onality of an asynchronous up counter and a down
counter, with the direc on of coun ng controlled by an UP/DOWN control input. In asynchronous
counters, each flip-flop’s clock input is driven by the output of the previous flip-flop, crea ng a ripple
effect. Depending on the control signal, the counter either increments (counts up) or decrements
(counts down) its binary value.
Characteris cs:
Each flip-flop’s clock is triggered by the output of the previous flip-flop, resul ng in
asynchronous behavior.
Suitable for applica ons where coun ng direc on needs to switch dynamically.
For demonstra on, consider a 3-bit asynchronous up-down counter, which counts from 0 (000) to 7
(111) in up mode and from 7 (111) down to 0 (000) in down mode.
Logic Diagram: The logic diagram below shows the general structure of a 3-bit asynchronous up-
down counter with JK flip-flops and an UP/DOWN control input. Each flip-flop is connected to toggle
based on the direc on specified by the control signal.
In this circuit:
Q0, Q1, and Q2 are the flip-flop outputs, represen ng the counter value.
Each flip-flop is in toggle mode, meaning that it changes state based on the output of the previous
flip-flop and the mode set by the UP/DOWN input.
2. Q1 toggles on the falling edge of Q0 in up mode or on the rising edge of Q0 in down mode,
depending on the UP/DOWN control.
3. Q2 toggles based on the combined state of Q1 and Q0 and the UP/DOWN input.
Theory: A MOD-4 synchronous up-counter is a digital circuit that counts from 0 to 3 (in binary) and
then resets back to 0. "MOD-4" indicates that the counter has four unique states (00, 01, 10, 11)
before it wraps around. Since it’s a synchronous counter, all flip-flops are triggered by the same clock
signal simultaneously, which ensures no cumula ve delay (unlike asynchronous counters).
Design Requirements:
1. We will use 2 JK flip-flops (labeled as Q1 and Q0) to store the count since 2 bits can
represent four states.
2. Since we need a MOD-4 counter, the counter should reset a er reaching 3 (11 in binary).
3. The JK flip-flops will be connected such that they toggle based on the counter’s current state.
Q0 will toggle on each clock pulse, represen ng the least significant bit (LSB).
Q1 will toggle whenever Q0 transi ons from 1 to 0 (which occurs every second clock pulse),
represen ng the most significant bit (MSB).
We can create a truth table to determine the input condi ons required for the JK flip-flops at each
state.
J1 and K1 control flip-flop Q1, which should toggle only when Q0 transi ons from 1 to 0.
+----------+ +----------+
| FF (Q0) | | FF (Q1) |
+----------+ +----------+
Truth Table
Explana on of Opera on
3. This produces a binary count sequence of 00, 01, 10, 11 on each clock pulse.
Theory: A MOD-8 synchronous up-counter is a digital circuit that counts from 0 to 7 (in binary) and
then resets back to 0, making a total of 8 unique states (hence, MOD-8). In a synchronous counter, all
flip-flops are triggered simultaneously by the same clock pulse, which prevents cumula ve delay
across flip-flops as seen in asynchronous counters.
To achieve this:
2. Each flip-flop toggles based on the current count and its respec ve toggle condi ons.
Q2 toggles when both Q0 and Q1 are 1, which happens every four clock pulses.
The following table shows the current state and next state of the flip-flops for each clock pulse, as
well as the necessary inputs to the JK flip-flops to achieve the desired transi ons.
J2 = Q0 AND Q1, K2 = Q0 AND Q1: Q2 toggles only when both Q0 and Q1 are high.
Explana on of Opera on
1. Q0 toggles with every clock pulse, represen ng the LSB of the count.
3. Q2 toggles when both Q0 and Q1 are high, represen ng the MSB and comple ng the MOD-8
cycle.
9. Shi Registers
Shi Registers
A Shi Register is a sequen al logic circuit used to store and move (shi ) data. They use flip-flops
(o en D flip-flops) and can shi data either le or right. The four main types are:
3. Parallel-In, Serial-Out (PISO): Data is loaded in parallel and shi ed out serially.
In a 4-bit SISO Shi Register, four D flip-flops are connected in sequence. Data enters at the input of
the first flip-flop (Q0) and shi s right with each clock pulse un l it reaches the output of the last flip-
flop (Q3).
Logic Diagram:
| | | |
Q0 Q1 Q2 Q3
Data Storage
Shi registers are fundamental in digital electronics for data handling and transfer.
A Sequence Generator is a digital circuit that produces a specific, repea ng binary sequence with
each clock pulse. It uses flip-flops (such as D or JK) and logic gates to transi on between predefined
states, making it useful for counters, digital clocks, and pa ern genera on.
This sequence generator outputs the sequence 0001, 0011, 0111, 1111 and then repeats. Each bit in
the sequence is represented by a flip-flop (Q3, Q2, Q1, Q0).
State Table:
Applica ons
Sequence generators are essen al in digital electronics for crea ng controlled, repea ng pa erns.
UNIT 4
The 8086 microprocessor is a 16-bit processor developed by Intel, which features a bipar te
architecture divided into two func onal units:
o It fetches instruc ons from memory and provides the addresses for instruc on
fetching and data transfer.
o It contains General Purpose Registers, Flags Register, ALU, and control circuits for
decoding and execu ng instruc ons.
Pointer and Index Registers: SP (Stack Pointer), BP (Base Pointer), SI (Source Index), DI
(Des na on Index)
Flags Register: Contains the status flags (Zero, Carry, Sign, etc.).
The Flag Register of the 8086 microprocessor is a 16-bit register used to store various status flags
that are set or cleared based on the result of opera ons.
The registers in the 8086 microprocessor can be categorized into the following groups:
1. General-Purpose Registers:
o AX, BX, CX, DX (16-bit): Used for arithme c, data manipula on, and indexing.
o These can be further divided into 8-bit registers: AH, AL, BH, BL, etc.
3. Segment Registers:
4. Instruc on Pointer:
In the 8086 microprocessor, the physical address is calculated using the segment address and offset
address.
Formula:
Physical Address=(Segment×16)+Offset\text{Physical Address} = ( \text{Segment} \ mes 16 ) +
\text{Offset}Physical Address=(Segment×16)+Offset
Example:
Calcula on:
Physical Address=(0x2000×16)+0x1234=0x32000+0x1234=0x33234\text{Physical Address} = (0x2000
\ mes 16) + 0x1234 = 0x32000 + 0x1234 =
0x33234Physical Address=(0x2000×16)+0x1234=0x32000+0x1234=0x33234
Explana on: The operand [SI] refers to the memory loca on whose address is stored in the SI
(Source Index) register. The value at this memory loca on is added to AL.
2. MOV AL, BL
Explana on: The contents of the BL register are moved to the AL register directly.
Procedure
A Procedure in assembly language is a block of code that can be called from different parts of the
program. It is used to perform a specific task, and once the task is completed, control returns to the
calling instruc on. Procedures are a fundamental part of structured programming, helping to break
down a complex program into smaller, more manageable blocks of code.
Key Points:
o A procedure can accept parameters (inputs) and may return a value (output).
o Local variables are defined within the procedure, which are not accessible outside of
it.
o Procedures typically involve stack opera ons to store return addresses and
parameters.
ADD_NUMBERS PROC
ADD_NUMBERS ENDP
In this example:
o It performs the addi on of two numbers and then returns control to the calling code
using the RET instruc on.
Macro
A Macro is similar to a procedure, but it works differently. It is essen ally a template of code that
gets expanded inline by the assembler during the assembly process. Macros do not have a separate
execu on stack or parameters (in the tradi onal sense), and they do not cause a jump in execu on,
unlike procedures.
Key Points:
o Macros are expanded at the point of their invoca on, so they are not reusable in the
way procedures are. Every me a macro is called, the assembler replaces the macro
with the actual code.
o Macros can accept parameters, but unlike procedures, they do not involve
pushing/popping parameters to/from the stack.
o Since macros are expanded inline, they can make the code more efficient by
elimina ng the overhead of calling procedures, but they can also increase the code
size if used excessively.
ENDM
ADD_MACRO 5, 10 ; The assembler replaces this with MOV AX, 5 and ADD AX, 10
In this example:
o When invoked, the macro is expanded by the assembler into the actual code (MOV
and ADD instruc ons), as if the code had been wri en directly.
7. Assembler Direc ve
An assembler direc ve is a command in assembly language that provides instruc ons to the
assembler but does not generate machine code.
o Syntax: DB 10h
o Syntax: DW 1234h
The segmenta on concept in the 8086 microprocessor allows it to address more memory than a 16-
bit address bus would typically allow (16-bit addresses can only access 64KB). The 8086 uses
segmented memory to address up to 1MB of memory by combining a segment address and an offset
address. The 8086 uses a 16-bit segment register and a 16-bit offset to form a 20-bit physical
address.
Key Points:
o CS (Code Segment): Points to the segment where the program's code resides.
o ES (Extra Segment): Used for extra data storage, typically during string opera ons.
Each segment is 64KB in size, and the combina on of a segment base and offset provides a 20-bit
physical address, giving access to 1MB of memory.
o The segment address is mul plied by 16 (or shi ed le by 4 bits), and the offset
address is added to it to form the physical address.
Example:
If the CS = 0x2000 and the IP = 0x1234, the physical address is calculated as:
o Modular Programming: Allows different types of data (code, stack, and data) to
reside in separate areas of memory.
o Memory Protec on: Different segments can be protected by the opera ng system to
prevent data from being overwri en.
UNIT 5
1. CPU: The central processing unit that controls the en re opera on of the microcontroller.
2. ROM (Read-Only Memory): Stores the program code. In the 8051, it is typically 4KB.
3. RAM (Random Access Memory): Used to store data and variables during program execu on.
It is 128 bytes in the 8051.
4. I/O Ports: 8051 has four parallel I/O ports (P0, P1, P2, P3), each of 8 bits.
5. Timers/Counters: There are two 16-bit mers/counters in the 8051 to generate delays or
count events.
7. Serial Communica on Control: 8051 supports serial data communica on through the UART.
8. Oscillator/Clock Circuit: Provides the necessary clock signal for the opera on of the
microcontroller.
The Flag Register (Program Status Word or PSW) in 8051 is an 8-bit register that holds the status
flags, which indicate the results of arithme c and logical opera ons.
CY AC F0 RS1 RS0 OV UD P
CY (Carry Flag): Set if a carry is generated from the most significant bit (used in addi on and
subtrac on).
4. 8051 Ports
The 8051 microcontroller has four parallel I/O ports (P0, P1, P2, P3), each of 8 bits, which are used
for interfacing with external devices.
1. Port 0 (P0):
o It is also used for mul plexed address and data bus in some 8051 variants.
2. Port 1 (P1):
3. Port 2 (P2):
o It can also be used for high-order address bus during external memory interfacing.
4. Port 3 (P3):
o 8-bit I/O port with addi onal func ons like serial communica on, interrupts, etc.
Microcontrollers are classified based on factors like architecture, size, processing capability, and
applica on. Common types include:
1. 8-bit Microcontrollers:
2. 16-bit Microcontrollers:
o Have 16-bit data buses and are more powerful than 8-bit controllers.
4. RISC Microcontrollers:
5. CISC Microcontrollers:
o Use Complex Instruc on Set Compu ng (CISC) architecture with a rich set of
instruc ons.
o Designed for specific applica ons, such as motor control, automo ve, or embedded
systems.
The internal RAM of the 8051 microcontroller is organized into several sec ons:
o Memory loca ons 0x00 to 0x7F are used as general-purpose RAM for storing
variables, data, etc.
o Memory loca ons 0x80 to 0xFF are used for Special Func on Registers (SFR), which
control I/O ports, mers, serial communica on, etc.
3. Bit-addressable RAM:
o The first 32 bytes of the RAM (from 0x20 to 0x2F) are bit-addressable. This means
each bit can be accessed and manipulated individually.
4. Stack Area:
o The stack is maintained star ng from 0x08 to 0x1F. The stack is used for storing
return addresses during func on calls and temporary data.
5. Internal RAM Organiza on Diagram:
+-----------------+-------------------------+
+-----------------+ 0xFF) |
| Bit-addressable| |
| RAM (0x20-0x2F) |
+-----------------+-------------------------+
This structure allows for flexible data storage and efficient handling of different memory
requirements within the microcontroller.