1

In a module:

reg a, b;
integer i, j;

initial
     begin
          for (a = 0; a < 2; a = a + 1)     
               //some code
     end

The textbook says it would be incorrect to get rid of integers i and j and use reg a and b directly as loop counters. Hint: reg variables have a fixed size and, hence, they wrap.

What does that mean? Doesn't integer have a fixed size as well? And what's wrapping?

1

1 Answer 1

2

A reg is either single bit, or multiple bit if you define it as an array. An integer, on the other hand is 32 bits. So if you have a loop, it is more convenient to use an integer variable that doesn't overflow as the loop advances.

In your example, you set a < 2, so with a single bit reg the loop never terminates.

Moreover integers are singed values.

Sign up to request clarification or add additional context in comments.

1 Comment

integer is 32 bit in verilog, never 64. Single-bit reg will overflow and loop will never exit. You need at least 2-bit reg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.