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

Signed Port Declarations

MediumVerilog / SystemVerilogBuild

Digital signal processing pipelines frequently pass signed data between arithmetic blocks. When crossing module boundaries, Verilog requires explicit sign declarations on ports. If an input port carrying negative values is declared without the signed keyword, the compiler silently treats the data as unsigned, causing operations like arithmetic right shifts to pad with zeros instead of sign-extending.

This module computes an arithmetic right shift on an 8-bit signed input. The input value a is shifted right by a specified 3-bit amount shamt. Because the input represents a signed two's complement integer, the shift operation must duplicate the sign bit (the most significant bit) into the newly vacated upper bits to preserve the negative value.

This circuit is purely combinational. There is no clock or reset. The output y must update immediately whenever a or shamt changes.

Example Evaluation Trace: • Input: a = 8'b10011100 (-100), shamt = 2 → Output: y = 8'b11100111 (-25) • Input: a = 8'b01111111 (127), shamt = 3 → Output: y = 8'b00001111 (15)

| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | a | input | 8 | Signed data input | | shamt | input | 3 | Unsigned shift amount | | y | output | 8 | Signed data output |

Constraints

  • The module must be purely combinational.
  • The a and y ports must explicitly use the signed keyword in their declarations.
  • The arithmetic right shift must be implemented using the >>> operator.
  • Negative values on a must retain their sign bit during the shift.

Topics

combinationalarithmeticsyntax

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