Documente Academic
Documente Profesional
Documente Cultură
/////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////
// Company:
//
// Engineer: Michael Gidaro, Erick Johnson
//
// Create Date:
4/26/13
// Design Name: CPU
// Module Name: control unit
// Project Name:
// Target Devices:
// Tool versions:
// Description:
Handles all control signal for the cpu
//
// Dependencies:
//
// Revision: Erick Johnson
//
//
// Additional Comments:
//
/////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////
module control_unit
(
rst,
instruction,
data_mem_wren,
reg_file_wren,
reg_file_dmux_select,
reg_file_rmux_select,
alu_mux_select,
alu_control,
alu_zero,
alu_shamt,
pc_control
);
//-------------------------// local parameters
//-------------------------//-------------------------// Input Ports
//-------------------------// < Enter Input Ports >
input
input
[31:26]
input
rst;
instruction; //get opcode
alu_zero;
<=
<=
<=
<=
FETCH2;
FETCH3;
FETCH4;
DECODE;
DECODE: case(instruction)
LOAD:
nextstate <= MEMORY_ADDRESS;
STORE:
nextstate <= MEMORY_ADDRESS;
ARITHMETIC:
nextstate <= ARITHMETIC_EXECUTE;
BRANCH:
nextstate <= BEQ_EXECUTE;
JUMP:
nextstate <= J_EXECUTE;
default:
nextstate <= FETCH1;
endcase
MEMORY_ADDRESS: case(instruction)
LOAD:
nextstate <= LOAD_READ;
STORE:
nextstate <= STORE_WRITE;
default:
nextstate <= FETCH1;
endcase
LOAD_READ:
LOAD_WRITE:
nextstate <= FETCH1;
STORE_WRITE:
nextstate <= FETCH1;
ARITHMETIC_EXECUTE: nextstate <= ARITHMETIC_WRITE;
ARITHMETIC_WRITE:
nextstate <= FETCH1;
BEQ_EXECUTE:
nextstate <= FETCH1;
J_EXECUTE:
nextstate <= FETCH1;
default:
nextstate <= FETCH1;
endcase
end
always @(*)
begin
reg_file_wren <= 0;
reg_file_rmux_select <= 0;
data_mem_wren <= 4b0000;
alu_mux_select <= 0;
reg_file_dmux_select <= 0;
alu_control <= 4b0000;
alu_shamt <= 5b00000;
pc_control <= 4b0000;
case(state)
FETCH1:
begin
wren <= 4b0000;
alu_mux_select,
pc_control <= 4b0000;
end
FETCH2:
begin
wren <= 4b0001;
alu_mux_select <= 1;
pc_control <= 4b0000;
end
FETCH3:
begin
wren <= 4b0011;
alu_mux_select <= 1;
pc_control <= 4b0000;
end
FETCH4:
begin
wren <= 4b1111;
alu_mux_select <= 1;
pc_control <= 4b0000;
end
DECODE: alu_mux_select <= 0;
BEQ_EXECUTE: pc_control <= 4b0011;
J_EXECUTE: pc_control <= 4b0001;
endcase
end
endmodule