Forum Discussion
Altera_Forum
Honored Contributor
14 years agovhdl coding
hi am new to vhdl programming. I need help in wirting the code for inserting variable data into a register. the length of the register should be based on the number of bits of data am giving to the r...
Altera_Forum
Honored Contributor
14 years ago --- Quote Start --- ya thanks for your quick response actually i have taken if statements to insert the data into the register. ex: if (numofbits = "0011") then data <= "111"; elsif(numofbits = "0100") then data <= "1111"; end if; so on i have to write code for variable numofbits for ex: 3 to 16 bits. is there any other way of writing the code instead of using so many if and elsif statements. --- Quote End --- Just how does numofbits 'vary'? The way you've written the above, implies that it does not vary within a given design since if it did then the assignments to 'data' would not be correct since in one case data is three bits, the other it is four. I doubt that is what you intend, but if by chance it is then the code would be... signal data: std_logic_vector(numofbits - 1 downto 0); ... data <= (others => '1'); But like I said, I doubt that is what you intend. Instead, I'm guessing that numofbits is more variable than that, in which case the following would work... signal data: std_logic_vector(??? downto 0); -- No idea how wide 'data' is ... process ... data <= (other => '0'); for i in 0 to (numofbits - 1) loop data(i) <= '1'; end loop; ... Kevin Jennings