The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 17th, 2024, 4:19pm
Pages: 1
Send Topic Print
what is the purpose to use rega<=datain & dataout<=rega? (Read 1746 times)
newic
Senior Member
****
Offline



Posts: 138

what is the purpose to use rega<=datain & dataout<=rega?
Nov 11th, 2011, 12:30am
 

Code:
module test(
  reset, clk, datain, dataout);

input [7:0] datain;
output [7:0] dataout;
input clk, reset;

reg [7:0] rega;
reg [7:0] dataout;

always @ (posedge clk or posedge reset) begin
 if( reset ==1'b1) begin
	  rega <= 8'b0;
	  dataout <= 8'b0;
   end
 else begin
	  rega <=datain;
	  dataout <= rega;
end

endmodule
 



May I know what the purpose to use rega<=datain & dataout<=rega?
if datain is  1001 0011, what is the expected output?
Back to top
 
 
View Profile   IP Logged
Marq Kole
Senior Member
****
Offline

Hmmm. That's
weird...

Posts: 122
Eindhoven, The Netherlands
Re: what is the purpose to use rega<=datain & dataout<=rega?
Reply #1 - Nov 13th, 2011, 1:17pm
 
Smiley You could just have written a test bench and run it if you wanted the answer...

It delays the output by one clock edge, so if the input is 1001 0011 at the first rising edge of clk/reset, the output will be xxxx xxxx. On the second rising edge of clk/reset it will be 1001 0011. That's because in the non-blocking assignments all right-hand sides that occur at the some simulation time point will be evaluated first and only after that the assignments will be done. As the first value of rega is its initial value, i.e. xxxx xxxx, that is what is assigned to dataout at the same time as 1001 0011 is assigned to rega.

Cheers,
Marq
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.