Guide for implementing combinational/sequential logic circuits using gate-level descriptions in text-based simulators. This skill applies when building circuits for mathematical functions like integer square root, Fibonacci sequences, or similar computations that require both combinational logic (arithmetic operations) and sequential logic (feedback loops, state machines). Use this skill when the task involves generating gate netlists, implementing multi-bit arithmetic circuits, or debugging event-driven circuit simulators.
This skill provides guidance for implementing mathematical computations as gate-level circuits. It covers combinational logic (adders, comparators, multiplexers) and sequential logic (feedback-based iteration) in text-based circuit simulators that use event-driven simulation.
Use this skill when:
gates.txt format)Before writing any circuit code:
- Examine any provided example gate files to understand:
out{i} = out{i} pattern for preserving inputs)Establish conventions - Document clearly:
mux(sel, a, b) select a when sel=0 or sel=1?Test simulator behavior - Create minimal test circuits to verify:
Before implementing complex algorithms:
Before implementation:
Implement in isolation before combining:
Primitive gates first:
Arithmetic building blocks:
Test each component:
For isqrt (integer square root):
For Fibonacci:
When combining components:
Mistake: Not preserving input signals in the gate file.
Solution: Many simulators require explicit input preservation:
out0 = out0 # Preserve input bit 0
out1 = out1 # Preserve input bit 1
...
Read example files to identify this pattern before implementation.
Mistake: Implementing formulas without verification.
Example: Using test_val = 2*res + 1 when the correct formula is different for the chosen iteration method.
Solution: Paper-trace the algorithm with concrete values before coding.
Mistake: Using multiplication without estimating gate cost.
Example: A 32x32 multiplier can require 30,000+ gates, exceeding typical limits.
Solution:
Mistake: Getting fib(k-1) instead of fib(k) due to iteration count errors.
Solution:
Mistake: Misunderstanding how feedback stabilizes in event-driven simulation.
Example: A toggle test showing 0 after even iterations is correct, not broken.
Solution:
Mistake: Confusing which input is selected when selector is 0 vs 1.
Solution: