Reduction AND and NAND
"Are all bits set?" shows up in terminal counts, full bitmasks and all-ready checks. A unary & answers it for any width without writing out an AND chain.
This module evaluates a parameterised input bus and asserts a flag when every bit in the bus is high. It also produces a complementary flag that is asserted when any bit in the bus is low. Both outputs must dynamically scale with the parameterised width without requiring code modifications.
This is a purely combinational circuit. Changes on the input must immediately reflect on the outputs without requiring a clock or reset.
Parameters
| Parameter | Default | Description |
|---|---|---|
WIDTH |
8 | The bit width of the input bus |
Ports
| Signal | Direction | Width | Description |
|---|---|---|---|
in |
input | WIDTH |
Parameterised input bus |
all_ones |
output | 1 | Asserted high when all bits of in are 1 |
not_all_ones |
output | 1 | Asserted high when at least one bit of in is 0 |
Constraints
- The design must be purely combinational with no latches or flip-flops
- The design must support any
WIDTHgreater than 1 - Do not use procedural loops to iterate through the bits
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of Verilog Syntax and Language Basics
Problem 10 of 25 in the Verilog Syntax and Language Basics track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks