Looking for something others

B

Brad Smallridge

Hi folks,

How does one write this code cleanly?

if( segment_pointer_count="111111111" ) then
segment_pointer_count <= "000000001"; -- skip zero
else
segment_pointer_count <= segment_pointer_count+1;
end if;


That is, with something that is length independent.

Thanks,

Brad Smallridge
b r a d @ a i v i s i o n . c o m
 
T

Tim Hubberstey

Brad said:
Hi folks,

How does one write this code cleanly?

if( segment_pointer_count="111111111" ) then
segment_pointer_count <= "000000001"; -- skip zero
else
segment_pointer_count <= segment_pointer_count+1;
end if;


That is, with something that is length independent.

Length independent _IF_ segment_pointer_count is 31 bits or less:

use numeric_std.all;
....
signal segment_pointer_count : unsigned(...);
....
if( segment_pointer_count=(2**segment_pointer_count'length)-1 ) then
segment_pointer_count <= 1; -- skip zero
else
segment_pointer_count <= segment_pointer_count+1;
end if;
 
N

Nicolas Matringe

Hello

Brad said:
Hi folks,

How does one write this code cleanly?

if( segment_pointer_count="111111111" ) then
segment_pointer_count <= "000000001"; -- skip zero
else
segment_pointer_count <= segment_pointer_count+1;
end if;

That is, with something that is length independent.

You can write this:

if segment_pointer_count = (segment_pointer_count'range => '1') then
segment_pointer_count <= (0 => '1', others => '0');
else
....

Nicolas
 
S

sps

if( segment_pointer_count= X"FF" ) then
segment_pointer_count <= X"01"; -- skip zero
else
segment_pointer_count <= segment_pointer_count+1;
end if;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top