Author Topic: Beginner reg question  (Read 806 times)

0 Members and 1 Guest are viewing this topic.

Offline TheGreatNedTopic starter

  • Contributor
  • Posts: 20
  • Country: us
Beginner reg question
« on: February 24, 2020, 11:02:07 pm »
Hi,

If I read and write to a simple reg on the same rising clock edge, is the read value guaranteed to be the old data?

I.e:

Code: [Select]
reg[15:0] myreg = 0;

...


always @ (posedge clk)
begin
  output_reg <= myreg;
  myreg <= myreg + 1;
end

output_reg is guaranteed to be the non-incremented (old) value, right?
 

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 3867
  • Country: us
Re: Beginner reg question
« Reply #1 on: February 24, 2020, 11:05:08 pm »
Yes and this is true regardless of the order of the statements as long as you use non-blocking assignment i.e. <=. You should always use non blocking assignments in a clocked block.
 

Offline TheGreatNedTopic starter

  • Contributor
  • Posts: 20
  • Country: us
Re: Beginner reg question
« Reply #2 on: February 25, 2020, 01:45:18 am »
Yes and this is true regardless of the order of the statements as long as you use non-blocking assignment i.e. <=. You should always use non blocking assignments in a clocked block.

thank you  8)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf