Decoder With Instruction Decoding
Decoder With Instruction Decoding
Let's now cover the Decoder in exactly the same structured, detailed, and example-
driven manner as we did for the Encoder — including what, why, how, truth table, diagram,
applications, real-world example (with buttons), Verilog code, and summary.
1. What is a Decoder?
A decoder is a combinational logic circuit that converts n input lines into 2ⁿ unique output
lines.
It activates exactly one output line based on the binary value of the inputs.
A decoder takes a binary number as input and decodes it to select one output line
corresponding to that number.
Inputs:
2-bit input: A1 A0
Outputs:
Only one output will be HIGH at a time, based on the input value.
Truth Table:
A1 A0 Y3 Y2 Y1 Y0
0 0 0 0 0 1
0 1 0 0 1 0
A1 A0 Y3 Y2 Y1 Y0
1 0 0 1 0 0
1 1 1 0 0 0
Input 00 → Y0 = 1
Input 01 → Y1 = 1
Input 10 → Y2 = 1
Input 11 → Y3 = 1
Y1 = ~A1 & A0
Y2 = A1 & ~A0
Y3 = A1 & A0
Inputs: A1, A0
+---+---+
| Decoder |
+---+---+
7. Applications of Decoders
Problem:
Suppose you’re designing a toy or learning kit that has 2 switches to choose among 4 output
devices (say, 4 di erent lights or buzzers).
Each time the user presses a binary value using two switches, only one output should
activate.
Solution:
Inputs:
Switch 1 (A1)
Switch 0 (A0)
Outputs:
Y0 → Turns ON Light 0
Y1 → Turns ON Light 1
Y2 → Turns ON Light 2
Y3 → Turns ON Light 3
0 0 0001
0 1 0010
1 0 0100
A1 A0 Light Output (Y3 Y2 Y1 Y0)
1 1 1000
Simple Diagram:
[Switch 1] ---> A1 ┐
[Switch 0] ---> A0 ┘
+---------+
| Decoder |
+---------+
┌────┴────┬────┬────┐
Let’s say:
Switches = 10
The decoder "decodes" binary input into one-hot output to control the light.
module decoder_2to4 (
);
case (in)
endcase
end
endmodule
10. Summary
n-to-2ⁿ 2ⁿ
n-bit Address selection, control signals
Decoder lines
Final Insight:
Would you like a PDF of this complete note or want to continue with another digital logic block
like multiplexer, demultiplexer, comparator, or ALU unit in the same format?
Absolutely! Let's extend the same note on Decoder with a complete, easy-to-understand
section on instruction decoding — how it works, why a decoder is used, and an example that
makes it click clearly.
Here’s the additional section to append at the end of the Decoder notes:
11. How Instruction Decoding Works (with Decoder)
When a processor fetches an instruction from memory, the instruction is stored as a binary
opcode.
The decoder activates exactly one control signal out of many — corresponding to that
instruction.
This way, only the required logic circuit (e.g., ALU, memory unit, control logic) gets activated.
Opcode Instruction
000 NOP
001 ADD
010 SUB
011 LOAD
100 STORE
101 AND
110 OR
111 JUMP
Using Decoder
Only one line is HIGH at a time, triggering that instruction's execution logic.
Decoder Output:
Diagram:
For example:
Opcode = 010 (SUB) → Decoder activates SUB line → ALU performs subtraction
Because:
It transforms compact binary opcodes into 1-hot enable signals
Component Role
Final Analogy:
You say "item 3" → Waiter (decoder) brings only that item
This makes instruction decoding super e icient — and that's exactly where decoders shine in
real CPU architecture.
Would you like me to now combine this full note (including this new section) into a single PDF
for download or move on to the next digital block like Multiplexer?