提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
提示:这里可以添加本文要记录的大概内容:
零基础小白探索modelsim-数据比较器
提示:以下是本篇文章正文内容,下面案例可供参考
一、数据比较器是什么?
数据比较器是用来比较俩个二进制数据大小
二、使用步骤
1.顶层模块
代码如下(示例):
module data_comparator(
input wire [3:0] a,
input wire [3:0] b,
input wire [2:0] c,
output reg [2:0] out
);
always@(a,b,c)
if(a>b)out=3'b100;
else if(a<b) out=3'b001;
else out=c;
endmodule
2.测试模块
代码如下(示例):
`timescale 1ns/1ns
module data_comparator_tb();
reg [3:0] test_a;
reg [3:0] test_b;
reg [2:0] test_c;
wire [2:0] test_out;
data_comparator u1(.a(test_a),.b(test_b),.c(test_c),.out(test_out));
initial
begin
test_a = 4'b0000;
test_b = 4'b0001;
test_c = 3'b010; //a<b,out==001,?1
#1000
test_a = 4'b0001;
test_b = 4'b0000;
test_c = 3'b010; //a>b,out==100,?4
#1000
test_a = 4'b0001;
test_b = 4'b0001;
test_c = 3'b100; //a>b,out==100,?4
#1000
test_a = 4'b0001;
test_b = 4'b0001;
test_c = 3'b001; //a<b,out==001,?1
#1000
test_a = 4'b0001;
test_b = 4'b0001;
test_c = 3'b010; //a=b,out==010,?2
#1000
test_a = 4'b0100;
test_b = 4'b0001;
test_c = 3'b010; //a>b,out==100,?4
#1000
test_a = 4'b0001;
test_b = 4'b0100;
test_c = 3'b010; //a<b,out==001,?1
end
endmodule
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了数据比较器的使用。