Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why doesn't my code load anything onto the registers. module Control _ Circuit ( input clk , input rst , input [ 1 5 :

Why doesn't my code load anything onto the registers.
module Control_Circuit (
input clk,
input rst,
input [15:0] instruction,
output [7:0] Rin,
output [7:0] Rout,
output [1:0] addSub
);
wire [3:0] current_state;
wire [3:0] next_state;
reg [3:0] state_reg;
// Instantiate Next_State FSM
Next_State fsm (
.instruction(instruction),
.current_state(current_state),
.next_state(next_state)
);
// Instantiate oneHot modules to generate Rin and Rout
oneHot rin_gen (
.select(next_state),
.out(Rin)
);
oneHot rout_gen (
.select(current_state),
.out(Rout)
);
// Register to hold the current state
always @(posedge clk or posedge rst) begin
if (rst)
state_reg <=4'b0000; // Initial state
else
state_reg <= next_state;
end
assign current_state = state_reg;
endmodule
module datapath (clk, rst, instruction, enableRegistersin, enableRegistersout, bus, myWire, addSub);
input clk, rst;
input [15:0] instruction;
input [15:0] enableRegistersin;
input [15:0] enableRegistersout;
input [1:0] addSub;
output [15:0] bus;
output [15:0] myWire;
genvar i;
generate
for (i =0; i <8; i = i +1) begin: registerGeneration
// Register R0-R7
myreg regin(
.clock(clk),
.x(bus),
.enable(enableRegistersin[i]),
.y(myWire[i]),
.rst(rst)
);
tristatebuffer regout(
.a(myWire[i]),
.enable(enableRegistersout[i]),
.b(bus)
);
end
endgenerate
// Register A
myreg regA (
.clock(clk),
.x(bus),
.enable(enableRegistersin[8]),
.y(myWire[8]),
.rst(rst)
);
// ALU
aLU alu (
.a(myWire[8]),
.b(bus),
.addSub(addSub[1:0]),// Assuming the ALU takes opcode from instruction
.result(myWire[9])
);
// Register G
myreg regG (
.clock(clk),
.x(myWire[9]),
.enable(enableRegistersin[9]),
.y(myWire[10]),
.rst(rst)
);
// Tristate buffer for RegG output
tristatebuffer regGout (
.a(myWire[10]),
.enable(enableRegistersout[10]),
.b(bus)
);
endmodule
module Next_State (
input [15:0] instruction,
input [3:0] current_state,
output reg [3:0] next_state
);
always @(*) begin
case (current_state)
4'b0000: begin
case (instruction[15:12])
4'b0000: next_state =4'b0001;
4'b0001: next_state =4'b0010;
4'b0010: next_state =4'b0011;
4'b0011: next_state =4'b0011;
4'b0100: next_state =4'b0011;
default: next_state =4'b0000; // default state if no match
endcase
end
4'b0001: next_state =4'b1000;
4'b1000: next_state =4'b0000;
4'b0010: next_state =4'b0000;
4'b0011: next_state =4'b0100;
4'b0100: next_state =4'b0101;
4'b0101: next_state =4'b0000;
default: next_state =4'b0000; // default state if no match
endcase
end
endmodule
module outputter (
input [3:0] state,
input [15:0] instruction,
output reg [15:0] Rin,
output reg [15:0] Rout,
output reg [1:0] addSub
);
reg [3:0] triReg, RegEnable;
// Wires for oneHot module outputs
wire [15:0] triStateWire, triRegEnableWire;
// Instantiate oneHot modules
oneHot writeDemux (
.select(triReg),
.out(triStateWire)
);
oneHot readDemux (
.select(RegEnable),
.out(triRegEnableWire)
);
// Assignments to the outputs
always @(state or instruction) begin
case(state)
4'b0001: begin // load 1
triReg =4'b0000; // No output enable in this state
RegEnable = instruction[11:8]; // Rxin enable
end
4'b1000: begin // load 2
triReg =4'b1010; // Data triReg enable
RegEnable =4'b0000; // No register enable in this state
end
4'b0010: begin // move
triReg = instruction[7:4]; // Rxout
RegEnable = instruction[11:8]; // Ryin
end
4'b0011: begin // add sub xor 1
triReg = instruction[11:8]; // Rxout
RegEnable =4'b1000; // Ain
end
4'b0100: begin // add sub xor 2
triReg = instruction[7:4]; // Ryout
RegEnable =4'b1001; // Gin
if (instruction[15:12]==4'b0011)
addSub =2'b01; // sub
else if (instruction[15:12]==4'b0010)
addSub =2'b10; // xor
else
addSub =2'b00; // add
end
4'b0101: begin // add sub xor 3
triReg =4'b1001; // Gout
RegEnable = instruction[5:2]; // Ryin
addSu

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions