Verilog实验报告

实验一:多路选择器

  1. 设计要求:4选1
  2. 代码
module selector(a,b,c,d,sl0,sl1,out);

parameter WL = 8;



input [WL-1:0] a,b,c,d;

input sl0,sl1;

output [WL-1:0] out;



reg [WL-1:0] out;

always @ (a or b or c or d or sl0 or sl1) begin

       case({sl0,sl1})

 2'b00 : out = a;

 2'b01 : out = b;

 2'b10 : out = c;

 2'b11 : out = d;

       endcase

end

endmodule

4X4的交叉开关消耗资源成倍的增长了。

  1. 波形仿真

    实验二:交叉开关

  2. 设计要求:编写一个4X4路交叉开关
  3. 代码
    module switch(in0,in1,in2,in3,sl0,sl1,sl2,sl3,out0,out1,out2,out3);
    
    parameter WL = 8;
    
    
    
    input [WL-1:0] in0,in1,in2,in3;
    
    input [1:0] sl0,sl1,sl2,sl3;
    
    output [WL-1:0] out0,out1,out2,out3;
    
    
    
    reg [WL-1:0] out0,out1,out2,out3;
    
    always@(in0 or in1 or in2 or in3 or sl0) begin
    
    case(sl0)
    
    2'b00:out0 = in0;
    
    2'b01:out0 = in1;
    
    2'b10:out0 = in2;
    
    2'b11:out0 = in3;
    
    endcase
    
    end
    
    
    
    always@(in0 or in1 or in2 or in3 or sl1) begin
    
    case(sl1)
    
    2'b00:out1 = in0;
    
    2'b01:out1 = in1;
    
    2'b10:out1 = in2;
    
    2'b11:out1 = in3;
    
    endcase
    
    end
    
    
    
    always@(in0 or in1 or in2 or in3 or sl2) begin
    
    case(sl2)
    
    2'b00:out2 = in0;
    
    2'b01:out2 = in1;
    
    2'b10:out2 = in2;
    
    2'b11:out2 = in3;
    
    endcase
    
    end
    
    
    
    always@(in0 or in1 or in2 or in3 or sl3) begin
    
    case(sl3)
    
    2'b00:out3 = in0;
    
    2'b01:out3 = in1;
    
    2'b10:out3 = in2;
    
    2'b11:out3 = in3;
    
    endcase
    
    end
    
    endmodule

  4. RTL View

 5.结论:4X4的交叉开关消耗资源成倍的增长了。

实验三:优先编码器

  1. 设计要求:编写一个8输入的优先编码器
  2. 代码:
module TEST_3(in,out);

parameter WL=8;

input [WL-1:0] in;

output [2:0] out;



reg out;

always @(in) begin

if(in[0]) out = 3'b001;

else if(in[1]) out = 3'b010;

else if(in[2]) out = 3'b011;

else if(in[3]) out = 3'b100;

else if(in[4]) out = 3'b101;

else if(in[5]) out = 3'b110;

else if(in[6]) out = 3'b111;

else out = 3'b000;

end

endmodule

4-16译码器的资源消耗约是3-8译码器的2倍。

  1. RTL View

    实验四:多路译码器

  2. 设计要求:编写一个4-16的译码器
  3. 代码:
    module TEST_4(in,out);
    
    input [3:0] in;
    
    output[15:0] out;
    
    
    
    reg [15:0]out;
    
    
    
    always @(in) begin
    
    case(in)
    
    4'b0000 : out = 16'b0000_0000_0000_0001;
    
    4'b0001 : out = 16'b0000_0000_0000_0010;
    
    4'b0010 : out = 16'b0000_0000_0000_0100;
    
    4'b0011 : out = 16'b0000_0000_0000_1000;
    
    4'b0100 : out = 16'b0000_0000_0001_0000;
    
    4'b0101 : out = 16'b0000_0000_0010_0000;
    
    4'b0110 : out = 16'b0000_0000_0100_0000;
    
    4'b0111 : out = 16'b0000_0000_1000_0000;
    
    4'b1000 : out = 16'b0000_0001_0000_0000;
    
    4'b1001 : out = 16'b0000_0010_0000_0000;
    
    4'b1010 : out = 16'b0000_0100_0000_0000;
    
    4'b1011 : out = 16'b0000_1000_0000_0000;
    
    4'b1100 : out = 16'b0001_0000_0000_0000;
    
    4'b1101 : out = 16'b0010_0000_0000_0000;
    
    4'b1110 : out = 16'b0100_0000_0000_0000;
    
    4'b1111 : out = 16'b1000_0000_0000_0000;
    
    endcase
    
    end
    
    endmodule
  4.  RTL View

  5. 结论:4-16译码器的资源消耗约是3-8译码器的2倍。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值