HDLBits-Gatesv

You are given a four-bit input vector in[3:0]. We want to know some relationships between each bit and its neighbour:
给你一个4位的输入向量[3:0]。我们想知道每个比特和它的邻居之间的关系
out_both: Each bit of this output vector should indicate whether both the corresponding input bit and its neighbour to the left (higher index) are ‘1’. For example, out_both[2] should indicate if in[2] and in[3] are both 1. Since in[3] has no neighbour to the left, the answer is obvious so we don’t need to know out_both[3].
out_both:这个输出向量的每一位都应该表明对应的输入位和它左边的邻居(更高的下标)是否都是“1”。例如,out_both[2]应该表示[2]和[3]中是否都是1。因为在[3]中左边没有邻居,所以答案很明显,所以我们不需要知道out_both[3]。
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_any:这个输出向量的每一位都应该表明是否有任何对应的输入位和它右边的邻居是“1”。例如,out_any[2]应该指示[2]或[1]中的任何一个为1。因为在[0]中右边没有邻居,所以答案很明显,所以我们不需要知道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[2] should indicate if in[2] is different from in[3]. For this part, treat the vector as wrapping around, so in[3]'s neighbour to the left is in[0].
out_different:这个输出向量的每一位都应该表明对应的输入位与它左边的邻居是否不同。例如,out_different[2]应该表示[2]中的内容与[3]中的内容是否不同。对于这一部分,将向量视为环绕,因此[3]中左边的邻居在[0]中

module top_module(
input [3:0] in,
output [2:0] out_both,
output [3:1] out_any,
output [3:0] out_different );
integer i;
always@(in)
begin
for(i=0;i<3;i++)
begin
out_both[i] = (in[i+1] ==1 & in[i] ==1)?1:0;
end
for(i=1;i<4;i++)
begin
out_any[i] = (in[i-1] ==1 | in[i] ==1)?1:0;
end
for(i=0;i<4;i++)
begin
if(i == 3)
out_different[3] = (in[3] == in[0])?0:1;
else
out_different[i] = (in[i+1] == in[i])?0:1;
end
end
endmodule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值