Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ255
Q255DVASIC interview problem

Constrain exactly five changed bit positions

TechniquesDVSystemVerilogConstraintsHamming distanceXOR
DifficultyEasy
TopicConstrained Random
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

Two randomized bytes must differ in exactly five bit locations. Write the single constraint that expresses that Hamming-distance relation.

Class declarationSystemVerilog
class distance_pair;
  rand bit [7:0] a;
  rand bit [7:0] b;
endclass

Example input and output

Use this case to check your interpretation
Input
a=8'h00, b=8'h1F
Output
legal: $countones(a ^ b) = 5
Explanation

a XOR b equals 8'b0001_1111, which contains exactly five set bits.

02

Requirements (4)

  • Count differing positions rather than counting ones in each operand independently.
  • Require exactly five differing bits.
  • Allow every pair that satisfies the relation.
  • Check whether randomize() succeeds.