Count Leading Sign Bits
Before normalising a signed number, a DSP needs to know how many copies of the sign bit sit at the top, since those are the bits it can shift away.
The solution module evaluates a 16 bit signed integer and counts the number of consecutive bits immediately following the most significant bit (MSB) that match the MSB. The count starts at bit 14 and proceeds downwards to bit 0. The search stops at the first bit that differs from the MSB. If all bits in the word match the MSB, the output reflects the maximum possible redundant bits.
This is a purely combinational circuit. There is no clock or reset. The output must update immediately and continuously based on the current input value.
| Signal | Direction | Width | Description |
|---|---|---|---|
in |
input | 16 | Signed input value |
count |
output | 4 | Purely combinational output representing the number of leading sign bits (0 to 15) |
Constraints
- The module must be purely combinational.
- The
countoutput must be exactly 4 bits wide to represent values from 0 to 15. - The MSB (
in[15]) is the reference sign bit and is not included in the count itself; the maximum count of matching bits is 15.
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 Datapath Design
Problem 26 of 27 in the Datapath Design track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks