1'b0: out=a; 1'b1: out=b; default:out=4'bx; endcase endmodule
4.3 结果分析
module mux421_tb(); reg [3:0]a; reg [3:0]b; reg sel; wire [3:0]out;
mux421 MUX(a,b,sel,out); initial begin
a=4'b0000;b=4'b0000;sel=1'b0; #5 a=4'b1100; #5 b=4'b0101; #5 sel=1'b1; #5 a=4'b1000; #5 b=4'b1110; #5 a=12; #5 b=13; end endmodule
用case语句设计一个4位2选1数据选择器
验证说明:当sel=1时,out=b,当sel=0时,out=a。
5 实验5 5.1 实验内容
使用case语句设计八功能的算术运算单元(ALU),其输入信号a和b均为4位,输入功能选择信号select为3位,输出信号out为5位。算术运算单元ALU所执行的操作与select信号有关。
5.2 实验步骤
`timescale 1ns / 1ps module alu8( input wire [2:0]sel, input wire [3:0]a, input wire[3:0] b, output reg [4:0] out); always @(a or b or sel) begin case(sel)
3'b000:out=a; 3'b001:out=a+b;
3'b010:out=a-b; 3'b011:out=a/b; 3'b100:out=a%b; 3'b101:out=a*b; 3'b110:out=a<<1; 3'b111:out=a>>1; default: out=5'bxxxxx; endcase end endmodule
5.3 结果分析
module alu8_tb(); reg [2:0]sel; reg [3:0]a; reg [3:0] b; wire [4:0] out;
alu8 ALU(sel,a,b,out); initial begin
a=4'b0000;b=4'b0000;sel=3'b000; #5 a=4'b1100; #5 b=4'b0101; #5 sel=3'b100; #5 a=4'b1000; #5 b=4'b1110; #5 sel=3'b101; #5 b=4'b1111; end endmodule
使用case语句设计8功能ALU
验证说明:当sel选择不同值时,out等于不同运算结果,即实现了8功能ALU。
6 实验6 6.1 实验内容
对实验5进行板级验证
通过板子上的码拨开关输入操作数,自行设计拨码开关的控制逻辑,也可利用板子上的其它控制资源(如按钮等)
将运算结果显示到数码管上
6.2 实验步骤
管脚约束:set_property IOSTANDARD LVCMOS33 [get_ports {a[3]}] set_property IOSTANDARD LVCMOS33 [get_ports {a[2]}] set_property IOSTANDARD LVCMOS33 [get_ports {a[1]}] set_property IOSTANDARD LVCMOS33 [get_ports {a[0]}] set_property IOSTANDARD LVCMOS33 [get_ports {b[3]}] set_property IOSTANDARD LVCMOS33 [get_ports {b[2]}] set_property IOSTANDARD LVCMOS33 [get_ports {b[1]}] set_property IOSTANDARD LVCMOS33 [get_ports {b[0]}] set_property IOSTANDARD LVCMOS33 [get_ports {out[4]}] set_property IOSTANDARD LVCMOS33 [get_ports {out[3]}]
set_property IOSTANDARD LVCMOS33 [get_ports {out[2]}] set_property IOSTANDARD LVCMOS33 [get_ports {out[1]}] set_property IOSTANDARD LVCMOS33 [get_ports {out[0]}] set_property IOSTANDARD LVCMOS33 [get_ports {sel[2]}] set_property IOSTANDARD LVCMOS33 [get_ports {sel[1]}] set_property IOSTANDARD LVCMOS33 [get_ports {sel[0]}] set_property PACKAGE_PIN U3 [get_ports {a[3]}] set_property PACKAGE_PIN U2 [get_ports {a[2]}] set_property PACKAGE_PIN V2 [get_ports {a[1]}] set_property PACKAGE_PIN V5 [get_ports {a[0]}] set_property PACKAGE_PIN V4 [get_ports {b[3]}] set_property PACKAGE_PIN R3 [get_ports {b[2]}] set_property PACKAGE_PIN T3 [get_ports {b[1]}] set_property PACKAGE_PIN T5 [get_ports {b[0]}] set_property PACKAGE_PIN F6 [get_ports {out[4]}] set_property PACKAGE_PIN G4 [get_ports {out[3]}] set_property PACKAGE_PIN G3 [get_ports {out[2]}] set_property PACKAGE_PIN J4 [get_ports {out[1]}] set_property PACKAGE_PIN H4 [get_ports {out[0]}] set_property PACKAGE_PIN P5 [get_ports {sel[2]}] set_property PACKAGE_PIN P4 [get_ports {sel[1]}] set_property PACKAGE_PIN P3 [get_ports {sel[0]}]
RTL原理图: