用3-8译码器实现全减器
描述
请使用3-8译码器和必要的逻辑门实现全减器,全减器接口图如下,A是被减数,B是减数,Ci是来自低位的借位,D是差,Co是向高位的借位。
3-8译码器代码如下,可将参考代码添加并例化到本题答案中。
module decoder_38(
input E ,
input A0 ,
input A1 ,
input A2 ,
output reg Y0n ,
output reg Y1n ,
output reg Y2n ,
output reg Y3n ,
output reg Y4n ,
output reg Y5n ,
output reg Y6n ,
output reg Y7n
);
always @(*)begin
if(!E)begin
Y0n = 1'b1;
Y1n = 1'b1;
Y2n = 1'b1;
Y3n = 1'b1;
Y4n = 1'b1;
Y5n = 1'b1;
Y6n = 1'b1;
Y7n = 1'b1;
end
else begin
case({A2,A1,A0})
3'b000 : begin
Y0n = 1'b0; Y1n = 1'b1; Y2n = 1'b1; Y3n = 1'b1;
Y4n = 1'b1; Y5n = 1'b1; Y6n = 1'b1; Y7n = 1'b1;
end
3'b001 : begin
Y0n = 1'b1; Y1n = 1'b0; Y2n = 1'b1; Y3n = 1'b1;
Y4n = 1'b1; Y5n = 1'b1; Y6n = 1'b1; Y7n = 1'b1;
end
3'b010 : begin
Y0n = 1'b1; Y1n = 1'b1; Y2n = 1'b0; Y3n = 1'b1;
Y4n = 1'b1; Y5n = 1'b1; Y6n = 1'b1; Y7n = 1'b1;
end
3'b011 : begin
Y0n = 1'b1; Y1n = 1'b1; Y2n = 1'b1; Y3n = 1'b0;
Y4n = 1'b1; Y5n = 1'b1; Y6n = 1'b1; Y7n = 1'b1;
end
3'b100 : begin
Y0n = 1'b1; Y1n = 1'b1; Y2n = 1'b1; Y3n = 1'b1;
Y4n = 1'b0; Y5n = 1'b1; Y6n = 1'b1; Y7n = 1'b1;
end
3'b101 : begin
Y0n = 1'b1; Y1n = 1'b1; Y2n = 1'b1; Y3n = 1'b1;
Y4n = 1'b1; Y5n = 1'b0; Y6n = 1'b1; Y7n = 1'b1;
end
3'b110 : begin
Y0n = 1'b1; Y1n = 1'b1; Y2n = 1'b1; Y3n = 1'b1;
Y4n = 1'b1; Y5n = 1'b1; Y6n = 1'b0; Y7n = 1'b1;
end
3'b111 : begin
Y0n = 1'b1; Y1n = 1'b1; Y2n = 1'b1; Y3n = 1'b1;
Y4n = 1'b1; Y5n = 1'b1; Y6n = 1'b1; Y7n = 1'b0;
end
default: begin
Y0n = 1'b1; Y1n = 1'b1; Y2n = 1'b1; Y3n = 1'b1;
Y4n = 1'b1; Y5n = 1'b1; Y6n = 1'b1; Y7n = 1'b1;
end
endcase
end
end
endmodule
输入描述:
input A ,
input B ,
input Ci
输出描述:
output wire D ,
output wire Co
解题思路:
先将全减器的真值表求出,根据真值表求出输出D和Co的逻辑函数,再使用3-8译码器实现逻辑函数。
全减器部分:
在全减器中,A是被减数,B是减数,Ci是来自低位的借位,D是差,Co是向高位的借位,全减器的真值表如下所示:
A | B | Ci | Co | D |
0 | 0 | 0 | 0 | 0 |
0 | 0 | 1 | 1 | 1 |
0 | 1 | 0 | 1 | 1 |
0 | 1 | 1 | 1 | 0 |
1 | 0 | 0 | 0 | 1 |
1 | 0 | 1 | 0 | 0 |
1 | 1 | 0 | 0 | 0 |
1 | 1 | 1 | 1 | 1 |
Co的逻辑函数表示为:
D的逻辑函数表示为:
令A,B,Ci分别对应于3-8译码器的输入端A2,A1,A0
将Co的逻辑函数转化为3-8译码器的输出端表示为:
将D的逻辑函数转化为3-8译码器的输出端表示为:
代码如下:
module decoder1(
input A ,
input B ,
input Ci ,
output wire D ,
output wire Co
);
wire Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7;
decoder_38 DE38 (.E(1'b1), .A0(Ci), .A1(B), .A2(A),
.Y0n(Y0), .Y1n(Y1), .Y2n(Y2), .Y3n(Y3),
.Y4n(Y4), .Y5n(Y5), .Y6n(Y6), .Y7n(Y7));
assign Co = ~Y1 | ~Y2 | ~Y3 | ~Y7 ;
assign D = ~Y1 | ~Y2 | ~Y4 | ~Y7 ;
endmodule