Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I wish to incorporate a onehot decoder for my registers so that only one register is accessing the bus at a time. I also wish

I wish to incorporate a onehot decoder for my registers so that only one register is accessing the bus at a time. I also wish to introduce a memory system that uses a program counter to navigate through my memory. The memory is an address system that stores each instruction code.
This is what my current code looks like
module datapath (
input clk,
input rst,
input [15:0] instruction,
input [1:0] addSub
);
// Register enables and tristate buffers
wire [15:0] Rout;
wire [15:0] bus;
wire [15:0] myWire [15:0];
// Control circuit control_signal
controlcircuit control_signal (
.clk(clk),
.rst(rst),
.instruction(instruction),
.reg_enable(enableRegisterin),
.tri_enable(enableRegistersout)
);
// Register Generation
genvar i;
generate
for (i =0; i <8; i = i +1) begin: registerGeneration
// Registers
myreg regin (
.clock(clk),
.x(bus),
.enable(Rin[i]),
.y(myWire[i]),
.rst(rst)
);
// Tristate buffer
tristatebuffer regout (
.a(myWire[i]),
.enable(Rout[i]),
.b(bus)
);
end
// Register A
myreg regA (
.clock(clk),
.x(bus),
.enable(Rin[8]),
.y(myWire[8]),
.rst(rst)
);
// ALU
ALU alu (
.a(myWire[8]),
.b(bus),
.addSub(addSub),
.result(myWire[9])
);
// Register G
myreg regG (
.clock(clk),
.x(myWire[9]),
.enable(Rin[9]),
.y(myWire[10]),
.rst(rst)
);
// Tristate buffer for RegG output
tristatebuffer regGout (
.a(myWire[10]),
.enable(Rout[10]),
.b(bus)
);
endgenerate
endmodule
module myreg (
input clock,
input [15:0] x,
input enable,
output reg [15:0] y,
input rst
);
always @(posedge clock or posedge rst)
begin
if (rst)
y <=16'b0;
else if (enable)
y <= x;
end
endmodule
module ALU (
input [15:0] a,
input [15:0] b,
input [1:0] addSub,
output reg [15:0] result
);
always @(*)
begin
case (addSub)
2'b00: result = a + b; // add
2'b01: result = a - b; // subtract
2'b10: result = a ^ b; // xor
default: result =16'b0; // default to 0
endcase
end
endmodule
module Next_State (instruction,current_state,next_state);
input [15:0]instruction;
input [3:0]current_state;
output [3:0]reg next_state;
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;
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;
endmodule
module tristatebuffer (
input [15:0] a,
output reg [15:0] b,
input enable
);
always @(*)
begin
if (enable)
b = a;
else
b =16'bZ; // tri-state
end
endmodule
module tristateenable(state, instruction, Rin, Rout, addSub);
input [3:0] state;
input [15:0] instruction;
input [1:0] branch;
output [15:0] Rin, Rout;
output addSub;
wire[3:0] triReg, triRegEnable
oneHot writeDemux(.select(triReg),.out(triStateWire))
//Gout,Rout7-0
oneHot readDemux(.select(RegEnable),.out(triRegEnableWire))
//Gin,Ain,Rin7-Rin0
always@(state) begin
case(state)
4'0001: begin//load 1
//triReg =4'1010//Data trireg enable
RegEnable = instruction[11:8]//Rxin enable
branch =2'b00
end
4'1000: begin//load 2
triReg =4'1010//Data trireg enable
branch =2'b00
end
4'0010: begin//move
triReg = instruction[7:4]//Rxout
RegEnable = instruction[11:8]//Ryin
branch =2'00
end
4'0011: begin//add sub xor 1
triReg = instruction[11:8]//Rxout
RegEnable =4'1000//Ain
end
4'0100: begin// add sub xor 2
triReg = instruction[7:4]
RegEnable =4'1001
if (instruction[15:12]=4'b0011)
addSub =2'b01;
else if (instruction[15:12]=4'b0010)
addSub =2'b10;
else
addSub =2'b00;
end
4'0101: begin// add sub xor 3
triReg =4'1001
RegEnable = instruction[5:2]
module instruction_memory(address, data);
input [3:0] address;
output [15:0] data;
//have to grab instruction then grab number
//load 0000
//move 0001
//add 0010
//XOR 1000
//REG00000
//REG10001
always @(address) begin //hard coded instruction - not write to memory

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

Step: 3

blur-text-image

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

Learning PostgreSQL

Authors: Salahaldin Juba, Achim Vannahme, Andrey Volkov

1st Edition

178398919X, 9781783989195

Students also viewed these Databases questions