I'm building a simple processor for one of my classes. I am just using the behavior view to handle all the details going on inside of the register file. I've got an array of four registers and I give them default values inside of the register file. Everything seems to be working but a few nanoseconds after the register was written with the new value it goes back to what the default value was. I'm not sure if I should be giving them the default values somewhere or if I'm doing something else wrong.
I think all the relevant code is pasted below, intval() just takes a bit_vector and returns a integer value.
Code:
process
--define register file
type register_unit is array(0 to 3) of bit_vector(7 downto 0);
variable registers: register_unit;
begin
-- initial the registers values
registers(0) := "00000000";
registers(1) := "00000001";
registers(2) := "00000010";
registers(3) := "00000011";
-- write data to register
if ((W = '1') and (CLOCK='1') ) then
registers(intval(Write_Reg)) := Write_Data;
end if;
You have assigned initial values for the registers inside process. These can be updated only when the execution of the process finished first time.
If you want to make default values for the registers, you need to declame them as signals outside the process and assign initial values. If you do this, whenever the device is powered up, the registers will have the default values.