Explore + Share Site

Simple Sudoku Solvers SIII, EIII: Verilog

“I think this was the strangest episode so far, for me. I don’t mean that in a bad way.”

Jump to Highlight ↗
📖 Curated Deep Read Preview 336 words · ~2 min read

Welcome back to another round of Simple Sudoku Solvers! If you are unfamiliar with the series, I suggest you start with the first post or by perusing the backlog. Last time, in assembly, we told the CPU exactly what to do, one instruction at a time. Today we go one level lower and build the machine directly in Verilog.

Verilog is a hardware description language. You don’t write a program that will at some point run on hardware. Instead, you describe a circuit, and the compiler turns that description into gates and flip-flops. We’ll run it in a simulator, because I don’t have a Sudoku chip lying around (future work), but the solver is real hardware in the sense that a synthesis tool accepts it and tells us how many gates it would take. Still counts, even with sim2real TBD.

The solver is about 145 lines, plus 40 lines of ceremony to feed it a puzzle and print the result. You can run it with iverilog -o sudoku sudoku.v && vvp sudoku, using Icarus Verilog. I didn’t test it anywhere else. As always, the code is on GitHub.

Season three is about solvers, specifications, and constraints, and somehow also about hardware and the lowest of low levels. That’s because hardware is possibly the purest version of a specification (and, to be quite honest, because I felt like it).

If you’ve never read Verilog before, here is what you need for this post.

A module is a circuit with inputs and outputs. wire [8:0] x is a bundle of nine wires, numbered 8 down to 0. reg is a bit of a misnomer: it’s a value we assign in a procedural block, and whether it becomes an actual register is actually dependent on our usage of it.

There are two kinds of blocks we care about. always @* describes combinational logic. Its outputs are a pure function of its inputs, and they change whenever the inputs do. Think of it as a very big expression.

Continue reading the full piece on blog.veitheller.de ↗
Quick Use-Case Tags (tap to vote)
Visit Website ↗

📝 Your Private Notes & Highlights 🔒 Only visible to you

Log in or create a free account to keep private highlights and personal notes on your stored picks.

Creator Trophy & Press Kit

Featured on Storesso

Are you the creator of blog.veitheller.de? Share your verified feature badge on your website, or export a custom 4:5 editorial social card for Instagram and X.

Verified Website Badge
Featured on Storesso
Claim Resource →
4:5 Social Studio

Generate a 1080×1350 vertical high-res feature card tailored for social sharing.

Instagram & X Feature Card

Export a polished, high-resolution 4:5 editorial graphic displaying your verified inclusion in the Storesso Discovery Index. Perfect for launch threads, founder updates, and newsletters.

Rendered at 1080×1350px (Retina ready) · No attribution watermark required.

Curated in These Public Collections

Discussion 0
🛡️ Safe comments: Text, Emojis & Reaction GIFs only (links & media URLs blocked)
✨ Author / Creator Quick-Reply No password required · Or Sign In