CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Combinational Logic

Packet Header Formatter

EasyVerilog / SystemVerilogBuild

Network packet headers require strict adherence to protocol specifications. While certain fields carry dynamic payload information, reserved fields and synchronization words must be tied to fixed constant values to ensure the receiver can properly frame the incoming data stream.

The solution module constructs a 32-bit packet header combinationally. The header format is assembled from dynamic input ports and fixed constants. The upper byte is a synchronization word that changes based on the operating mode. The middle sections contain the device identifier and payload length, separated by reserved zero-padded bits. The lower byte contains a hardcoded protocol version and a terminating reserved sequence.

| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | mode | input | 1 | Operating mode flag. | | device_id | input | 5 | Unique identifier for the transmitting device. | | payload_len | input | 8 | Length of the data payload in bytes. | | header_word | output | 32 | Formatted 32-bit header. |

The 32-bit header_word is constructed using the following exact bit mapping:

  • header_word[31:24]: Synchronization byte. Tied to 8'hAA when mode is 1; tied to 8'h55 when mode is 0.
  • header_word[23:19]: Assigned directly to the device_id input.
  • header_word[18:16]: Reserved field. Tied to the constant 3'b000.
  • header_word[15:8]: Assigned directly to the payload_len input.
  • header_word[7:4]: Protocol version field. Tied to the constant 4'b0100 (Version 4).
  • header_word[3:0]: Terminator field. Tied to the constant 4'b1111.

Constraints

  • The header_word output must be driven purely combinationally; there is no clock or reset in this circuit.
  • All reserved and fixed fields must match the exact bit widths and binary values specified.
  • The mode input only affects the upper 8 bits; all other constants remain fixed regardless of the operating mode.

Topics

Combinational LogicData FormattingConstantsConcatenation

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

Sign in to solveSee what Pro unlocks

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.

Related problems

  • Single Continuous AssignmentEasy
  • Basic Vector ConcatenationEasy
  • Ternary Operator MuxEasy
  • Underscores for ReadabilityEasy
  • Left Hand Side ConcatenationEasy
  • Inout Port MechanicsEasy
  • Explicit Binary LiteralsEasy
  • Vector Port EndiannessEasy

Browse all problems · Learning tracks