Skip to content
LAM
Read Home Blog
Make Projects HTML Tools Games
Touch grass Notes Resume Links
Home Blog HTML Projects
Tools Games Notes Resume Links
Back Simple Block Diagram - Add/Sub Circuit Electronics
Download Open
Show description 2,111 chars · Electronics

Simple Block Diagram - Add/Sub Circuit

Simple Block Diagram - Add/Sub Circuit




SIMPLIFIED BLOCK DIAGRAM

4-Bit Add/Sub with Automatic 2's Complement





CIRCUIT ARCHITECTURE


A[3:0]
B[3:0]
SA
SB



STAGE 1
XOR GATES
A' = A XOR SA
B' = B XOR SB
Cin = SA OR SB
(Conditional
Inversion)
















STAGE 2
4-BIT ADDER
Sum1 = A' + B'
+ Cin
(Main Addition
with +1 for
single 2's comp)




A', B', Cin



STAGE 3
4-BIT ADDER
Final = Sum1
+ 0 + (SA∧SB)
(Adds +1 only
when both SA
and SB are 1)




Sum1




SA AND SB


Result[3:0]




Inverts bits when
SA or SB = 1

Adds +1 when
SA OR SB = 1

Adds +1 when
SA AND SB = 1










HOW IT WORKS - SIMPLE EXPLANATION



🔹 STAGE 1: Prepare the numbers

XOR gates either pass the number through (when control = 0) or invert all bits (when control = 1)

This is the FIRST STEP of 2's complement: invert the bits





🔹 STAGE 2: Add with +1 if needed

The first adder adds the two prepared numbers

The carry input is set to 1 when either SA or SB is 1

This is the SECOND STEP of 2's complement: add 1

This works perfectly for scenarios 1, 2, and 3!





🔹 STAGE 3: Fix scenario 4

When BOTH SA and SB are 1, we need TWO 2's complements

Stage 2 only added +1, so we're SHORT by 1

The second adder adds that missing +1 only when (SA AND SB) = 1

For other scenarios, it just passes the result through (adds +0)





KEY INSIGHT: Second Adder = Result + 0000 + (SA AND SB)
• When SA AND SB = 0: adds nothing (pass through)
• When SA AND SB = 1: adds +1 (fixes scenario 4)






OPERATION TRUTH TABLE



SA

SB

Operation

Stage 1 Output

Stage 2 Output

Stage 3 Adds

Final Result




0

0

X + Y

A, B

A + B + 0

+0

X + Y ✓




0

1

X - Y

A, NOT B

A + (NOT B) + 1

+0

X - Y ✓




1

0

-X + Y

NOT A, B

(NOT A) + B + 1

+0

-X + Y ✓




1

1

-X - Y

NOT A, NOT B

(NOT A) + (NOT B) + 1

+1

-X - Y ✓








WHY THIS IS BETTER THAN A MUX

A multiplexer (MUX) is like a switch that selects between two inputs.…

Simple Block Diagram - Add/Sub Circuit

13,820 bytes · HTML source
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple Block Diagram - Add/Sub Circuit</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Courier New', monospace;
            background: #1a1a1a;
            color: #00ff00;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        h1 {
            text-align: center;
            margin-bottom: 10px;
            color: #00ff00;
            text-shadow: 0 0 10px #00ff00;
        }

        .subtitle {
            text-align: center;
            margin-bottom: 30px;
            color: #00aa00;
            font-size: 14px;
        }

        .diagram {
            background: #2a2a2a;
            border: 2px solid #00ff00;
            border-radius: 10px;
            padding: 40px;
            margin-bottom: 30px;
        }

        svg {
            width: 100%;
            height: auto;
            background: #1a1a1a;
            border-radius: 5px;
        }

        .block {
            fill: #2a2a2a;
            stroke: #00ffff;
            stroke-width: 3;
        }

        .block-text {
            fill: #00ffff;
            font-size: 18px;
            font-weight: bold;
            text-anchor: middle;
        }

        .small-text {
            fill: #00aa00;
            font-size: 14px;
            text-anchor: middle;
        }

        .wire {
            fill: none;
            stroke: #00ff00;
            stroke-width: 3;
        }

        .arrow {
            fill: #00ff00;
        }

        .label {
            fill: #ffff00;
            font-size: 16px;
            font-weight: bold;
        }

        .explanation {
            background: #2a2a2a;
            border: 2px solid #00ff00;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
        }

        .explanation h2 {
            color: #00ffff;
            margin-bottom: 15px;
        }

        .explanation p {
            color: #00ff00;
            line-height: 1.6;
            margin-bottom: 10px;
        }

        .operation-table {
            background: #2a2a2a;
            border: 2px solid #ffff00;
            border-radius: 10px;
            padding: 20px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 15px;
        }

        th, td {
            padding: 12px;
            text-align: center;
            border: 1px solid #00aa00;
        }

        th {
            background: #0a0a0a;
            color: #ffff00;
            font-weight: bold;
        }

        td {
            background: #1a1a1a;
            color: #00ff00;
        }

        .stage-box {
            background: #0a0a0a;
            border: 2px solid #00ffff;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
        }

        .stage-box h3 {
            color: #00ffff;
            margin-bottom: 10px;
        }

        .stage-box p {
            color: #00aa00;
            line-height: 1.5;
        }

        .formula {
            background: #0a0a0a;
            border-left: 4px solid #ff00ff;
            padding: 10px;
            margin: 10px 0;
            color: #ff00ff;
            font-family: monospace;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>SIMPLIFIED BLOCK DIAGRAM</h1>
        <div class="subtitle">4-Bit Add/Sub with Automatic 2's Complement</div>

        <div class="diagram">
            <svg viewBox="0 0 1100 600" preserveAspectRatio="xMidYMid meet">
                <!-- Title -->
                <text x="550" y="30" class="label" style="font-size: 22px; text-anchor: middle;">CIRCUIT ARCHITECTURE</text>
                
                <!-- Inputs -->
                <text x="80" y="150" class="label">A[3:0]</text>
                <text x="80" y="250" class="label">B[3:0]</text>
                <text x="80" y="350" class="label">SA</text>
                <text x="80" y="400" class="label">SB</text>
                
                <!-- Stage 1: XOR Block -->
                <rect x="200" y="120" width="180" height="250" class="block" rx="10"/>
                <text x="290" y="180" class="block-text">STAGE 1</text>
                <text x="290" y="205" class="small-text">XOR GATES</text>
                <text x="290" y="240" class="small-text" style="fill: #00ff00;">A' = A XOR SA</text>
                <text x="290" y="265" class="small-text" style="fill: #00ff00;">B' = B XOR SB</text>
                <text x="290" y="300" class="small-text" style="fill: #00ff00;">Cin = SA OR SB</text>
                <text x="290" y="340" class="small-text">(Conditional</text>
                <text x="290" y="360" class="small-text">Inversion)</text>
                
                <!-- Arrows from inputs to Stage 1 -->
                <line x1="120" y1="145" x2="200" y2="145" class="wire"/>
                <polygon points="200,145 190,140 190,150" class="arrow"/>
                
                <line x1="120" y1="245" x2="200" y2="245" class="wire"/>
                <polygon points="200,245 190,240 190,250" class="arrow"/>
                
                <line x1="120" y1="345" x2="200" y2="300" class="wire"/>
                <polygon points="200,300 193,295 188,305" class="arrow"/>
                
                <line x1="120" y1="395" x2="200" y2="330" class="wire"/>
                <polygon points="200,330 193,325 188,335" class="arrow"/>
                
                <!-- Stage 2: First Adder -->
                <rect x="480" y="120" width="180" height="250" class="block" rx="10"/>
                <text x="570" y="180" class="block-text">STAGE 2</text>
                <text x="570" y="205" class="small-text">4-BIT ADDER</text>
                <text x="570" y="240" class="small-text" style="fill: #00ff00;">Sum1 = A' + B'</text>
                <text x="570" y="265" class="small-text" style="fill: #00ff00;">+ Cin</text>
                <text x="570" y="310" class="small-text">(Main Addition</text>
                <text x="570" y="330" class="small-text">with +1 for</text>
                <text x="570" y="350" class="small-text">single 2's comp)</text>
                
                <!-- Arrow from Stage 1 to Stage 2 -->
                <line x1="380" y1="245" x2="480" y2="245" class="wire"/>
                <polygon points="480,245 470,240 470,250" class="arrow"/>
                <text x="430" y="235" class="small-text">A', B', Cin</text>
                
                <!-- Stage 3: Second Adder -->
                <rect x="760" y="120" width="180" height="250" class="block" rx="10"/>
                <text x="850" y="180" class="block-text">STAGE 3</text>
                <text x="850" y="205" class="small-text">4-BIT ADDER</text>
                <text x="850" y="240" class="small-text" style="fill: #00ff00;">Final = Sum1</text>
                <text x="850" y="265" class="small-text" style="fill: #00ff00;">+ 0 + (SA∧SB)</text>
                <text x="850" y="310" class="small-text">(Adds +1 only</text>
                <text x="850" y="330" class="small-text">when both SA</text>
                <text x="850" y="350" class="small-text">and SB are 1)</text>
                
                <!-- Arrow from Stage 2 to Stage 3 -->
                <line x1="660" y1="245" x2="760" y2="245" class="wire"/>
                <polygon points="760,245 750,240 750,250" class="arrow"/>
                <text x="710" y="235" class="small-text">Sum1</text>
                
                <!-- SA AND SB line to Stage 3 -->
                <line x1="120" y1="370" x2="700" y2="370" class="wire" stroke-dasharray="5,5"/>
                <line x1="700" y1="370" x2="760" y2="310" class="wire" stroke-dasharray="5,5"/>
                <text x="400" y="390" class="small-text" style="fill: #ffaa00;">SA AND SB</text>
                
                <!-- Output -->
                <text x="990" y="250" class="label">Result[3:0]</text>
                <line x1="940" y1="245" x2="980" y2="245" class="wire"/>
                <polygon points="980,245 970,240 970,250" class="arrow"/>
                
                <!-- Bottom labels -->
                <text x="290" y="450" class="small-text" style="fill: #ffff00;">Inverts bits when</text>
                <text x="290" y="470" class="small-text" style="fill: #ffff00;">SA or SB = 1</text>
                
                <text x="570" y="450" class="small-text" style="fill: #ffff00;">Adds +1 when</text>
                <text x="570" y="470" class="small-text" style="fill: #ffff00;">SA OR SB = 1</text>
                
                <text x="850" y="450" class="small-text" style="fill: #ffff00;">Adds +1 when</text>
                <text x="850" y="470" class="small-text" style="fill: #ffff00;">SA AND SB = 1</text>
                
                <!-- Connection lines to bottom labels -->
                <line x1="290" y1="370" x2="290" y2="440" class="wire" stroke-width="2" stroke-dasharray="3,3"/>
                <line x1="570" y1="370" x2="570" y2="440" class="wire" stroke-width="2" stroke-dasharray="3,3"/>
                <line x1="850" y1="370" x2="850" y2="440" class="wire" stroke-width="2" stroke-dasharray="3,3"/>
            </svg>
        </div>

        <div class="explanation">
            <h2>HOW IT WORKS - SIMPLE EXPLANATION</h2>
            
            <div class="stage-box">
                <h3>🔹 STAGE 1: Prepare the numbers</h3>
                <p>XOR gates either pass the number through (when control = 0) or invert all bits (when control = 1)</p>
                <p>This is the FIRST STEP of 2's complement: invert the bits</p>
            </div>

            <div class="stage-box">
                <h3>🔹 STAGE 2: Add with +1 if needed</h3>
                <p>The first adder adds the two prepared numbers</p>
                <p>The carry input is set to 1 when either SA or SB is 1</p>
                <p>This is the SECOND STEP of 2's complement: add 1</p>
                <p>This works perfectly for scenarios 1, 2, and 3!</p>
            </div>

            <div class="stage-box">
                <h3>🔹 STAGE 3: Fix scenario 4</h3>
                <p>When BOTH SA and SB are 1, we need TWO 2's complements</p>
                <p>Stage 2 only added +1, so we're SHORT by 1</p>
                <p>The second adder adds that missing +1 only when (SA AND SB) = 1</p>
                <p>For other scenarios, it just passes the result through (adds +0)</p>
            </div>

            <div class="formula">
                KEY INSIGHT: Second Adder = Result + 0000 + (SA AND SB)
                <br>• When SA AND SB = 0: adds nothing (pass through)
                <br>• When SA AND SB = 1: adds +1 (fixes scenario 4)
            </div>
        </div>

        <div class="operation-table">
            <h2 style="color: #ffff00; text-align: center;">OPERATION TRUTH TABLE</h2>
            <table>
                <tr>
                    <th>SA</th>
                    <th>SB</th>
                    <th>Operation</th>
                    <th>Stage 1 Output</th>
                    <th>Stage 2 Output</th>
                    <th>Stage 3 Adds</th>
                    <th>Final Result</th>
                </tr>
                <tr>
                    <td>0</td>
                    <td>0</td>
                    <td>X + Y</td>
                    <td>A, B</td>
                    <td>A + B + 0</td>
                    <td>+0</td>
                    <td>X + Y ✓</td>
                </tr>
                <tr>
                    <td>0</td>
                    <td>1</td>
                    <td>X - Y</td>
                    <td>A, NOT B</td>
                    <td>A + (NOT B) + 1</td>
                    <td>+0</td>
                    <td>X - Y ✓</td>
                </tr>
                <tr>
                    <td>1</td>
                    <td>0</td>
                    <td>-X + Y</td>
                    <td>NOT A, B</td>
                    <td>(NOT A) + B + 1</td>
                    <td>+0</td>
                    <td>-X + Y ✓</td>
                </tr>
                <tr>
                    <td>1</td>
                    <td>1</td>
                    <td>-X - Y</td>
                    <td>NOT A, NOT B</td>
                    <td>(NOT A) + (NOT B) + 1</td>
                    <td>+1</td>
                    <td>-X - Y ✓</td>
                </tr>
            </table>
        </div>

        <div class="explanation">
            <h2>WHY THIS IS BETTER THAN A MUX</h2>
            <p>A multiplexer (MUX) is like a switch that selects between two inputs. You haven't learned about it yet, so we use what you already know: <strong>adders</strong>!</p>
            <p>By feeding 0000 to one input of the second adder, we effectively get:</p>
            <div class="formula">
                Second Adder Output = First Input + 0 + Carry In
            </div>
            <p>This is just adding 0 or 1 based on the carry in, which is exactly what we need.</p>
            <p><strong>Same result, simpler components!</strong></p>
        </div>
    </div>
</body>
</html>