Browse Source

fix instruction memory offset

Simard Yohan 2 years ago
parent
commit
e8c135f1b9
3 changed files with 34 additions and 37 deletions
  1. 28
    31
      CPU.vhd
  2. 5
    1
      config_simu.wcfg
  3. 1
    5
      instruction_memory.vhd

+ 28
- 31
CPU.vhd View File

@@ -83,46 +83,46 @@ architecture Behavioral of CPU is
83 83
 	signal ALU_C : std_logic;
84 84
 	signal ALU_Ctrl : std_logic_vector(1 downto 0);
85 85
 	
86
-	signal registers_addr_A : std_logic_vector(3 downto 0);
87
-	signal registers_addr_B : std_logic_vector(3 downto 0);
88
-	signal registers_addr_W : std_logic_vector(3 downto 0);
86
+	signal registers_addr_A : std_logic_vector(3 downto 0) := (others => '0');
87
+	signal registers_addr_B : std_logic_vector(3 downto 0) := (others => '0');
88
+	signal registers_addr_W : std_logic_vector(3 downto 0) := (others => '0');
89 89
 	signal registers_W : std_logic := '0';
90
-	signal registers_DATA : std_logic_vector(7 downto 0);
90
+	signal registers_DATA : std_logic_vector(7 downto 0) := (others => '0');
91 91
 	signal registers_QA : std_logic_vector(7 downto 0);
92 92
 	signal registers_QB : std_logic_vector(7 downto 0);
93 93
 	
94
-	signal data_memory_addr : std_logic_vector(7 downto 0);
95
-	signal data_memory_data : std_logic_vector(7 downto 0);
96
-	signal data_memory_rw : std_logic;
94
+	signal data_memory_addr : std_logic_vector(7 downto 0) := (others => '0');
95
+	signal data_memory_data : std_logic_vector(7 downto 0) := (others => '0');
96
+	signal data_memory_rw : std_logic := '1';
97 97
 	signal data_memory_q : std_logic_vector(7 downto 0);
98 98
 	
99
-	signal instr_memory_addr : std_logic_vector(7 downto 0);
99
+	signal instr_memory_addr : std_logic_vector(7 downto 0) := (others => '0');
100 100
 	signal instr_memory_q : std_logic_vector(31 downto 0);
101 101
 
102 102
 	-- Etage 1
103 103
 	signal IP : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
104
-	signal OP1 : STD_LOGIC_VECTOR(7 downto 0);
105
-	signal A1 : STD_LOGIC_VECTOR(7 downto 0);
106
-	signal B1 : STD_LOGIC_VECTOR(7 downto 0);
107
-	signal C1 : STD_LOGIC_VECTOR(7 downto 0);
104
+	signal OP1 : STD_LOGIC_VECTOR(7 downto 0) := NOP;
105
+	signal A1 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
106
+	signal B1 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
107
+	signal C1 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
108 108
 
109 109
 	-- Etage 2
110
-	signal OP2 : STD_LOGIC_VECTOR(7 downto 0);
111
-	signal A2 : STD_LOGIC_VECTOR(7 downto 0);
112
-	signal B2 : STD_LOGIC_VECTOR(7 downto 0);
113
-	signal C2 : STD_LOGIC_VECTOR(7 downto 0);
110
+	signal OP2 : STD_LOGIC_VECTOR(7 downto 0) := NOP;
111
+	signal A2 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
112
+	signal B2 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
113
+	signal C2 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
114 114
 
115 115
 	-- Etage 3
116
-	signal OP3 : STD_LOGIC_VECTOR(7 downto 0);
117
-	signal A3 : STD_LOGIC_VECTOR(7 downto 0);
118
-	signal B3 : STD_LOGIC_VECTOR(7 downto 0);
116
+	signal OP3 : STD_LOGIC_VECTOR(7 downto 0) := NOP;
117
+	signal A3 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
118
+	signal B3 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
119 119
 
120 120
 	-- Etage 4
121
-	signal OP4 : STD_LOGIC_VECTOR(7 downto 0);
122
-	signal A4 : STD_LOGIC_VECTOR(7 downto 0);
123
-	signal B4 : STD_LOGIC_VECTOR(7 downto 0);
121
+	signal OP4 : STD_LOGIC_VECTOR(7 downto 0) := NOP;
122
+	signal A4 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
123
+	signal B4 : STD_LOGIC_VECTOR(7 downto 0) := (others => '0');
124 124
 
125
-	signal bubble : integer := 2;
125
+	signal bubble : integer := 3;
126 126
 
127 127
 begin
128 128
    myalu: ALU PORT MAP (
@@ -178,6 +178,11 @@ begin
178 178
 	data_memory_addr <= A3 when (OP3 = STORE) else B3;
179 179
 	data_memory_data <= B3;
180 180
 	
181
+	C1 <= instr_memory_q(7 downto 0) when (bubble = 0) else "00000000";
182
+	B1 <= instr_memory_q(15 downto 8) when (bubble = 0) else "00000000";
183
+	A1 <= instr_memory_q(23 downto 16) when (bubble = 0) else "00000000";
184
+	OP1 <= instr_memory_q(31 downto 24) when (bubble = 0) else NOP;
185
+	
181 186
 	process
182 187
 	begin
183 188
 	wait until CLK'event and CLK='1';
@@ -212,19 +217,11 @@ begin
212 217
 			
213 218
 			-- Memoire -> etage 1
214 219
 			if (bubble = 0) then
215
-				C1 <= instr_memory_q(7 downto 0);
216
-				B1 <= instr_memory_q(15 downto 8);
217
-				A1 <= instr_memory_q(23 downto 16);
218
-				OP1 <= instr_memory_q(31 downto 24);
219 220
 				IP <= IP + 1;
220 221
 				if (needBubbles(to_integer(unsigned(instr_memory_q(31 downto 24)))) = '1') then
221 222
 					bubble <= 3;
222 223
 				end if;
223 224
 			else
224
-				C1 <= "00000000";
225
-				B1 <= "00000000";
226
-				A1 <= "00000000";
227
-				OP1 <= NOP;
228 225
 				bubble <= bubble - 1;
229 226
 			end if;
230 227
 	end if;

+ 5
- 1
config_simu.wcfg View File

@@ -13,7 +13,7 @@
13 13
          </top_modules>
14 14
       </db_ref>
15 15
    </db_ref_list>
16
-   <WVObjectSize size="11" />
16
+   <WVObjectSize size="12" />
17 17
    <wvobject fp_name="/cpu_test/clk" type="logic" db_ref_id="1">
18 18
       <obj_property name="ElementShortName">clk</obj_property>
19 19
       <obj_property name="ObjectShortName">clk</obj_property>
@@ -26,6 +26,10 @@
26 26
       <obj_property name="ElementShortName">clk_period</obj_property>
27 27
       <obj_property name="ObjectShortName">clk_period</obj_property>
28 28
    </wvobject>
29
+   <wvobject fp_name="/cpu_test/uut/instr_mem/q" type="array" db_ref_id="1">
30
+      <obj_property name="ElementShortName">q[31:0]</obj_property>
31
+      <obj_property name="ObjectShortName">q[31:0]</obj_property>
32
+   </wvobject>
29 33
    <wvobject fp_name="/cpu_test/uut/ip" type="array" db_ref_id="1">
30 34
       <obj_property name="ElementShortName">ip[7:0]</obj_property>
31 35
       <obj_property name="ObjectShortName">ip[7:0]</obj_property>

+ 1
- 5
instruction_memory.vhd View File

@@ -32,10 +32,6 @@ architecture Behavioral of instruction_memory is
32 32
 		9 => LOAD  & "00001000" & "00010100" & "00000000", -- load mem@20 (8) in R8
33 33
 		others => (others => '0'));
34 34
 begin
35
-	process
36
-	begin
37
-		wait until CLK'event and CLK='1';
38
-			q <= memory(to_integer(unsigned(addr)));
39
-	end process;
35
+		q <= memory(to_integer(unsigned(addr)));
40 36
 end Behavioral;
41 37
 

Loading…
Cancel
Save