0% found this document useful (0 votes)
14 views7 pages

4b Mag Comp

The document describes the design of a 4-bit magnitude comparator using Verilog code in behavioral mode, synthesized with Makerchip and NgVeri tools. It explains the functionality of the comparator, which determines the relationship between two 4-bit binary numbers, providing outputs for greater than, less than, and equal conditions. The document includes the Verilog code implementation, a truth table, and references for further reading.

Uploaded by

abishek2003jothi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

4b Mag Comp

The document describes the design of a 4-bit magnitude comparator using Verilog code in behavioral mode, synthesized with Makerchip and NgVeri tools. It explains the functionality of the comparator, which determines the relationship between two 4-bit binary numbers, providing outputs for greater than, less than, and equal conditions. The document includes the Verilog code implementation, a truth table, and references for further reading.

Uploaded by

abishek2003jothi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

4-bit Magnitude Comparator

(using HDL language)

1. Abstract
The design uses Verilog code in behavioral mode, also known as RTL (Register Transfer Level) coding, to
create the functional block of the comparator. This Verilog code is synthesized using the Makerchip platform
and the NgVeri tool, which convert the HDL (Hardware Description Language) design into a corresponding
block structure.

2. Theory
A comparator is a circuit which compares the two values. A Magnitude Comparator is a combinational
circuit which compares the magnitude of two binary numbers. It decides whether a number is greater than,
less than or equal to, by comparing the magnitudes of both the numbers. It is mostly used inside arithmetic
operations in ALU (Arithmetic and Logic unit) which is situated inside CPU (Central Processing Unit). If two n-
bit number must be compared, then the given circuit has 22𝑛 total conditions. For example – if there are 2 bit
number , there will be 4 input and 16 rows in the truth table , similarly In this given circuit , if the number of
bit in each number is 4 then , it is 4 bit magnitude comparator which means that it has 8 input and total of 3
output that is greater than(A>B), less than(A<B) and equal to(A=B) if A and B be two binary numbers. Let
suppose that there are two number A and B, and each have 4-bit A0, A1, A2, A3 and B0, B1, B2, B3. Now, 4-bit
magnitude comparator compares the magnitude of both number and provide the output accordingly that
whether (A>B) or (A<B) or (A=B).

3. Truth Table (ex. 2bit)

4. Circuit
5. Verilog code for Comparator:
\TLV_version 1d: tl-x.org

\SV

//Your Verilog/System Verilog Code Starts Here:

// Verilog file: comparator.v

//***************************************

module comparator(

input [3:0] a_in, // Input A

input [3:0] b_in, // Input B

output reg l, // When A is less than B, it is high

output reg e, // When A is equal to B, it is high

output reg g; // When A is greater than B, it is high

// Execute this block when inputs A_in or B_in change

always @(a_in or b_in) begin

// If A is greater than B, set g high

if (a_in > b_in) begin

l = 1'b0;

e = 1'b0;

g = 1'b1;

end

// If A is equal to B, set e high


else if (a_in == b_in) begin

l = 1'b0;

e= 1'b1;

g= 1'b0;

end

// Otherwise, set l high (A < B)

else begin

l= 1'b1;

e= 1'b0;

g = 1'b0;

end

end

endmodule

//Top Module Code Starts here:

module top(input logic clk, input logic reset, input logic [31:0] cyc_cnt, output logic passed, output logic failed);

logic [3:0] a_in;//input

logic [3:0] b_in;//input

logic l;//output

logic e;//output

logic g;//output

//The $random() can be replaced if user wants to assign values

assign A_in = $random();

assign B_in = $random();

comparator comparator(.a_in(a_in), .b_in(b_in), .l(l), .e(e), .g(g));

\TLV

//Add \TLV here if desired

\SV

endmodule
6. Schematic Diagram

7.Makerchip plot:
6.Output Waveforms

A3, A2, A1, A0

B3, B2, B1, B0


(A>B), (A=B), (A<B)
References

[1] https://www.geeksforgeeks.org/magnitude-comparator-in-digital-logic/

[2] https://www.researchgate.net/publication/275726067_Performance_Analysis_of_Magnitude_Comparator_using_
Different_Design_Techniques

[3] https://eevibes.com/digital-logic-design/how-to-design-a-4-bit-magnitude-comparator-circuit/

Project Submitted by:

Shanthi Priya K
Rajiv Gandhi University of Knowledge and Technologies,
IIIT Nuzvid,
Eluru ,521202

You might also like