Codiode

Parameterized Vector Slicing

HardVerilog / SystemVerilogBuild6 solved

Packet parsers pull a field out of a wide word at an offset that is only known at run time. Fixed slices like data[15:8] can't do that.

The module receives a 32-bit data word and a dynamically changing 5-bit offset. It evaluates the inputs combinationally and extracts an 8-bit slice starting exactly at the specified bit offset.

This is a purely combinational circuit. There are no clock or reset signals. The output updates immediately when any input changes.

Signal Direction Width Description
data_in input 32 The full data word to be sliced
offset input 5 The starting bit index for the extraction
data_out output 8 The extracted 8-bit slice starting at offset

Constraints

  • The circuit must be purely combinational.
  • The offset input is guaranteed to be in the range 0 to 24; you do not need to handle out-of-bounds indices.
  • You must dynamically slice the input vector based on the variable offset.

Topics

Combinational LogicData RoutingVerilog Syntax

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 7 of 25 in the Verilog Syntax and Language Basics track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.