angjohn
Junior Member level 2
parameter s7 = 5’b00111
following code is written using Verilog:
//CU
module Controlunit (Z, reset, CMP, OPCODE, CLK);
output[14:0] Z;
wire[14:0] Z;
input reset;
input CMP;
input[7:0] OPCODE;
input CLK;
//internal FSM state declarations, PS= Present state, NS=next state
reg[4:0] PS;
wire[4:0] NS;
//state encodings
parameter S0 = 5'b00000;
parameter S1 = 5'b00001;
parameter S2 = 5'b00010;
parameter S3 = 5'b00011;
parameter S4 = 5'b00100;
parameter S5 = 5'b00101;
parameter S6 = 5'b00110;
parameter S7 = 5'b00111;
parameter S8 = 5'b01000;
parameter S9 = 5'b01001;
parameter S10 = 5'b01010;
parameter S11 = 5'b01011;
parameter S12 = 5'b01100;
parameter S13 = 5'b01101;
parameter S14 = 5'b01110;
parameter S15 = 5'b01111;
parameter S16 = 5'b10000;
parameter S17 = 5'b10001;
parameter S18 = 5'b10010;
parameter S19 = 5'b10011;
wire[1:0] a;
wire[1:0] b;
wire c;
wire d;
wire[3:0] e;
assign a = OPCODE[7:6] ;
assign b = OPCODE[5:4] ;
assign c = OPCODE[3] ;
assign d = OPCODE[2] ;
assign e = OPCODE[7:4] ;
//combinational logic
function[19:0] fsm;
input[1:0] fsm_a;
input[1:0] fsm_b;
input fsm_c;
input fsm_d;
input[3:0] fsm_e;
input[4:0] fsm_PS;
input fsm_CMP;
reg[14:0] fsm_Z;
reg[4:0] fsm_NS;
begin
case (fsm_PS)
S0 :
begin
fsm_NS = S1 ;
fsm_Z = 15'b010000000000000 ;
end
S1 :
begin
fsm_NS = S2 ;
fsm_Z = 15'b000000000000000 ;
end
S2 :
begin
fsm_Z = 15'b101000000000000 ;
if (fsm_a == 2'b00 | fsm_a == 2'b01)
begin
fsm_NS = S3 ;
end
else if (fsm_a == 2'b10)
begin
fsm_NS = S10 ;
end
else if (fsm_a == 2'b11)
begin
fsm_NS = S19 ;
end
end
S3 :
begin
fsm_Z = 15'b000000000000000 ;
case (fsm_e)
4'b0000 :
begin
fsm_NS = S4 ;
end
4'b0001 :
begin
fsm_NS = S5 ;
end
4'b0010 :
begin
fsm_NS = S6 ;
end
4'b0011 :
begin
fsm_NS = S7 ;
end
4'b0100 :
begin
fsm_NS = S8 ;
end
default :
begin
fsm_NS = S9 ;
end
endcase
end
S4 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010001000 ;
end
else
begin
fsm_Z = 15'b000000001001000 ;
end
end
S5 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010001001 ;
end
else
begin
fsm_Z = 15'b000000001100001 ;
end
end
S6 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010001010 ;
end
else
begin
fsm_Z = 15'b000000001001010 ;
end
end
S7 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010001011 ;
end
else
begin
fsm_Z = 15'b000000001001011 ;
end
end
S8 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010000100 ;
end
else
begin
fsm_Z = 15'b000000001100100 ;
end
end
S9 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010000101 ;
end
else
begin
fsm_Z = 15'b000000001100101 ;
end
end
S10 :
begin
fsm_Z = 15'b000000000000110 ;
fsm_NS = S11 ;
end
S11 :
begin
fsm_Z = 15'b001000100000110 ;
case (fsm_b)
2'b00 :
begin
fsm_NS = S12 ;
end
2'b01 :
begin
fsm_NS = S15 ;
end
2'b10 :
begin
fsm_NS = S17 ;
end
default :
begin
fsm_NS = S18 ;
end
endcase
end
S12 :
begin
if (fsm_d == 1'b0)
begin
fsm_NS = S14 ;
fsm_Z = 15'b000000000000110 ;
end
else
begin
fsm_Z = 15'b000010000000110 ;
fsm_NS = S13 ;
end
end
S13 :
begin
fsm_NS = S14 ;
fsm_Z = 15'b000010100000110 ;
end
S14 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010010110 ;
end
else
begin
fsm_Z = 15'b000000001010110 ;
end
end
S15 :
begin
fsm_NS = S16 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000011000000110 ;
end
else
begin
fsm_Z = 15'b000011000100110 ;
end
end
S16 :
begin
fsm_NS = S1 ;
fsm_Z = 15'b000010000000110 ;
end
S17 :
begin
fsm_NS = S1 ;
fsm_Z = 15'b000100000010110 ;
end
S18 :
begin
fsm_NS = S1 ;
if (fsm_CMP == 1'b1)
begin
fsm_Z = 15'b000100000010110 ;
end
else
begin
fsm_Z = 15'b000000000000000 ;
end
end
S19 :
begin
fsm_NS = S1 ;
fsm_Z = 15'b000000000000000 ;
end
endcase
fsm = {fsm_Z, fsm_NS};
end
endfunction
//reevaluate combinational logic whenever opcode or Present state changes
assign {Z, NS}=fsm(a,b,c,d,e,PS,CMP);
//clock the state flip flop
always @(negedge CLK)
begin
if (reset == 1'b1)
PS = S0 ;
else
PS = NS ;
end
endmodule
thanks for helping !!!!
following code is written using Verilog:
//CU
module Controlunit (Z, reset, CMP, OPCODE, CLK);
output[14:0] Z;
wire[14:0] Z;
input reset;
input CMP;
input[7:0] OPCODE;
input CLK;
//internal FSM state declarations, PS= Present state, NS=next state
reg[4:0] PS;
wire[4:0] NS;
//state encodings
parameter S0 = 5'b00000;
parameter S1 = 5'b00001;
parameter S2 = 5'b00010;
parameter S3 = 5'b00011;
parameter S4 = 5'b00100;
parameter S5 = 5'b00101;
parameter S6 = 5'b00110;
parameter S7 = 5'b00111;
parameter S8 = 5'b01000;
parameter S9 = 5'b01001;
parameter S10 = 5'b01010;
parameter S11 = 5'b01011;
parameter S12 = 5'b01100;
parameter S13 = 5'b01101;
parameter S14 = 5'b01110;
parameter S15 = 5'b01111;
parameter S16 = 5'b10000;
parameter S17 = 5'b10001;
parameter S18 = 5'b10010;
parameter S19 = 5'b10011;
wire[1:0] a;
wire[1:0] b;
wire c;
wire d;
wire[3:0] e;
assign a = OPCODE[7:6] ;
assign b = OPCODE[5:4] ;
assign c = OPCODE[3] ;
assign d = OPCODE[2] ;
assign e = OPCODE[7:4] ;
//combinational logic
function[19:0] fsm;
input[1:0] fsm_a;
input[1:0] fsm_b;
input fsm_c;
input fsm_d;
input[3:0] fsm_e;
input[4:0] fsm_PS;
input fsm_CMP;
reg[14:0] fsm_Z;
reg[4:0] fsm_NS;
begin
case (fsm_PS)
S0 :
begin
fsm_NS = S1 ;
fsm_Z = 15'b010000000000000 ;
end
S1 :
begin
fsm_NS = S2 ;
fsm_Z = 15'b000000000000000 ;
end
S2 :
begin
fsm_Z = 15'b101000000000000 ;
if (fsm_a == 2'b00 | fsm_a == 2'b01)
begin
fsm_NS = S3 ;
end
else if (fsm_a == 2'b10)
begin
fsm_NS = S10 ;
end
else if (fsm_a == 2'b11)
begin
fsm_NS = S19 ;
end
end
S3 :
begin
fsm_Z = 15'b000000000000000 ;
case (fsm_e)
4'b0000 :
begin
fsm_NS = S4 ;
end
4'b0001 :
begin
fsm_NS = S5 ;
end
4'b0010 :
begin
fsm_NS = S6 ;
end
4'b0011 :
begin
fsm_NS = S7 ;
end
4'b0100 :
begin
fsm_NS = S8 ;
end
default :
begin
fsm_NS = S9 ;
end
endcase
end
S4 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010001000 ;
end
else
begin
fsm_Z = 15'b000000001001000 ;
end
end
S5 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010001001 ;
end
else
begin
fsm_Z = 15'b000000001100001 ;
end
end
S6 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010001010 ;
end
else
begin
fsm_Z = 15'b000000001001010 ;
end
end
S7 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010001011 ;
end
else
begin
fsm_Z = 15'b000000001001011 ;
end
end
S8 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010000100 ;
end
else
begin
fsm_Z = 15'b000000001100100 ;
end
end
S9 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010000101 ;
end
else
begin
fsm_Z = 15'b000000001100101 ;
end
end
S10 :
begin
fsm_Z = 15'b000000000000110 ;
fsm_NS = S11 ;
end
S11 :
begin
fsm_Z = 15'b001000100000110 ;
case (fsm_b)
2'b00 :
begin
fsm_NS = S12 ;
end
2'b01 :
begin
fsm_NS = S15 ;
end
2'b10 :
begin
fsm_NS = S17 ;
end
default :
begin
fsm_NS = S18 ;
end
endcase
end
S12 :
begin
if (fsm_d == 1'b0)
begin
fsm_NS = S14 ;
fsm_Z = 15'b000000000000110 ;
end
else
begin
fsm_Z = 15'b000010000000110 ;
fsm_NS = S13 ;
end
end
S13 :
begin
fsm_NS = S14 ;
fsm_Z = 15'b000010100000110 ;
end
S14 :
begin
fsm_NS = S1 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000000010010110 ;
end
else
begin
fsm_Z = 15'b000000001010110 ;
end
end
S15 :
begin
fsm_NS = S16 ;
if (fsm_c == 1'b0)
begin
fsm_Z = 15'b000011000000110 ;
end
else
begin
fsm_Z = 15'b000011000100110 ;
end
end
S16 :
begin
fsm_NS = S1 ;
fsm_Z = 15'b000010000000110 ;
end
S17 :
begin
fsm_NS = S1 ;
fsm_Z = 15'b000100000010110 ;
end
S18 :
begin
fsm_NS = S1 ;
if (fsm_CMP == 1'b1)
begin
fsm_Z = 15'b000100000010110 ;
end
else
begin
fsm_Z = 15'b000000000000000 ;
end
end
S19 :
begin
fsm_NS = S1 ;
fsm_Z = 15'b000000000000000 ;
end
endcase
fsm = {fsm_Z, fsm_NS};
end
endfunction
//reevaluate combinational logic whenever opcode or Present state changes
assign {Z, NS}=fsm(a,b,c,d,e,PS,CMP);
//clock the state flip flop
always @(negedge CLK)
begin
if (reset == 1'b1)
PS = S0 ;
else
PS = NS ;
end
endmodule
thanks for helping !!!!