LOGIC GATES Etc 6B
LOGIC GATES Etc 6B
1. Logic Gates
Logic gates are the fundamental building blocks of digital circuits. They perform basic logical functions and are
used to create more complex circuits. The common types of logic gates are:
a. AND Gate
Operation: The output is 1 only if both inputs are 1.
Truth Table:
A B Output (A AND B)
0 0 0
0 1 0
1 0 0
1 1 1
b. OR Gate
Operation: The output is 1 if at least one of the inputs is 1.
Truth Table:
A B Output (A OR B)
0 0 0
0 1 1
1 0 1
1 1 1
c. NOT Gate (Inverter)
Operation: Reverses the input (inverts the signal).
Truth Table:
A Output (NOT A)
0 1
1 0
d. NAND Gate
Operation: The output is 0 only if both inputs are 1.
Truth Table:
A B Output (A NAND B)
0 0 1
0 1 1
1 0 1
1 1 0
e. NOR Gate
Operation: The output is 1 only if both inputs are 0.
Truth Table:
A B Output (A NOR B)
0 0 1
0 1 0
1 0 0
1 1 0
f. XOR Gate (Exclusive OR)
Operation: The output is 1 if one and only one input is 1.
Truth Table:
A B Output (A XOR B)
0 0 0
0 1 1
1 0 1
1 1 0
g. XAND Gate (Exclusive AND)
Operation: The output is 1 if both inputs are 1, otherwise 0 (similar to AND but with exclusive control).
Truth Table:
A B Output (A XAND B)
0 0 0
0 1 0
1 0 0
1 1 1
2. Flip-Flops
Flip-flops are circuits used to store binary data (0 or 1). They are the building blocks of memory and registers in
digital computers.
a. Data Flip-Flop (D-Flip-Flop)
Operation: The output Q takes the value of input D on the triggering edge of the clock pulse.
Truth Table:
Clock D Q (Output)
↑ 0 0
↑ 1 1
b. JK Flip-Flop
Operation: A more versatile flip-flop with inputs J and K. It can be toggled, set, or reset based on the
inputs.
Truth Table:
Clock J K Q (Output) Description
↑ 0 0 No Change No Change
↑ 0 1 0 Reset
↑ 1 0 1 Set
↑ 1 1 Toggle Toggle (Flip)
c. SR Flip-Flop (Set-Reset)
Operation: Uses inputs S (set) and R (reset) to control the output.
Truth Table:
Clock S R Q (Output) Description
↑ 0 0 No Change No Change
↑ 0 1 0 Reset
↑ 1 0 1 Set
↑ 1 1 Invalid Invalid State (undefined)
3. Registers
A register is a small storage location that holds data or instructions. A register typically contains multiple flip-
flops. Registers are used to store intermediate data within the CPU.
Example:
A 4-bit register might consist of four D-Flip-Flops, where each flip-flop stores one bit of data.
4. Counters
A counter is a sequential circuit that counts in a specific sequence, such as binary counting.
Binary Counter: A counter that increments or decrements in binary. A 4-bit binary counter can count
from 0 to 15 (0000 to 1111 in binary).
5. Adders
An adder is a digital circuit that performs the addition of two binary numbers.
a. Half Adder
Operation: Adds two single-bit numbers and produces a sum and a carry.
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
Operation: Adds two bits along with a carry-in bit.
Truth Table:
0 0 0 0 0
0 1 0 1 0
1 0 0 1 0
1 1 0 0 1
6. Multiplexers (MUX)
A multiplexer is a device that selects one of many input signals and forwards the selected input to a single
output line.
2-to-1 MUX: It has two data inputs, one control input, and one output.
Truth Table:
Control Output
0 D0
1 D1
7. Encoders
An encoder is a circuit that converts an active input signal into a coded output. For example, a 4-to-2 binary
encoder converts 4 input lines into 2 output lines.
8. Decoders
A decoder is the inverse of an encoder. It takes binary inputs and activates one of many outputs based on the
input.
3-to-8 Line Decoder: It has 3 input lines and 8 output lines.
DATA REPRESENTATION
5. Number Bases
In computer systems, we use different number bases to represent values, such as binary (base-2), decimal (base-
10), octal (base-8), and hexadecimal (base-16).
a. Binary (Base-2)
Uses two digits: 0 and 1.
b. Decimal (Base-10)
Uses ten digits: 0 to 9.
c. Octal (Base-8)
Uses eight digits: 0 to 7. Each octal digit represents three binary digits.
d. Hexadecimal (Base-16)
Uses sixteen digits: 0 to 9 and A to F. Each hexadecimal digit represents four binary digits.
A processor (or Central Processing Unit - CPU) is the brain of a computer system. It performs computations,
executes instructions, and controls the flow of data.
1. CPU Components
The CPU is made up of several key components that work together to process data and instructions. These
components include:
a. Control Unit (CU)
The Control Unit directs the operation of the processor by interpreting and executing instructions. It
manages data flow between the CPU, memory, and input/output devices. It controls the timing and
coordination of operations by generating control signals.
b. Arithmetic and Logic Unit (ALU)
The ALU performs arithmetic operations (e.g., addition, subtraction, multiplication) and logical
operations (e.g., AND, OR, NOT). It processes the data that is being executed.
c. Registers
Registers are small, fast storage locations within the CPU used to hold data temporarily during
processing. Some key types of registers include:
o Program Counter (PC): Holds the address of the next instruction to be executed.
o Accumulator (ACC): Stores intermediate results of calculations.
o Instruction Register (IR): Holds the current instruction being decoded and executed.
d. Bus Interface Unit
The Bus Interface Unit is responsible for communication between the CPU and other components such
as memory, I/O devices, and other processors. It ensures data is transferred correctly across the system
bus.
2. Instruction Format
An instruction is a binary code that tells the CPU what operation to perform. The instruction format
determines how instructions are structured in memory. A typical instruction consists of the following fields:
Opcode: The operation code that specifies the operation to be performed (e.g., ADD, SUB, LOAD,
STORE).
Operand(s): The data or memory location on which the operation is performed (e.g., a number, register,
or memory address).
| Opcode | Operand 1 | Operand 2 | Operand 3 |
| ADD | R1 | R2 | - |
3. Instruction Set
The Instruction Set is a collection of all the instructions a processor can execute. It defines the operations,
formats, and addressing modes available to the programmer. The instruction set architecture (ISA) is critical in
determining the processor’s capabilities.
Key types of instructions in a CPU include:
Data Transfer: E.g., LOAD, STORE
Arithmetic Operations: E.g., ADD, SUB, MUL
Logical Operations: E.g., AND, OR, NOT
Control Flow: E.g., JUMP, CALL, RETURN
Comparison: E.g., CMP (compare), TEST
4. Addressing Modes
Addressing modes define how the CPU accesses data and instructions. The most common addressing modes
include:
a. Immediate Addressing
The operand is specified directly in the instruction. The value is constant.
o Example: MOV R1, #5 (Move the value 5 into register R1)
b. Direct Addressing
The address of the operand is specified explicitly.
o Example: MOV R1, [1000] (Move the value at memory address 1000 into register R1)
c. Indirect Addressing
The operand’s address is stored in a register or memory location.
o Example: MOV R1, [R2] (Move the value at the address stored in R2 into R1)
d. Register Addressing
The operand is stored in a register, and the instruction specifies the register.
o Example: MOV R1, R2 (Move the value in R2 into R1)
e. Indexed Addressing
A register holds a base address, and an offset is added to it to calculate the effective address.
o Example: MOV R1, [R2 + 5] (Move the value at the address R2 + 5 into R1)
6. Cache Memory
Cache Memory is a small, fast type of memory located close to the CPU. It is used to store frequently
accessed data and instructions to reduce the time needed to access them from slower main memory
(RAM).
o Levels of Cache:
L1 Cache: Located on the processor chip, the smallest and fastest cache.
L2 Cache: Slightly larger and slower than L1 cache, often located on the CPU chip or
nearby.
L3 Cache: Larger and slower than L2, typically shared across multiple CPU cores.
Cache Hit: When the requested data is found in the cache.
Cache Miss: When the requested data is not found in the cache, and the system must fetch it from
slower memory.
7. Instruction Cycle
The Instruction Cycle is the process by which the CPU fetches, decodes, and executes instructions. It consists
of the following stages:
1. Fetch: The CPU fetches the instruction from memory (using the Program Counter).
2. Decode: The CPU decodes the instruction to determine the operation and operands.
3. Execute: The CPU performs the specified operation using the ALU or other components.
4. Store: The result of the operation is stored back in a register or memory.
This cycle is repeated for each instruction in the program.
8. Clock Speed
Clock Speed refers to the rate at which the processor executes instructions, measured in Hertz (Hz). A
clock cycle is the time between two ticks of the clock. The higher the clock speed, the faster the
processor can execute instructions.
Example: A processor with a clock speed of 3 GHz can perform 3 billion cycles per second.
Overclocking: Increasing the clock speed beyond the manufacturer’s specifications to boost
performance (can result in overheating).
9. Graphics Processing Unit (GPU)
The Graphics Processing Unit is a specialized processor designed to handle graphics rendering tasks. It
is optimized for performing parallel operations on large datasets, such as rendering pixels in an image or
performing calculations for 3D graphics.
GPU vs. CPU:
o CPU: Optimized for serial processing tasks and general-purpose computing.
o GPU: Optimized for parallel processing, making it ideal for tasks like rendering images, video
decoding, and scientific simulations.