虚拟机:VMware -14.0.0.24051
环 境:ubuntu 18.04.1
脚 本:makefile(点击直达)
应用工具:vcs 和 verdi
文章目录
一、Demand
- 比较两个输入字节的大小,三个输出端口,当 a大于b,re=1,其余为0;当 a小于b,reb=1,其余为0;当a等于b时,eq=1,其余为0。
- 用行为级描述语句和连续赋值语句实现
二、Block Diagram
三、Design and Functional Verification
(1)RTL
//-- Solution 1
//-- modified by xlinxdu, 2022/04/25
module compare(
//-- interface
input wire [7:0] a ,
input wire [7:0] b ,
output reg re ,
output reg reb,
output reg eq
);
/*-----------------------------------------------\
-------------- compare a with b --------------
\-----------------------------------------------*/
always @ (*)begin
if(a > b)begin
{
re,reb,eq} = {
1'b1,1'b0,1'b0};
end
else if(a < b)begin
{
re,reb,eq} = {
1'b0,1'b1,1'b0};
end
else if(a == b)begin
{
re,reb,eq} = {
1'b0,1'b0,1'b1};
end
else begin
{
re,reb,eq} = {
1'bx,1'bx,1'bx};
end
end
endmodule
//-- Solution 2
//-- modified by xlinxdu, 2022/04/25
module compare(
//-- interface
input wire [7:0] a ,
input wire [7:0] b ,
output reg re ,
output reg reb,
output reg eq
);
wire re_s,reb_s,eq_s;
assign re_s = (a > b) ? 1'b1:1'b0;
assign reb_s = (a < b) ? 1'b1:1'b0;
assign eq_s = (a == b)? 1'b1:1'b0;
always @ (*) begin
{
re,reb,eq} = {
re_s,reb_s,eq_s};
end
endmodule
(2)Test Bench
//-- modified by xlinxdu, 2022/04/25
module tb_compare;
reg [7:0] a ;
reg [7:0] b ;
wire re ;
wire reb;
wire eq ;
initial begin
a = 8'b0;
b = 8'b0;
end
always begin
#100;
a = {
$random}%255;
b = {
$random}%255;
end
compare tb_compare(
.a (a ),
.b (b ),
.re (re ),
.reb(reb),
.eq (eq )
);
initial begin
#10000 $finish;
$fsdbDumpfile("compare.fsdb");
$fsdbDumpvars ;
$fsdbDumpMDA ;
end
endmodule
四、Result
(1)Solution 1
(2)Solution 2
由上述结果可知,无论是行为级描述语句,还是连续赋值语句,在使用同一个测试平台的时候,结果是一样的。由结果可知,模块数据通路是正常的,功能验证通过。
作者:xlinxdu
版权:本文是作者原创,版权归作者所有。
转载:未经作者允许,禁止转载,转载必须保留此段声明,必须在文章中给出原文连接。