Verilog Instantiation clarification

Status
Not open for further replies.

bciaren

Newbie level 4
Joined
Mar 14, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,336
In this sample file (from textbook), do these two things mean the same thing?

Code:
module eq2(
    input  wire [1:0] a,b,
	 output wire aeqb
	 );
// internal signal declaration
		
	  wire e0,e1;
//body
// instatiate two 1-bit comparators
eq1 eq_bit0_unit(.i0(a[0]), .i1(b[0]), .eq(e0));
eq1 eq_bit1_unit (.eq(e1), .i0(a[1]), .i1(b[1]));

// a and b are equal if individual bits are equal
assign aeqb = e0 & e1;

endmodule

Code:
module eq2(
    input  wire [1:0] a,b,
	 output wire aeqb
	 );
// internal signal declaration
		
	  wire e0,e1;
//body
// instatiate two 1-bit comparators
eq1 eq_bit0_unit(.i0(a[0]), .i1(b[0]), .eq(e0));
eq1 eq_bit1_unit (i0(a[1]), .i1(b[1]), .eq(e1));

// a and b are equal if individual bits are equal
assign aeqb = e0 & e1;

endmodule

If not, could you explain why the former is chosen? I'm not following this if that's the case.. thanks
 

hi

Both are same, will generate exactly the same thing. Just position of the ports connection different
But in the second one there is one error I guess( I have not touched verilog for a long time) as far as I remember you cannot have position and named connection together in the single instance calling.
and if you see in your case you have the two together in the second case

- - - Updated - - -

Code:
eq1 eq_bit1_unit (i0(a[1]), .i1(b[1]), .eq(e1));
should be
Code:
eq1 eq_bit1_unit (.i0(a[1]), .i1(b[1]), .eq(e1));
 

You should use former, because the latter has a big fat error in it. But assuming the error is just a typo as pointed out by syedshan ... then yes they should be equivalent. If you used named port notation a la "eq1 eq_bit1_unit (.i0(a[1]), .i1(b[1]), .eq(e1));" then it should work fine.

Disregarding the missing '.' character, the 2nd version gets my vote. Consistent order of named ports makes it more readable IMO.
 
Last edited:

YES, it should be:
Code:
eq1 eq_bit0_unit(.i0(a[0]), .i1(b[0]), .eq(e0));
eq1 eq_bit1_unit (.i0(a[1]), .i1(b[1]), .eq(e1));

Sorry about that typo! Thank you so much for answering, I hated the way the book wrote it. My book uses the 1st code, I feel the 2nd version is much more easily read.

Thank you again!
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…