even longer vectors

See also the shorter version: Gates and vectors.

You are given a 100-bit input vector in[99:0]. We want to know some relationships between each bit and its neighbour:

out_both: Each bit of this output vector should indicate whether both the corresponding input bit and its neighbour to the left are '1'. For example, out_both[98] should indicate if in[98] and in[99] are both 1. Since in[99] has no neighbour to the left, the answer is obvious so we don't need to know out_both[99].
out_any: Each bit of this output vector should indicate whether any of the corresponding input bit and its neighbour to the right are '1'. For example, out_any[2] should indicate if either in[2] or in[1] are 1. Since in[0] has no neighbour to the right, the answer is obvious so we don't need to know out_any[0].
out_different: Each bit of this output vector should indicate whether the corresponding input bit is different from its neighbour to the left. For example, out_different[98] should indicate if in[98] is different from in[99]. For this part, treat the vector as wrapping around, so in[99]'s neighbour to the left is in[0].

Gatesv100 - HDLBits (01xz.net)

(29条消息) HDLBits答案汇总_日拱一卒_未来可期的博客-CSDN博客

 1 module top_module( 
 2     input [99:0] in,
 3     output [98:0] out_both,
 4     output [99:1] out_any,
 5     output [99:0] out_different );
 6 
 7     integer i;
 8     
 9     always @(*) begin
10         for(i=0;i<99;i++) begin
11             out_both[i] = in[i] & in[i+1];
12             out_any[i+1] = in[i+1] | in[i];
13             out_different[i] = in[i] ^ in[i+1];
14         end
15         out_different[99] = in[0] ^ in[99];
16     end
17 
18 endmodule

 

posted @ 2023-04-21 13:52  江左子固  阅读(21)  评论(0)    收藏  举报