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

Parameterized ALU with Safe Defaults

MediumVerilog / SystemVerilogBuild

Arithmetic Logic Units form the execution core of any processor. When an instruction decoder issues an undefined opcode, the ALU must fail safely without inferring unintended state-holding elements. Undefined states in combinational blocks often synthesize into latches, which can destroy timing closure and waste area.

This purely combinational module computes an arithmetic or logical operation based on a 3-bit opcode. The data path width is configurable via a parameter W. If the provided opcode does not match a defined operation, the module must output zero to ensure deterministic behaviour.

| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | a | input | W | First operand | | b | input | W | Second operand | | opcode | input | 3 | Operation selector | | out | output | W | Computation result |

The module must support the following operations: • 3'b000: Addition (a + b) • 3'b001: Subtraction (a - b) • 3'b010: Bitwise AND (a & b) • 3'b011: Bitwise OR (a | b) • 3'b100: Bitwise XOR (a ^ b) • Any other value: Output zero

Constraints

  • The module is purely combinational; there is no clock or reset.
  • The design must strictly evaluate all 8 possible opcode combinations without inferring latches.
  • The parameter W must default to 8.
  • Arithmetic operations must silently wrap on overflow or underflow.

Topics

combinationalalulatchessystemverilog

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

  • Binary to Gray Code DatapathEasy
  • 16-bit Arithmetic Barrel ShifterHard
  • Twos Complement Overflow in SubtractionMedium
  • 8-bit Combinational PopcountMedium
  • 8-bit Logical Barrel ShifterMedium
  • Absolute Value with Bit GrowthMedium
  • 8 bit Basic ALU with FlagsEasy
  • Fixed Point Multiplication with SaturationHard

Browse all problems · Learning tracks