Consider the following combinatorial Gray-to-Binary decoding implementati…
Consider the following combinatorial Gray-to-Binary decoding implementation for an N -bit bus: parameter WIDTH = 4; reg [WIDTH-1:0] bin; reg [WIDTH-1:0] gray; integer i; always @(*) begin bin[WIDTH-1] = gray[WIDTH-1]; for (i = WIDTH-2; i >= 0; i = i - 1) begin bin[i] = bin[i+1] ^ gray[i]; end end Suppose gray changes from 4'b0010 to 4'b0110 at t = 10 ns . What is the final settled value of bin , and what is the maximum number of cascaded XOR logic levels in the critical path for a generic WIDTH ?
- bin = 4'b0100 , critical path = $\lceil \log_2(WIDTH) \rceil$ XOR levels
- bin = 4'b0100 , critical path = $WIDTH - 1$ XOR levels
- bin = 4'b0101 , critical path = $WIDTH - 1$ XOR levels
- bin = 4'b0101 , critical path = $2 \times (WIDTH - 1)$ XOR levels
Correct answer
B. bin = 4'b0100 , critical path = $WIDTH - 1$ XOR levels
Explanation
1. **Value Calculation:** Given gray = 4'b0110 : * bin[3] = gray[3] = 0 * bin[2] = bin[3] ^ gray[2] = 0 ^ 1 = 1 * bin[1] = bin[2] ^ gray[1] = 1 ^ 1 = 0 * bin[0] = bin[1] ^ gray[0] = 0 ^ 0 = 0 Therefore, bin = 4'b0100 (decimal 4). In standard binary: 4 is 0100 , whose Gray code is 0100 ^ 0010 = 0110 , which matches. 2. **Logic Depth:** Because each bit bin[i] strictly depends on bin[i+1] , synthesis builds a linear ripple-carry chain of XOR gates from MSB to LSB. For an $N$-bit bus, bit $N-1$ requires 0 XOR gates, bit $N-2$ requires 1 XOR, down to bit $0$ which requires $N-1$ XOR gates in series. Hence, the critical path is $WIDTH - 1$ XOR levels.