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 EEE120 Lab 4: The Architect's Guide Electronics
Download Open
Show description 2,227 chars · Electronics

EEE120 Lab 4: The Architect's Guide

EEE120 Lab 4: The Architect's Guide












EEE120 Lab 4 Cheat Sheet

Mastering the Control ROM & Writing Test Programs










What does "Making a Test" mean?




You are building a programmable computer. To "test" it, you have to wear two different hats:







1. The Architect (ROM)
You teach the CPU how to do a task. You define the "AND" instruction by flipping bits in microprocessor.v (the ROM).









2. The Programmer (RAM)
You ask the CPU to perform that task. You write a list of numbers in ram_vals.txt that forces the CPU to run your new instruction.









// The Workflow

Step 1: Modify ROM (Define Instruction)

-> Set control bits for 'AND' at address 12 (0xC)

Step 2: Modify RAM (Write Program)

-> 0 // Load

-> 3 // Value 3

-> C // Run the 'AND' instruction

-> ...

Step 3: Simulate (iverilog)













The Control Word Decoder

When editing my_rom[x] = 14'h...., you are setting these bits. This is Table 3 from your manual, visualized.






Bit

Name

Function






13:12

Next Step

01=Go to Step 1, 00=Done (Fetch Next)




11:10

Unused

Always 00




9

use_pc

1=Next Instruction, 0=Use MAR (Data)




8

load_mar

1=Save Data Bus to Address Register




7

arith

1=Add/Sub, 0=Logic




6

invert

1=Invert Input A (for Subtract)




5

pass

1=Pass Data (No math), 0=Do Math




4

load_acc

1=Save result to Accumulator




3

acc_to_db

1=Put Accumulator on Data Bus




2

read

1=Read from RAM




1

write

1=Write to RAM




0

load_ir

1=Load New Instruction (Fetch)















Task 4-5 Solutions

Use these logic values to build your hex codes.




1. AND Instruction
ALU does "AND" when Arith=0, Pass=0.


Arith: 0
Invert: 0
Pass: 0







2. ZERO Instruction
Subtract Accum from itself. (A - A = 0)


Arith: 1
Invert: 1
Cin: 1 (via carry)







3. STORE Instruction
Needs 2 Steps! 1. Load address into MAR.2. Write Accum to RAM.












How to write 'ram_vals.txt'

Task 4-5 Check






To prove your new instructions work, you need to write a program that uses them.…

EEE120 Lab 4: The Architect's Guide

14,942 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>EEE120 Lab 4: The Architect's Guide</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&family=JetBrains+Mono:wght@400;700&display=swap');
        
        body {
            font-family: 'Inter', sans-serif;
            background-color: #0f172a;
            color: #e2e8f0;
        }
        .code-font {
            font-family: 'JetBrains Mono', monospace;
        }
        .card {
            background-color: #1e293b;
            border: 1px solid #334155;
            transition: transform 0.2s;
        }
        .card:hover {
            transform: translateY(-2px);
            border-color: #60a5fa;
        }
        .bit-box {
            width: 24px;
            height: 24px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 0.75rem;
            border-radius: 4px;
            margin-right: 2px;
        }
        .bit-1 { background-color: #22c55e; color: #000; font-weight: bold; }
        .bit-0 { background-color: #334155; color: #94a3b8; }
    </style>
</head>
<body class="min-h-screen p-6 md:p-12">

    <!-- Header -->
    <header class="max-w-6xl mx-auto mb-12 text-center">
        <div class="inline-block p-3 rounded-full bg-blue-600/20 text-blue-400 mb-4">
            <i class="fas fa-microchip text-2xl"></i>
        </div>
        <h1 class="text-4xl md:text-5xl font-bold text-white mb-4">EEE120 Lab 4 Cheat Sheet</h1>
        <p class="text-lg text-slate-400">Mastering the Control ROM & Writing Test Programs</p>
    </header>

    <!-- Main Grid -->
    <div class="max-w-6xl mx-auto grid grid-cols-1 lg:grid-cols-3 gap-8">

        <!-- Section 1: The Big Picture -->
        <div class="lg:col-span-3">
            <div class="card rounded-xl p-6">
                <h2 class="text-2xl font-bold text-white mb-4"><i class="fas fa-project-diagram mr-2 text-blue-400"></i>What does "Making a Test" mean?</h2>
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <p class="text-slate-300 mb-4 leading-relaxed">
                            You are building a programmable computer. To "test" it, you have to wear two different hats:
                        </p>
                        <ul class="space-y-4">
                            <li class="flex items-start">
                                <div class="bg-purple-500/20 p-2 rounded text-purple-400 mt-1 mr-3"><i class="fas fa-brain"></i></div>
                                <div>
                                    <strong class="text-purple-300">1. The Architect (ROM)</strong>
                                    <p class="text-sm text-slate-400">You teach the CPU <em>how</em> to do a task. You define the "AND" instruction by flipping bits in <span class="code-font bg-slate-800 px-1 rounded text-yellow-400">microprocessor.v</span> (the ROM).</p>
                                </div>
                            </li>
                            <li class="flex items-start">
                                <div class="bg-green-500/20 p-2 rounded text-green-400 mt-1 mr-3"><i class="fas fa-keyboard"></i></div>
                                <div>
                                    <strong class="text-green-300">2. The Programmer (RAM)</strong>
                                    <p class="text-sm text-slate-400">You ask the CPU to <em>perform</em> that task. You write a list of numbers in <span class="code-font bg-slate-800 px-1 rounded text-yellow-400">ram_vals.txt</span> that forces the CPU to run your new instruction.</p>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <div class="bg-slate-900 rounded-lg p-4 border border-slate-700 code-font text-sm">
                        <div class="text-slate-500">// The Workflow</div>
                        <div class="mt-2"><span class="text-purple-400">Step 1:</span> Modify ROM (Define Instruction)</div>
                        <div class="pl-4 text-slate-500">-> Set control bits for 'AND' at address 12 (0xC)</div>
                        <div class="mt-2"><span class="text-green-400">Step 2:</span> Modify RAM (Write Program)</div>
                        <div class="pl-4 text-slate-500">-> 0 // Load</div>
                        <div class="pl-4 text-slate-500">-> 3 // Value 3</div>
                        <div class="pl-4 text-slate-500">-> C // Run the 'AND' instruction</div>
                        <div class="pl-4 text-slate-500">-> ...</div>
                        <div class="mt-2"><span class="text-blue-400">Step 3:</span> Simulate (iverilog)</div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Section 2: The Bit Decoder -->
        <div class="lg:col-span-2">
            <div class="card rounded-xl p-6 h-full">
                <h3 class="text-xl font-bold text-white mb-4">The Control Word Decoder</h3>
                <p class="text-sm text-slate-400 mb-4">When editing <span class="code-font text-yellow-400">my_rom[x] = 14'h....</span>, you are setting these bits. This is Table 3 from your manual, visualized.</p>
                
                <div class="overflow-x-auto">
                    <table class="w-full text-left border-collapse">
                        <thead>
                            <tr class="text-slate-400 text-xs border-b border-slate-700">
                                <th class="p-2">Bit</th>
                                <th class="p-2">Name</th>
                                <th class="p-2">Function</th>
                            </tr>
                        </thead>
                        <tbody class="text-sm code-font">
                            <tr class="border-b border-slate-800 bg-slate-800/50">
                                <td class="p-2 text-blue-400">13:12</td>
                                <td>Next Step</td>
                                <td>01=Go to Step 1, 00=Done (Fetch Next)</td>
                            </tr>
                            <tr class="border-b border-slate-800">
                                <td class="p-2 text-slate-500">11:10</td>
                                <td>Unused</td>
                                <td>Always 00</td>
                            </tr>
                            <tr class="border-b border-slate-800">
                                <td class="p-2 text-purple-400">9</td>
                                <td>use_pc</td>
                                <td>1=Next Instruction, 0=Use MAR (Data)</td>
                            </tr>
                            <tr class="border-b border-slate-800">
                                <td class="p-2 text-purple-400">8</td>
                                <td>load_mar</td>
                                <td>1=Save Data Bus to Address Register</td>
                            </tr>
                            <tr class="border-b border-slate-800 bg-yellow-900/20">
                                <td class="p-2 text-yellow-400">7</td>
                                <td>arith</td>
                                <td>1=Add/Sub, 0=Logic</td>
                            </tr>
                            <tr class="border-b border-slate-800 bg-yellow-900/20">
                                <td class="p-2 text-yellow-400">6</td>
                                <td>invert</td>
                                <td>1=Invert Input A (for Subtract)</td>
                            </tr>
                            <tr class="border-b border-slate-800 bg-yellow-900/20">
                                <td class="p-2 text-yellow-400">5</td>
                                <td>pass</td>
                                <td>1=Pass Data (No math), 0=Do Math</td>
                            </tr>
                            <tr class="border-b border-slate-800">
                                <td class="p-2 text-green-400">4</td>
                                <td>load_acc</td>
                                <td>1=Save result to Accumulator</td>
                            </tr>
                            <tr class="border-b border-slate-800">
                                <td class="p-2 text-green-400">3</td>
                                <td>acc_to_db</td>
                                <td>1=Put Accumulator on Data Bus</td>
                            </tr>
                            <tr class="border-b border-slate-800">
                                <td class="p-2 text-red-400">2</td>
                                <td>read</td>
                                <td>1=Read from RAM</td>
                            </tr>
                            <tr class="border-b border-slate-800">
                                <td class="p-2 text-red-400">1</td>
                                <td>write</td>
                                <td>1=Write to RAM</td>
                            </tr>
                            <tr class="border-b border-slate-800">
                                <td class="p-2 text-blue-400">0</td>
                                <td>load_ir</td>
                                <td>1=Load New Instruction (Fetch)</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

        <!-- Section 3: Task 4-5 Solutions -->
        <div class="lg:col-span-1 space-y-4">
            <div class="card rounded-xl p-6 bg-gradient-to-b from-slate-800 to-slate-900">
                <h3 class="text-lg font-bold text-white mb-2">Task 4-5 Solutions</h3>
                <p class="text-xs text-slate-400 mb-4">Use these logic values to build your hex codes.</p>
                
                <!-- AND -->
                <div class="mb-4 border-b border-slate-700 pb-4">
                    <strong class="text-blue-400 block mb-1">1. AND Instruction</strong>
                    <p class="text-xs text-slate-300 mb-2">ALU does "AND" when Arith=0, Pass=0.</p>
                    <div class="flex gap-1 text-xs">
                        <span class="bg-slate-700 px-2 py-1 rounded">Arith: 0</span>
                        <span class="bg-slate-700 px-2 py-1 rounded">Invert: 0</span>
                        <span class="bg-slate-700 px-2 py-1 rounded">Pass: 0</span>
                    </div>
                </div>

                <!-- ZERO -->
                <div class="mb-4 border-b border-slate-700 pb-4">
                    <strong class="text-blue-400 block mb-1">2. ZERO Instruction</strong>
                    <p class="text-xs text-slate-300 mb-2">Subtract Accum from itself. (A - A = 0)</p>
                    <div class="flex gap-1 text-xs flex-wrap">
                        <span class="bg-slate-700 px-2 py-1 rounded">Arith: 1</span>
                        <span class="bg-slate-700 px-2 py-1 rounded">Invert: 1</span>
                        <span class="bg-slate-700 px-2 py-1 rounded">Cin: 1 (via carry)</span>
                    </div>
                </div>

                <!-- STORE -->
                <div>
                    <strong class="text-blue-400 block mb-1">3. STORE Instruction</strong>
                    <p class="text-xs text-slate-300 mb-2">Needs 2 Steps! <br>1. Load address into MAR.<br>2. Write Accum to RAM.</p>
                </div>
            </div>
        </div>

        <!-- Section 4: The Test Code Generator -->
        <div class="lg:col-span-3">
            <div class="card rounded-xl p-6 border-blue-500/30">
                <div class="flex justify-between items-center mb-4">
                    <h2 class="text-2xl font-bold text-white">How to write 'ram_vals.txt'</h2>
                    <span class="bg-blue-600 text-xs font-bold px-3 py-1 rounded-full">Task 4-5 Check</span>
                </div>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <p class="text-slate-300 mb-4">
                            To prove your new instructions work, you need to write a program that uses them. Copy/Paste this logic into your <span class="code-font">ram_vals.txt</span> file to test specific functions.
                        </p>
                        <div class="bg-slate-950 p-4 rounded-lg border border-slate-800">
                            <h4 class="text-white font-bold mb-2 border-b border-slate-800 pb-2">The "AND" Test Logic</h4>
                            <p class="text-sm text-slate-400 mb-2">If your AND instruction is at ROM index 12 (Hex C):</p>
                            <pre class="code-font text-sm text-green-400">
0  // Load ACC
3  // with value 3 (Binary 0011)
C  // AND Instruction
5  // with value 5 (Binary 0101)
2  // STOP</pre>
                            <div class="mt-2 text-xs text-slate-500">
                                Expected Result: 3 AND 5 = <strong class="text-white">1</strong> (Binary 0001)
                            </div>
                        </div>
                    </div>

                    <div>
                        <div class="bg-slate-950 p-4 rounded-lg border border-slate-800">
                            <h4 class="text-white font-bold mb-2 border-b border-slate-800 pb-2">The "STORE" Test Logic</h4>
                            <p class="text-sm text-slate-400 mb-2">Assume STORE is at ROM index ... (Let's say Hex E):</p>
                            <pre class="code-font text-sm text-green-400">
0  // Load ACC
F  // with value 15 (Binary 1111)
E  // STORE Instruction
8  // at RAM Address 8
0  // Load ACC (Overwrite it to prove we saved it)
0  // with value 0
1  // Add (Load from RAM)
8  // from Address 8
2  // STOP</pre>
                            <div class="mt-2 text-xs text-slate-500">
                                Expected Result: Accumulator should end up back at <strong class="text-white">15 (F)</strong>.
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>

    <footer class="max-w-6xl mx-auto mt-12 text-center text-slate-500 text-sm pb-12">
        <p>Generated for EEE120 | Lab 4 Companion</p>
    </footer>

</body>
</html>