Nested Concatenation and Replication
A packet header is a fixed-width word built from fields of different sizes, with zero padding where no field sits.
The module receives four distinct protocol fields and packs them into a single 32 bit output header. The fields must be concatenated in a specific order from the most significant bit to the least significant bit. Zero padding must be inserted between specific fields using replication operators.
The mapping of the 32 bit header is as follows:
- Bits [31:28]:
version - Bits [27:22]:
type_id - Bits [21:18]: 4 bits of zero padding
- Bits [17:15]:
flags - Bits [14:8]: 7 bits of zero padding
- Bits [7:0]:
payload_len
This is a purely combinational circuit. The output header must reflect the concatenated inputs continuously and immediately.
| Signal | Direction | Width | Description |
|---|---|---|---|
version |
input | 4 | Protocol version number |
type_id |
input | 6 | Packet type identifier |
flags |
input | 3 | Control flags |
payload_len |
input | 8 | Length of the payload in bytes |
header |
output | 32 | Formatted 32 bit packet header |
Constraints
- The output
headermust be driven by purely combinational logic. - The output must be exactly 32 bits wide.
- Unused bits in the padding regions must be strictly driven to 0.
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 20 of 25 in the Verilog Syntax and Language Basics track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks