Comparator

3
Comparator.v Thu May 26 04:31:01 2016 Page 1 1 module Comparator(input [32:0] dataIn1, 2 input [32:0] dataIn2, 3 input clock, 4 input reset, 5 output reg equals 6 ); 7 8 always @(posedge clock) 9 if(reset==1) 10 equals <= 0; 11 else 12 if (dataIn1 == dataIn2) 13 equals <= 1; 14 else 15 equals <= 0; 16 17 18 endmodule 19 20 21 module test; 22 23 reg [32:0] dataIn1; 24 reg [32:0] dataIn2; 25 reg clock; 26 reg reset; 27 28 wire equals; 29 30 Comparator uut ( 31 .dataIn1(dataIn1), 32 .dataIn2(dataIn2), 33 .clock(clock), 34 .reset(reset), 35 .equals(equals) 36 ); 37 38 initial begin 39 clock = 0; 40 forever #5 clock = ~clock; 41 end 42 43 initial begin 44 dataIn1 = 0; 45 dataIn2 = 0; 46 reset = 1; 47 @(negedge clock) 48 reset = 0; 49 dataIn1 = 5; 50 dataIn2 = 10; 51 @(negedge clock) 52 dataIn1 = 10; 53 @(negedge clock); 54 dataIn2 = 5; 55 @(negedge clock) 56 dataIn1 = 5; 57 @(negedge clock)

description

Compares a number with another

Transcript of Comparator

Page 1: Comparator

Comparator.v Thu May 26 04:31:01 2016

Page 1

1 module Comparator(input [32:0] dataIn1,2 input [32:0] dataIn2,3 input clock,4 input reset,5 output reg equals6 );7 8 always @(posedge clock)9 if(reset==1)

10 equals <= 0;11 else12 if (dataIn1 == dataIn2)13 equals <= 1;14 else15 equals <= 0;16 17 18 endmodule19 20 21 module test;22 23 reg [32:0] dataIn1;24 reg [32:0] dataIn2;25 reg clock;26 reg reset;27 28 wire equals;29 30 Comparator uut (31 .dataIn1(dataIn1),32 .dataIn2(dataIn2),33 .clock(clock),34 .reset(reset),35 .equals(equals)36 );37 38 initial begin39 clock = 0;40 forever #5 clock = ~clock;41 end42 43 initial begin44 dataIn1 = 0;45 dataIn2 = 0;46 reset = 1;47 @(negedge clock)48 reset = 0;49 dataIn1 = 5;50 dataIn2 = 10;51 @(negedge clock)52 dataIn1 = 10;53 @(negedge clock);54 dataIn2 = 5;55 @(negedge clock)56 dataIn1 = 5;57 @(negedge clock)

Page 2: Comparator

Comparator.v Thu May 26 04:31:01 2016

Page 2

58 reset = 1;59 @(negedge clock)60 reset = 0;61 62 #100 $stop();63 64 end65 66 endmodule67 68

Page 3: Comparator