牛客网Verilog刷题——VL19

牛客网Verilog刷题——VL19

题目

  在本题中,已经给出了下面74HC138译码器真值表对应的3-8译码器模块程序。需要例化该模块,实现逻辑函数:L=(~A)B+AC。
在这里插入图片描述

信号类型输入/输出位宽
AwireIntput1
BwireIntput1
CwireIntput1
LwireOutput1

  在写Verilog代码前,根据需要实现的函数:L=(~A)B+AC。我们可以知道其真值表如下。

ABCL
0000
0010
0101
0111
1000
1011
1100
1111

  根据上述真值表,可以知道,当ABC为010、011、101、111时,输出L为1,所以L = Y2_n + Y3_n + Y5_n + Y7_n,这里“+”号表示或操作,在数电中,我们学过,或门可以用与非门进行替换,即L = ~(Y2_n & Y3_n & Y5_n & Y7_n)。

答案

`timescale 1ns/1ns

module lca_4(
	input		[3:0]       A_in  ,
	input	    [3:0]		B_in  ,
    input                   C_1   ,
 
 	output	 wire			CO    ,
	output   wire [3:0]	    S
);

wire [3:0]	G;
wire [3:0]	P;
wire [3:0]	C;

assign 	G = A_in & B_in;
assign	P = A_in ^ B_in;
assign  C[0] = G[0] | P[0] & C_1;
assign  C[1] = G[1] | P[1] & C[0];
assign  C[2] = G[2] | P[2] & C[1];
assign  C[3] = G[3] | P[3] & C[2];
assign	CO = C[3];

assign	S[0] = P[0] ^ C_1;
assign	S[1] = P[1] ^ C[0];
assign	S[2] = P[2] ^ C[1];
assign	S[3] = P[3] ^ C[2];

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值