## 4 bit comparator

This is the code for a 4 bit equality comparator.

 ```module eq4bit ( a, b, led2); input wire [3:0] a, b; output wire led2;   wire p1,p2,p3,p4;   comp1bit compare1 (a,b,p1); comp1bit compare2 (a,b,p2); comp1bit compare3 (a,b,p3); comp1bit compare4 (a,b,p4);   assign led2 = p1 & p2 & p3 & p4;   endmodule   module comp1bit ( input a, b, output p ); assign p = (a & b) | ( ~a & ~b); endmodule```

Essentially, it gives output 1 when all 4 bits of a are equal to the 4 bits of b.
The video shows the result when it is implemmented on Spartixed board.

Following ucf file is used.

 ```NET "led2" LOC = P131;   NET "a" LOC = P33; NET "a" LOC = P32; NET "a" LOC = P30; NET "a" LOC = P29;   NET "b" LOC = P27; NET "b" LOC = P26; NET "b" LOC = P24; NET "b" LOC = P23;```

In place of the module instantiation, we could also use a much simpler implementation as this one.

 ```module eq4bit ( a, b, led2); input wire [3:0] a, b; output wire led2;   assign led2 = (a == b) ? 1'b1 : 1'b0; endmodule  ```

Suggested Exercises

1. Modify the code so that it gives output when a is less than b - use the 1 bit istantiation method ( is slightly difficult) and well as the shorter version .
2. Modify the code so it compares if a is greater than b.