BSCpE V GF
1. Finite State Machine
if (data_in)
state <= S3;
else
state <= S2;
S3:
if (data_in)
state <= S4;
else
state <= S2;
S4:
if (data_in)
state <= S1;
else
state <= S2;
endcase // case (state)
end // always @ (posedge clk or
posedge reset)
// Output depends only on the
state
always @ (state) begin
case (state)
S0:
data_out = 1'b0;
S1:
data_out = 1'b1;
S2:
data_out = 1'b0;
S3:
data_out = 1'b1;
S4:
data_out = 1'b1;
default:
data_out = 1'b0;
endcase // case (state)
end // always @ (state)
endmodule // moore_mac
FUNCTIONS
A. Moore: a Moore machine is a finite-state machine whose output values are
determined solely by its current state. This is in contrast to a Mealy machine, whose
output values are determined both by its current state and by the values of its inputs.
B. Mealy: a Mealy machine is a finite-state machine whose output values are
determined both by its current state and the current inputs. A Mealy machine is
a deterministic finite-state transducer: for each state and input, at most one transition
is possible.
2. Memory Blocks
Verilog Code:
module raminfr (clk, en, we, addr, di, do);
input
clk;
input
we;
input
en;
input [4:0] addr;
input [3:0] di;
if (we)
RAM[addr] <= di;
end
end
endmodule
do <= RAM[addr];
Functions:
The Memory block holds and delays its input by one major integration time step.
When placed in an iterator subsystem, it holds and delays its input by one iteration. This
block accepts continuous and discrete signals. The block accepts one input and
generates one output. Each signal can be scalar or vector. If the input is a vector, the
block holds and delays all elements of the vector by the same time step.
You specify the block output for the first time step using the Initial condition parameter.
Careful selection of this parameter can minimize unwanted output behavior. However,
you cannot specify the sample time. This block's sample time depends on the type of
solver used, or you can specify to inherit it. The Inherit sample time parameter
determines whether sample time is inherited or based on the solver.
System Overview:
3. Control Unit
Functions:
Control Unit (CU) is generally a sizable collection of complex digital circuitry
interconnecting and controlling the many execution units contained within a CPU. The
CU is normally the first CPU unit to accept from an externally stored computer program,
a single instruction. The CU then decodes this individual instruction into several
sequential that controls and coordinates the CPU's inner works to properly manipulate
the data. The design of these sequential steps are based on the needs of each
instruction and can range in number of steps, the order of execution, and which units are
enabled. Thus by only using a program of set instructions in memory, the CU will
configure all the CPU's data flows as needed to manipulate the data correctly between
instructions. This results in a computer that could run a complete program and requiring
no human intervention to make hardware changes between instructions (as had to be
done when using only punch cards for computations before stored programmed
computers with CUs where invented). These detailed steps from the CU dictate which of
the CPU's interconnecting hardware control signals to enable/disable or which CPU units
are selected/de-selected and the unit's proper order of execution as required by the
instruction's operation to produce the desired manipulated data.
4. MIPS Singlecycle Processor
Verilog Code
input clk ;
input[31:0] instruction ;
reg[31:0] npc;
input zero ;
input jump ;
input branch ;
wire[31:0] pcInc;
wire[31:0] Branch1 ;
wire[15:0] address;
wire[31:0] branchAdd;
reg[31:0] mux1;
wire select1 ;
wire[31:0] jumpAdd ;
output [31:0] pc ;
reg [31:0] pc ;
Functions:
System Overview:
Verilog Code:
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0010;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0110;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0000;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0001;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b1)) begin Operation <= 4'b0111;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b1100;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0011;
end
if
end
if
end
if
end
if
end
end
endmodule
Functions:
Verilog Code
module logic_unit(d_out1,logic_u
nit,s0,s1,c0,A,B);
output [3:0] d_out1;
input s0,s1,c0,logic_unit;
input [3:0] A;
input [3:0] B;
reg [3:0] d_out1;
always @(s0,s1,A,B,logic_unit)
begin
if(logic_unit== 1'b1)
begin
begin
begin
d_out1 = ( A | B);
end
else
begin
d_out1 = ( A ^~ B);
end
end
else
begin
d_out1 = 4'b0000;
end
end
end
module
arithmetic(d_out,A,B,cout,arithm
etic_unit,s0,s1,c0,M);
inout [3:0] d_out;
output cout;
input s0,s1,c0,M,arithmetic_unit;
input [3:0] A,B;wire [3:0] d_out;
reg cout;
wire s0,s1,c0,M,arithmetic_unit;
wire [3:0] A,B;wire [3:0]D1;
wire D0;
wire [3:0]L1;
wire L0;
wire [3:0]K1;
wire K0;
reg [3:0] d_out2;
reg [3:0] temp;
reg en;
assign {D0,D1} = A + B;
assign {L0,L1} = (A + (~B));
assign {K0,K1} = ((~A) + B);
assign d_out = d_out2;
always
@(s0,s1,c0,arithmetic_unit)
begin
if(arithmetic_unit)beginif(s1
== 1'b0 & s0 == 1'b0 & c0 == 1'b0)
begin
d_out2 = A;
end
d_out2 = A + 1'b1;
end
d_out2 = D1;
cout = D0;
end
d_out2 = D1 + 1'b1;
cout = D0;
end
d_out2 = L1;
cout = L0;
end
d_out2 = L1 + 1'b1;
cout = L0;
end
d_out2 = K1;
cout = K0;
end
else begin
d_out2 = K1 + 1'b1;
cout = K0;
end
end
else
begin
d_out2 = 4'b0000;
end
end
endmodule`timescale 1ns /
1ps
module
alu(CRY_OUT,DATA_OUT,CRY_
IN,DATA_IN1,DATA_IN2,SEL1,S
EL2,MODE);
output CRY_OUT;
output [3:0] DATA_OUT;
input CRY_IN;
input [3:0] DATA_IN1,DATA_IN2;
input SEL1,SEL2,MODE;
reg logic_unit;
reg arithmetic_unit;
wire [3:0] DATA_OUT1;
.s0(SEL1),
.s1(SEL2),
.c0(CRY_IN),
.A(DATA_IN1),
.B(DATA_IN2),
.
logic_unit(logic_unit));
arithmetic
arithmetic_ins(.d_out(DATA_OU
T1),
.cout(CRY_OUT),
.s0(SEL1),
.s1(SEL2),
.A(DATA_IN1),
.B(DATA_IN2),
.c0(CRY_IN),
.M(MODE),
.
arithmetic_unit(arithmetic_unit));
always @(SEL1,SEL2,MODE)
begin
if(MODE == 1'b0)
begin
logic_unit = 1'b1;
arithmetic_unit = 1'b0;
end
else begin
logic_unit = 1'b0;
arithmetic_unit = 1'b1;
end
end
endmodule
7.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58. Titan, Jan Jennifer C.
59. BSCpE V-GF
1. Finite State Machine
(
input clk, data_in, reset,
output reg data_out
);
// Declare state register
reg
[2:0]state;
// Declare states
parameter S0 = 0, S1 = 1, S2
= 2, S3 = 3, S4 = 4;
// Determine the next state
if (data_in)
state <= S3;
else
state <= S2;
S3:
if (data_in)
state <= S4;
else
state <= S2;
63.
64.
65.
66.
67.
S4:
if (data_in)
state <= S1;
else
state <= S2;
endcase // case (state)
end // always @ (posedge clk or
posedge reset)
// Output depends only on the
state
always @ (state) begin
case (state)
S0:
data_out = 1'b0;
S1:
data_out = 1'b1;
S2:
data_out = 1'b0;
S3:
data_out = 1'b1;
S4:
data_out = 1'b1;
default:
data_out = 1'b0;
endcase // case (state)
end // always @ (state)
endmodule // moore_mac
68.
FUNCTIONS
C. Moore: a Moore machine is a finite-state machine whose output values are
determined solely by its current state. This is in contrast to a Mealy machine, whose
output values are determined both by its current state and by the values of its inputs.
D. Mealy: a Mealy machine is a finite-state machine whose output values are
determined both by its current state and the current inputs. A Mealy machine is
a deterministic finite-state transducer: for each state and input, at most one transition
is possible.
69.
70.
2. Memory Blocks
Verilog Code:
71. module raminfr (clk, en, we, addr, di,
do);
72. input
clk;
73. input
we;
74. input
en;
75. input [4:0] addr;
76. input [3:0] di;
77. output [3:0] do;
78. reg [3:0] RAM [31:0];
79. reg [3:0] do;
90.
Functions:
91.
The Memory block holds and delays its input by one major integration
time step. When placed in an iterator subsystem, it holds and delays its input by one
iteration. This block accepts continuous and discrete signals. The block accepts one
input and generates one output. Each signal can be scalar or vector. If the input is a
vector, the block holds and delays all elements of the vector by the same time step.
92.
You specify the block output for the first time step using the Initial
condition parameter. Careful selection of this parameter can minimize unwanted output
behavior. However, you cannot specify the sample time. This block's sample time
depends on the type of solver used, or you can specify to inherit it. The Inherit sample
time parameter determines whether sample time is inherited or based on the solver.
System Overview:
93.
3. Control Unit
94.
Functions:
95.
Control Unit (CU) is generally a sizable collection of complex digital
circuitry interconnecting and controlling the many execution units contained within a
CPU. The CU is normally the first CPU unit to accept from an externally stored computer
program, a single instruction. The CU then decodes this individual instruction into
several sequential that controls and coordinates the CPU's inner works to properly
manipulate the data. The design of these sequential steps are based on the needs of
each instruction and can range in number of steps, the order of execution, and which
units are enabled. Thus by only using a program of set instructions in memory, the CU
will configure all the CPU's data flows as needed to manipulate the data correctly
between instructions. This results in a computer that could run a complete program and
requiring no human intervention to make hardware changes between instructions (as
had to be done when using only punch cards for computations before stored
programmed computers with CUs where invented). These detailed steps from the CU
dictate which of the CPU's interconnecting hardware control signals to enable/disable or
which CPU units are selected/de-selected and the unit's proper order of execution as
required by the instruction's operation to produce the desired manipulated data.
96.
4. MIPS Singlecycle Processor
Verilog Code
97.
98. module PC(clk , instruction , zero ,
branch , jump , pc );
99. input clk ;
100.
101.
102.
103.
104.
105.
106.
input[31:0] instruction ;
reg[31:0] npc;
input zero ;
input jump ;
input branch ;
125. begin
126.
if ( select1 == 1 )
127.
mux1 = branchAdd ;
128.
else
129.
mux1 = pcInc ;
130. end
131.
132. assign jumpAdd = ( instruction[25:0]
<< 2 );
133.
134. always@ ( jump or jumpAdd or
mux1 )
135. begin
136.
if ( jump == 1 )
137.
npc = jumpAdd ;
138.
else
139.
npc = mux1;
140. end
141.
142. always @(posedge clk )
143.
pc <= npc;
144. endmodule
Functions:
System Overview:
Verilog Code:
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0010;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0110;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0000;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0001;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b1)) begin Operation <= 4'b0111;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b1100;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0011;
end
if
end
if
end
if
end
if
end
end
endmodule
Functions:
Verilog Code
module logic_unit(d_out1,logic_u
nit,s0,s1,c0,A,B);
output [3:0] d_out1;
input s0,s1,c0,logic_unit;
input [3:0] A;
input [3:0] B;
reg [3:0] d_out1;
always @(s0,s1,A,B,logic_unit)
begin
if(logic_unit== 1'b1)
begin
begin
begin
d_out1 = ( A | B);
end
else
begin
d_out1 = ( A ^~ B);
end
end
else
begin
d_out1 = 4'b0000;
end
end
end
input s0,s1,c0,M,arithmetic_unit;
input [3:0] A,B;wire [3:0] d_out;
reg cout;
wire s0,s1,c0,M,arithmetic_unit;
wire [3:0] A,B;wire [3:0]D1;
wire D0;
wire [3:0]L1;
wire L0;
wire [3:0]K1;
wire K0;
reg [3:0] d_out2;
reg [3:0] temp;
reg en;
assign {D0,D1} = A + B;
assign {L0,L1} = (A + (~B));
assign {K0,K1} = ((~A) + B);
assign d_out = d_out2;
always
@(s0,s1,c0,arithmetic_unit)
begin
if(arithmetic_unit)beginif(s1
== 1'b0 & s0 == 1'b0 & c0 == 1'b0)
begin
d_out2 = A;
end
d_out2 = A + 1'b1;
end
d_out2 = D1;
cout = D0;
end
d_out2 = D1 + 1'b1;
cout = D0;
end
d_out2 = L1;
cout = L0;
end
d_out2 = L1 + 1'b1;
cout = L0;
end
d_out2 = K1;
cout = K0;
end
else begin
d_out2 = K1 + 1'b1;
cout = K0;
end
end
else
begin
d_out2 = 4'b0000;
end
end
endmodule`timescale 1ns /
1ps
module
alu(CRY_OUT,DATA_OUT,CRY_
IN,DATA_IN1,DATA_IN2,SEL1,S
EL2,MODE);
output CRY_OUT;
output [3:0] DATA_OUT;
input CRY_IN;
input [3:0] DATA_IN1,DATA_IN2;
input SEL1,SEL2,MODE;
reg logic_unit;
reg arithmetic_unit;
wire [3:0] DATA_OUT1;
wire [3:0] DATA_OUT2;
assign DATA_OUT = (MODE ?
DATA_OUT1 : DATA_OUT2);
logic_unit logic_unit_ins(.d_out1(
DATA_OUT2),
.s0(SEL1),
.s1(SEL2),
.c0(CRY_IN),
.A(DATA_IN1),
.B(DATA_IN2),
.
logic_unit(logic_unit));
arithmetic
arithmetic_ins(.d_out(DATA_OU
T1),
.cout(CRY_OUT),
.s0(SEL1),
.s1(SEL2),
.A(DATA_IN1),
.B(DATA_IN2),
.c0(CRY_IN),
.M(MODE),
.
arithmetic_unit(arithmetic_unit));
always @(SEL1,SEL2,MODE)
begin
if(MODE == 1'b0)
begin
logic_unit = 1'b1;
arithmetic_unit = 1'b0;
end
else begin
logic_unit = 1'b0;
arithmetic_unit = 1'b1;
end
end
endmodule
7.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
End
Endmodule
(
input clk, data_in, reset,
output reg data_out
);
// Declare state register
reg
[2:0]state;
// Declare states
parameter S0 = 0, S1 = 1, S2
= 2, S3 = 3, S4 = 4;
// Determine the next state
if (data_in)
state <= S3;
else
state <= S2;
S3:
if (data_in)
state <= S4;
else
state <= S2;
70.
71.
72.
73.
74.
S4:
if (data_in)
state <= S1;
else
state <= S2;
endcase // case (state)
end // always @ (posedge clk or
posedge reset)
// Output depends only on the
state
always @ (state) begin
case (state)
S0:
data_out = 1'b0;
S1:
data_out = 1'b1;
S2:
data_out = 1'b0;
S3:
data_out = 1'b1;
S4:
data_out = 1'b1;
default:
data_out = 1'b0;
endcase // case (state)
end // always @ (state)
endmodule // moore_mac
75.
FUNCTIONS
E. Moore: a Moore machine is a finite-state machine whose output values are
determined solely by its current state. This is in contrast to a Mealy machine, whose
output values are determined both by its current state and by the values of its inputs.
F. Mealy: a Mealy machine is a finite-state machine whose output values are
determined both by its current state and the current inputs. A Mealy machine is
a deterministic finite-state transducer: for each state and input, at most one transition
is possible.
76.
77.
146. Memory Blocks
Verilog Code:
78. module raminfr (clk, en, we, addr, di,
do);
79. input
clk;
80. input
we;
81. input
en;
82. input [4:0] addr;
83. input [3:0] di;
84. output [3:0] do;
85. reg [3:0] RAM [31:0];
86. reg [3:0] do;
97.
Functions:
98.
The Memory block holds and delays its input by one major integration
time step. When placed in an iterator subsystem, it holds and delays its input by one
iteration. This block accepts continuous and discrete signals. The block accepts one
input and generates one output. Each signal can be scalar or vector. If the input is a
vector, the block holds and delays all elements of the vector by the same time step.
99.
You specify the block output for the first time step using the Initial
condition parameter. Careful selection of this parameter can minimize unwanted output
behavior. However, you cannot specify the sample time. This block's sample time
depends on the type of solver used, or you can specify to inherit it. The Inherit sample
time parameter determines whether sample time is inherited or based on the solver.
System Overview:
100.
147. Control Unit
101.
Functions:
102. Control Unit (CU) is generally a sizable collection of complex digital
circuitry interconnecting and controlling the many execution units contained within a
CPU. The CU is normally the first CPU unit to accept from an externally stored computer
program, a single instruction. The CU then decodes this individual instruction into
several sequential that controls and coordinates the CPU's inner works to properly
manipulate the data. The design of these sequential steps are based on the needs of
each instruction and can range in number of steps, the order of execution, and which
units are enabled. Thus by only using a program of set instructions in memory, the CU
will configure all the CPU's data flows as needed to manipulate the data correctly
between instructions. This results in a computer that could run a complete program and
requiring no human intervention to make hardware changes between instructions (as
had to be done when using only punch cards for computations before stored
programmed computers with CUs where invented). These detailed steps from the CU
dictate which of the CPU's interconnecting hardware control signals to enable/disable or
which CPU units are selected/de-selected and the unit's proper order of execution as
required by the instruction's operation to produce the desired manipulated data.
103.
148. MIPS Singlecycle Processor
Verilog Code
104.
105.
module PC(clk , instruction ,
zero , branch , jump , pc );
106.
input clk ;
107.
108.
109.
110.
111.
112.
113.
input[31:0] instruction ;
reg[31:0] npc;
input zero ;
input jump ;
input branch ;
114.
wire[31:0] pcInc;
115.
wire[31:0] Branch1 ;
116.
wire[15:0] address;
117.
wire[31:0] branchAdd;
118.
reg[31:0] mux1;
119.
wire select1 ;
120.
wire[31:0] jumpAdd ;
121.
output [31:0] pc ;
122.
reg [31:0] pc ;
123.
124.
125.
assign select1 = branch &
zero ;
126.
assign pcInc = pc + 4 ;
127.
assign address =
instruction[15:0];
128.
assign Branch1 =
{{16{address[15]}},address[15:0]} ; /
/ sign extension
129.
assign branchAdd = pcInc + (
branch << 2 ) ;
130.
131.
always@( branchAdd or
pcInc or select1 )
132.
begin
133.
if ( select1 == 1 )
134.
mux1 = branchAdd ;
135.
else
136.
mux1 = pcInc ;
137.
end
138.
139.
assign jumpAdd =
( instruction[25:0] << 2 );
140.
141.
always@ ( jump or jumpAdd
or mux1 )
142.
begin
143.
if ( jump == 1 )
144.
npc = jumpAdd ;
145.
else
146.
npc = mux1;
147.
end
148.
149.
always @(posedge clk )
150.
pc <= npc;
151.
endmodule
Functions:
System Overview:
Verilog Code:
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0010;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0110;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0000;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0001;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b1)) begin Operation <= 4'b0111;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b1100;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0011;
end
if
end
if
end
if
end
if
end
end
endmodule
Functions:
Verilog Code
module logic_unit(d_out1,logic_u
nit,s0,s1,c0,A,B);
output [3:0] d_out1;
input s0,s1,c0,logic_unit;
input [3:0] A;
input [3:0] B;
reg [3:0] d_out1;
always @(s0,s1,A,B,logic_unit)
begin
if(logic_unit== 1'b1)
begin
begin
begin
d_out1 = ( A | B);
end
else
begin
d_out1 = ( A ^~ B);
end
end
else
begin
d_out1 = 4'b0000;
end
end
end
module
arithmetic(d_out,A,B,cout,arithm
etic_unit,s0,s1,c0,M);
inout [3:0] d_out;
output cout;
input s0,s1,c0,M,arithmetic_unit;
input [3:0] A,B;wire [3:0] d_out;
reg cout;
wire s0,s1,c0,M,arithmetic_unit;
wire [3:0] A,B;wire [3:0]D1;
wire D0;
wire [3:0]L1;
wire L0;
wire [3:0]K1;
wire K0;
reg [3:0] d_out2;
reg [3:0] temp;
reg en;
assign {D0,D1} = A + B;
assign {L0,L1} = (A + (~B));
assign {K0,K1} = ((~A) + B);
assign d_out = d_out2;
always
@(s0,s1,c0,arithmetic_unit)
begin
if(arithmetic_unit)beginif(s1
== 1'b0 & s0 == 1'b0 & c0 == 1'b0)
begin
d_out2 = A;
end
d_out2 = A + 1'b1;
end
d_out2 = D1;
cout = D0;
end
d_out2 = D1 + 1'b1;
cout = D0;
end
d_out2 = L1;
cout = L0;
end
d_out2 = L1 + 1'b1;
cout = L0;
end
d_out2 = K1;
cout = K0;
end
else begin
d_out2 = K1 + 1'b1;
cout = K0;
end
end
else
begin
d_out2 = 4'b0000;
end
end
endmodule`timescale 1ns /
1ps
module
alu(CRY_OUT,DATA_OUT,CRY_
IN,DATA_IN1,DATA_IN2,SEL1,S
EL2,MODE);
output CRY_OUT;
output [3:0] DATA_OUT;
input CRY_IN;
input [3:0] DATA_IN1,DATA_IN2;
input SEL1,SEL2,MODE;
reg logic_unit;
reg arithmetic_unit;
wire [3:0] DATA_OUT1;
.s0(SEL1),
.s1(SEL2),
.c0(CRY_IN),
.A(DATA_IN1),
.B(DATA_IN2),
.
logic_unit(logic_unit));
arithmetic
arithmetic_ins(.d_out(DATA_OU
T1),
.cout(CRY_OUT),
.s0(SEL1),
.s1(SEL2),
.A(DATA_IN1),
.B(DATA_IN2),
.c0(CRY_IN),
.M(MODE),
.
arithmetic_unit(arithmetic_unit));
always @(SEL1,SEL2,MODE)
begin
if(MODE == 1'b0)
begin
logic_unit = 1'b1;
arithmetic_unit = 1'b0;
end
else begin
logic_unit = 1'b0;
arithmetic_unit = 1'b1;
end
end
endmodule
151.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
if (reset)
state <= S0;
else
case (state)
S0:
if (data_in)
state <= S1;
else
state <= S0;
S1:
if (data_in)
state <= S1;
else
state <= S2;
S2:
192.
193.
194.
if (data_in)
state <= S3;
else
state <= S2;
S3:
if (data_in)
data_out = 1'b0;
S1:
data_out = 1'b1;
S2:
data_out = 1'b0;
S3:
data_out = 1'b1;
S4:
data_out = 1'b1;
default:
data_out = 1'b0;
endcase // case (state)
end // always @ (state)
endmodule // moore_mac
200.
FUNCTIONS
G. Moore: a Moore machine is a finite-state machine whose output values are
determined solely by its current state. This is in contrast to a Mealy machine, whose
output values are determined both by its current state and by the values of its inputs.
H. Mealy: a Mealy machine is a finite-state machine whose output values are
determined both by its current state and the current inputs. A Mealy machine is
a deterministic finite-state transducer: for each state and input, at most one transition
is possible.
201.
202.
2. Memory Blocks
Verilog Code:
203. module raminfr (clk, en, we, addr, di,
do);
204. input
clk;
205. input
we;
206. input
en;
207. input [4:0] addr;
208. input [3:0] di;
209. output [3:0] do;
210. reg [3:0] RAM [31:0];
211. reg [3:0] do;
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
Functions:
223. The Memory block holds and delays its input by one major integration
time step. When placed in an iterator subsystem, it holds and delays its input by one
iteration. This block accepts continuous and discrete signals. The block accepts one
input and generates one output. Each signal can be scalar or vector. If the input is a
vector, the block holds and delays all elements of the vector by the same time step.
224. You specify the block output for the first time step using the Initial
condition parameter. Careful selection of this parameter can minimize unwanted output
behavior. However, you cannot specify the sample time. This block's sample time
depends on the type of solver used, or you can specify to inherit it. The Inherit sample
time parameter determines whether sample time is inherited or based on the solver.
System Overview:
225.
3. Control Unit
226.
Functions:
227. Control Unit (CU) is generally a sizable collection of complex digital
circuitry interconnecting and controlling the many execution units contained within a
CPU. The CU is normally the first CPU unit to accept from an externally stored computer
program, a single instruction. The CU then decodes this individual instruction into
several sequential that controls and coordinates the CPU's inner works to properly
manipulate the data. The design of these sequential steps are based on the needs of
each instruction and can range in number of steps, the order of execution, and which
units are enabled. Thus by only using a program of set instructions in memory, the CU
will configure all the CPU's data flows as needed to manipulate the data correctly
between instructions. This results in a computer that could run a complete program and
requiring no human intervention to make hardware changes between instructions (as
had to be done when using only punch cards for computations before stored
programmed computers with CUs where invented). These detailed steps from the CU
dictate which of the CPU's interconnecting hardware control signals to enable/disable or
which CPU units are selected/de-selected and the unit's proper order of execution as
required by the instruction's operation to produce the desired manipulated data.
228.
4. MIPS Singlecycle Processor
Verilog Code
229.
230. module PC(clk , instruction , zero ,
branch , jump , pc );
231. input clk ;
232.
233.
234.
235.
236.
237.
238.
input[31:0] instruction ;
reg[31:0] npc;
input zero ;
input jump ;
input branch ;
257. begin
258.
if ( select1 == 1 )
259.
mux1 = branchAdd ;
260.
else
261.
mux1 = pcInc ;
262. end
263.
264. assign jumpAdd = ( instruction[25:0]
<< 2 );
265.
266. always@ ( jump or jumpAdd or
mux1 )
267. begin
268.
if ( jump == 1 )
269.
npc = jumpAdd ;
270.
else
271.
npc = mux1;
272. end
273.
274. always @(posedge clk )
275.
pc <= npc;
276. endmodule
Functions:
System Overview:
Verilog Code:
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0010;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0110;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0000;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0001;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b1)) begin Operation <= 4'b0111;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b1100;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0011;
end
if
end
if
end
if
end
if
end
end
endmodule
Functions:
Verilog Code
module logic_unit(d_out1,logic_u
nit,s0,s1,c0,A,B);
output [3:0] d_out1;
input s0,s1,c0,logic_unit;
input [3:0] A;
input [3:0] B;
reg [3:0] d_out1;
always @(s0,s1,A,B,logic_unit)
begin
if(logic_unit== 1'b1)
begin
begin
begin
d_out1 = ( A | B);
end
else
begin
d_out1 = ( A ^~ B);
end
end
else
begin
d_out1 = 4'b0000;
end
end
end
input s0,s1,c0,M,arithmetic_unit;
input [3:0] A,B;wire [3:0] d_out;
reg cout;
wire s0,s1,c0,M,arithmetic_unit;
wire [3:0] A,B;wire [3:0]D1;
wire D0;
wire [3:0]L1;
wire L0;
wire [3:0]K1;
wire K0;
reg [3:0] d_out2;
reg [3:0] temp;
reg en;
assign {D0,D1} = A + B;
assign {L0,L1} = (A + (~B));
assign {K0,K1} = ((~A) + B);
assign d_out = d_out2;
always
@(s0,s1,c0,arithmetic_unit)
begin
if(arithmetic_unit)beginif(s1
== 1'b0 & s0 == 1'b0 & c0 == 1'b0)
begin
d_out2 = A;
end
d_out2 = A + 1'b1;
end
d_out2 = D1;
cout = D0;
end
d_out2 = D1 + 1'b1;
cout = D0;
end
d_out2 = L1;
cout = L0;
end
d_out2 = L1 + 1'b1;
cout = L0;
end
d_out2 = K1;
cout = K0;
end
else begin
d_out2 = K1 + 1'b1;
cout = K0;
end
end
else
begin
d_out2 = 4'b0000;
end
end
endmodule`timescale 1ns /
1ps
module
alu(CRY_OUT,DATA_OUT,CRY_
IN,DATA_IN1,DATA_IN2,SEL1,S
EL2,MODE);
output CRY_OUT;
output [3:0] DATA_OUT;
input CRY_IN;
input [3:0] DATA_IN1,DATA_IN2;
input SEL1,SEL2,MODE;
reg logic_unit;
reg arithmetic_unit;
wire [3:0] DATA_OUT1;
wire [3:0] DATA_OUT2;
assign DATA_OUT = (MODE ?
DATA_OUT1 : DATA_OUT2);
logic_unit logic_unit_ins(.d_out1(
DATA_OUT2),
.s0(SEL1),
.s1(SEL2),
.c0(CRY_IN),
.A(DATA_IN1),
.B(DATA_IN2),
.
logic_unit(logic_unit));
arithmetic
arithmetic_ins(.d_out(DATA_OU
T1),
.cout(CRY_OUT),
.s0(SEL1),
.s1(SEL2),
.A(DATA_IN1),
.B(DATA_IN2),
.c0(CRY_IN),
.M(MODE),
.
arithmetic_unit(arithmetic_unit));
always @(SEL1,SEL2,MODE)
begin
if(MODE == 1'b0)
begin
logic_unit = 1'b1;
arithmetic_unit = 1'b0;
end
else begin
logic_unit = 1'b0;
arithmetic_unit = 1'b1;
end
end
endmodule
7.
33.
34.
35.
End
Endmodule
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58. Hepana, Jerome V.
59. BSCpE V GF
1. Finite State Machine
if (data_in)
state <= S3;
else
state <= S2;
S3:
if (data_in)
state <= S4;
else
state <= S2;
S4:
if (data_in)
state <= S1;
else
63.
64.
65.
66.
67.
68.
FUNCTIONS
I.
Verilog Code:
71. module raminfr (clk, en, we, addr, di,
do);
72. input
clk;
73. input
we;
74. input
en;
75. input [4:0] addr;
76. input [3:0] di;
77. output [3:0] do;
78. reg [3:0] RAM [31:0];
79. reg [3:0] do;
90.
Functions:
91.
The Memory block holds and delays its input by one major integration
time step. When placed in an iterator subsystem, it holds and delays its input by one
iteration. This block accepts continuous and discrete signals. The block accepts one
input and generates one output. Each signal can be scalar or vector. If the input is a
vector, the block holds and delays all elements of the vector by the same time step.
92.
You specify the block output for the first time step using the Initial
condition parameter. Careful selection of this parameter can minimize unwanted output
behavior. However, you cannot specify the sample time. This block's sample time
depends on the type of solver used, or you can specify to inherit it. The Inherit sample
time parameter determines whether sample time is inherited or based on the solver.
System Overview:
93.
3. Control Unit
94.
Functions:
95.
Control Unit (CU) is generally a sizable collection of complex digital
circuitry interconnecting and controlling the many execution units contained within a
CPU. The CU is normally the first CPU unit to accept from an externally stored computer
program, a single instruction. The CU then decodes this individual instruction into
several sequential that controls and coordinates the CPU's inner works to properly
manipulate the data. The design of these sequential steps are based on the needs of
each instruction and can range in number of steps, the order of execution, and which
units are enabled. Thus by only using a program of set instructions in memory, the CU
will configure all the CPU's data flows as needed to manipulate the data correctly
between instructions. This results in a computer that could run a complete program and
requiring no human intervention to make hardware changes between instructions (as
had to be done when using only punch cards for computations before stored
programmed computers with CUs where invented). These detailed steps from the CU
dictate which of the CPU's interconnecting hardware control signals to enable/disable or
which CPU units are selected/de-selected and the unit's proper order of execution as
required by the instruction's operation to produce the desired manipulated data.
96.
4. MIPS Singlecycle Processor
Verilog Code
97.
98. module PC(clk , instruction , zero ,
branch , jump , pc );
99. input clk ;
100.
101.
102.
103.
104.
105.
106.
input[31:0] instruction ;
reg[31:0] npc;
input zero ;
input jump ;
input branch ;
125. begin
126.
if ( select1 == 1 )
127.
mux1 = branchAdd ;
128.
else
129.
mux1 = pcInc ;
130. end
131.
132. assign jumpAdd = ( instruction[25:0]
<< 2 );
133.
134. always@ ( jump or jumpAdd or
mux1 )
135. begin
136.
if ( jump == 1 )
137.
npc = jumpAdd ;
138.
else
139.
npc = mux1;
140. end
141.
142. always @(posedge clk )
143.
pc <= npc;
144. endmodule
Functions:
System Overview:
Verilog Code:
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0010;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0110;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0000;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0001;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b1)) begin Operation <= 4'b0111;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b1100;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0011;
end
if
end
if
end
if
end
if
end
end
endmodule
Functions:
Verilog Code
module logic_unit(d_out1,logic_u
nit,s0,s1,c0,A,B);
output [3:0] d_out1;
input s0,s1,c0,logic_unit;
input [3:0] A;
input [3:0] B;
reg [3:0] d_out1;
always @(s0,s1,A,B,logic_unit)
begin
if(logic_unit== 1'b1)
begin
begin
begin
d_out1 = ( A | B);
end
else
begin
d_out1 = ( A ^~ B);
end
end
else
begin
d_out1 = 4'b0000;
end
end
end
input s0,s1,c0,M,arithmetic_unit;
input [3:0] A,B;wire [3:0] d_out;
reg cout;
wire s0,s1,c0,M,arithmetic_unit;
wire [3:0] A,B;wire [3:0]D1;
wire D0;
wire [3:0]L1;
wire L0;
wire [3:0]K1;
wire K0;
reg [3:0] d_out2;
reg [3:0] temp;
reg en;
assign {D0,D1} = A + B;
assign {L0,L1} = (A + (~B));
assign {K0,K1} = ((~A) + B);
assign d_out = d_out2;
always
@(s0,s1,c0,arithmetic_unit)
begin
if(arithmetic_unit)beginif(s1
== 1'b0 & s0 == 1'b0 & c0 == 1'b0)
begin
d_out2 = A;
end
d_out2 = A + 1'b1;
end
d_out2 = D1;
cout = D0;
end
d_out2 = D1 + 1'b1;
cout = D0;
end
d_out2 = L1;
cout = L0;
end
d_out2 = L1 + 1'b1;
cout = L0;
end
d_out2 = K1;
cout = K0;
end
else begin
d_out2 = K1 + 1'b1;
cout = K0;
end
end
else
begin
d_out2 = 4'b0000;
end
end
endmodule`timescale 1ns /
1ps
module
alu(CRY_OUT,DATA_OUT,CRY_
IN,DATA_IN1,DATA_IN2,SEL1,S
EL2,MODE);
output CRY_OUT;
output [3:0] DATA_OUT;
input CRY_IN;
input [3:0] DATA_IN1,DATA_IN2;
input SEL1,SEL2,MODE;
reg logic_unit;
reg arithmetic_unit;
wire [3:0] DATA_OUT1;
wire [3:0] DATA_OUT2;
assign DATA_OUT = (MODE ?
DATA_OUT1 : DATA_OUT2);
logic_unit logic_unit_ins(.d_out1(
DATA_OUT2),
.s0(SEL1),
.s1(SEL2),
.c0(CRY_IN),
.A(DATA_IN1),
.B(DATA_IN2),
.
logic_unit(logic_unit));
arithmetic
arithmetic_ins(.d_out(DATA_OU
T1),
.cout(CRY_OUT),
.s0(SEL1),
.s1(SEL2),
.A(DATA_IN1),
.B(DATA_IN2),
.c0(CRY_IN),
.M(MODE),
.
arithmetic_unit(arithmetic_unit));
always @(SEL1,SEL2,MODE)
begin
if(MODE == 1'b0)
begin
logic_unit = 1'b1;
arithmetic_unit = 1'b0;
end
else begin
logic_unit = 1'b0;
arithmetic_unit = 1'b1;
end
end
endmodule
7.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
End
Endmodule
if (data_in)
state <= S3;
else
state <= S2;
S3:
if (data_in)
state <= S4;
else
state <= S2;
S4:
if (data_in)
state <= S1;
else
69.
70.
71.
72.
73.
74.
FUNCTIONS
K. Moore: a Moore machine is a finite-state machine whose output values are
determined solely by its current state. This is in contrast to a Mealy machine, whose
output values are determined both by its current state and by the values of its inputs.
L. Mealy: a Mealy machine is a finite-state machine whose output values are
determined both by its current state and the current inputs. A Mealy machine is
a deterministic finite-state transducer: for each state and input, at most one transition
is possible.
75.
76.
77. Memory Blocks
Verilog Code:
78. module raminfr (clk, en, we, addr, di,
do);
79. input
clk;
80. input
we;
81. input
en;
82. input [4:0] addr;
83. input [3:0] di;
84. output [3:0] do;
85. reg [3:0] RAM [31:0];
86. reg [3:0] do;
97.
Functions:
98.
The Memory block holds and delays its input by one major integration
time step. When placed in an iterator subsystem, it holds and delays its input by one
iteration. This block accepts continuous and discrete signals. The block accepts one
input and generates one output. Each signal can be scalar or vector. If the input is a
vector, the block holds and delays all elements of the vector by the same time step.
99.
You specify the block output for the first time step using the Initial
condition parameter. Careful selection of this parameter can minimize unwanted output
behavior. However, you cannot specify the sample time. This block's sample time
depends on the type of solver used, or you can specify to inherit it. The Inherit sample
time parameter determines whether sample time is inherited or based on the solver.
System Overview:
100.
101. Control Unit
102.
Functions:
103. Control Unit (CU) is generally a sizable collection of complex digital
circuitry interconnecting and controlling the many execution units contained within a
CPU. The CU is normally the first CPU unit to accept from an externally stored computer
program, a single instruction. The CU then decodes this individual instruction into
several sequential that controls and coordinates the CPU's inner works to properly
manipulate the data. The design of these sequential steps are based on the needs of
each instruction and can range in number of steps, the order of execution, and which
units are enabled. Thus by only using a program of set instructions in memory, the CU
will configure all the CPU's data flows as needed to manipulate the data correctly
between instructions. This results in a computer that could run a complete program and
requiring no human intervention to make hardware changes between instructions (as
had to be done when using only punch cards for computations before stored
programmed computers with CUs where invented). These detailed steps from the CU
dictate which of the CPU's interconnecting hardware control signals to enable/disable or
which CPU units are selected/de-selected and the unit's proper order of execution as
required by the instruction's operation to produce the desired manipulated data.
104.
105. MIPS Singlecycle Processor
Verilog Code
106.
107. module PC(clk , instruction , zero ,
branch , jump , pc );
108. input clk ;
109.
110.
111.
112.
113.
114.
115.
input[31:0] instruction ;
reg[31:0] npc;
input zero ;
input jump ;
input branch ;
134. begin
135.
if ( select1 == 1 )
136.
mux1 = branchAdd ;
137.
else
138.
mux1 = pcInc ;
139. end
140.
141. assign jumpAdd = ( instruction[25:0]
<< 2 );
142.
143. always@ ( jump or jumpAdd or
mux1 )
144. begin
145.
if ( jump == 1 )
146.
npc = jumpAdd ;
147.
else
148.
npc = mux1;
149. end
150.
151. always @(posedge clk )
152.
pc <= npc;
153. endmodule
Functions:
System Overview:
Verilog Code:
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0010;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0110;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0000;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0001;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b1)) begin Operation <= 4'b0111;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b1100;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0011;
end
if
end
if
end
if
end
if
end
end
endmodule
Functions:
Verilog Code
module logic_unit(d_out1,logic_u
nit,s0,s1,c0,A,B);
output [3:0] d_out1;
input s0,s1,c0,logic_unit;
input [3:0] A;
input [3:0] B;
reg [3:0] d_out1;
always @(s0,s1,A,B,logic_unit)
begin
if(logic_unit== 1'b1)
begin
begin
begin
d_out1 = ( A | B);
end
else
begin
d_out1 = ( A ^~ B);
end
end
else
begin
d_out1 = 4'b0000;
end
end
end
input s0,s1,c0,M,arithmetic_unit;
input [3:0] A,B;wire [3:0] d_out;
reg cout;
wire s0,s1,c0,M,arithmetic_unit;
wire [3:0] A,B;wire [3:0]D1;
wire D0;
wire [3:0]L1;
wire L0;
wire [3:0]K1;
wire K0;
reg [3:0] d_out2;
reg [3:0] temp;
reg en;
assign {D0,D1} = A + B;
assign {L0,L1} = (A + (~B));
assign {K0,K1} = ((~A) + B);
assign d_out = d_out2;
always
@(s0,s1,c0,arithmetic_unit)
begin
if(arithmetic_unit)beginif(s1
== 1'b0 & s0 == 1'b0 & c0 == 1'b0)
begin
d_out2 = A;
end
d_out2 = A + 1'b1;
end
d_out2 = D1;
cout = D0;
end
d_out2 = D1 + 1'b1;
cout = D0;
end
d_out2 = L1;
cout = L0;
end
d_out2 = L1 + 1'b1;
cout = L0;
end
d_out2 = K1;
cout = K0;
end
else begin
d_out2 = K1 + 1'b1;
cout = K0;
end
end
else
begin
d_out2 = 4'b0000;
end
end
endmodule`timescale 1ns /
1ps
module
alu(CRY_OUT,DATA_OUT,CRY_
IN,DATA_IN1,DATA_IN2,SEL1,S
EL2,MODE);
output CRY_OUT;
output [3:0] DATA_OUT;
input CRY_IN;
input [3:0] DATA_IN1,DATA_IN2;
input SEL1,SEL2,MODE;
reg logic_unit;
reg arithmetic_unit;
wire [3:0] DATA_OUT1;
wire [3:0] DATA_OUT2;
assign DATA_OUT = (MODE ?
DATA_OUT1 : DATA_OUT2);
logic_unit logic_unit_ins(.d_out1(
DATA_OUT2),
.s0(SEL1),
.s1(SEL2),
.c0(CRY_IN),
.A(DATA_IN1),
.B(DATA_IN2),
.
logic_unit(logic_unit));
arithmetic
arithmetic_ins(.d_out(DATA_OU
T1),
.cout(CRY_OUT),
.s0(SEL1),
.s1(SEL2),
.A(DATA_IN1),
.B(DATA_IN2),
.c0(CRY_IN),
.M(MODE),
.
arithmetic_unit(arithmetic_unit));
always @(SEL1,SEL2,MODE)
begin
if(MODE == 1'b0)
begin
logic_unit = 1'b1;
arithmetic_unit = 1'b0;
end
else begin
logic_unit = 1'b0;
arithmetic_unit = 1'b1;
end
end
endmodule
156.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
End
Endmodule
if (data_in)
state <= S3;
else
state <= S2;
S3:
if (data_in)
state <= S4;
else
state <= S2;
S4:
if (data_in)
state <= S1;
else
217.
218.
219.
220.
221.
222.
FUNCTIONS
M. Moore: a Moore machine is a finite-state machine whose output values are
determined solely by its current state. This is in contrast to a Mealy machine, whose
output values are determined both by its current state and by the values of its inputs.
N. Mealy: a Mealy machine is a finite-state machine whose output values are
determined both by its current state and the current inputs. A Mealy machine is
a deterministic finite-state transducer: for each state and input, at most one transition
is possible.
223.
224.
2. Memory Blocks
Verilog Code:
225. module raminfr (clk, en, we, addr, di,
do);
226. input
clk;
227. input
we;
228. input
en;
229. input [4:0] addr;
230. input [3:0] di;
231. output [3:0] do;
232. reg [3:0] RAM [31:0];
233. reg [3:0] do;
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
Functions:
245. The Memory block holds and delays its input by one major integration
time step. When placed in an iterator subsystem, it holds and delays its input by one
iteration. This block accepts continuous and discrete signals. The block accepts one
input and generates one output. Each signal can be scalar or vector. If the input is a
vector, the block holds and delays all elements of the vector by the same time step.
246. You specify the block output for the first time step using the Initial
condition parameter. Careful selection of this parameter can minimize unwanted output
behavior. However, you cannot specify the sample time. This block's sample time
depends on the type of solver used, or you can specify to inherit it. The Inherit sample
time parameter determines whether sample time is inherited or based on the solver.
System Overview:
247.
3. Control Unit
248.
Functions:
249. Control Unit (CU) is generally a sizable collection of complex digital
circuitry interconnecting and controlling the many execution units contained within a
CPU. The CU is normally the first CPU unit to accept from an externally stored computer
program, a single instruction. The CU then decodes this individual instruction into
several sequential that controls and coordinates the CPU's inner works to properly
manipulate the data. The design of these sequential steps are based on the needs of
each instruction and can range in number of steps, the order of execution, and which
units are enabled. Thus by only using a program of set instructions in memory, the CU
will configure all the CPU's data flows as needed to manipulate the data correctly
between instructions. This results in a computer that could run a complete program and
requiring no human intervention to make hardware changes between instructions (as
had to be done when using only punch cards for computations before stored
programmed computers with CUs where invented). These detailed steps from the CU
dictate which of the CPU's interconnecting hardware control signals to enable/disable or
which CPU units are selected/de-selected and the unit's proper order of execution as
required by the instruction's operation to produce the desired manipulated data.
250.
4. MIPS Singlecycle Processor
Verilog Code
251.
252. module PC(clk , instruction , zero ,
branch , jump , pc );
253. input clk ;
254.
255.
256.
257.
258.
259.
260.
input[31:0] instruction ;
reg[31:0] npc;
input zero ;
input jump ;
input branch ;
279. begin
280.
if ( select1 == 1 )
281.
mux1 = branchAdd ;
282.
else
283.
mux1 = pcInc ;
284. end
285.
286. assign jumpAdd = ( instruction[25:0]
<< 2 );
287.
288. always@ ( jump or jumpAdd or
mux1 )
289. begin
290.
if ( jump == 1 )
291.
npc = jumpAdd ;
292.
else
293.
npc = mux1;
294. end
295.
296. always @(posedge clk )
297.
pc <= npc;
298. endmodule
Functions:
System Overview:
Verilog Code:
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0010;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b0)) begin Operation <= 4'b0110;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0000;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b0)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0001;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b0)&( Funct[
3]==1'b1)) begin Operation <= 4'b0111;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b1)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b1100;
end
if
((ALUOp1==1'b1)&(Funct[0]==1'b0)&(Funct[1]==1'b1)&(Funct[2]==1'b1)&( Funct[
3]==1'b0)) begin Operation <= 4'b0011;
end
if
end
if
end
if
end
if
end
end
endmodule
Functions:
Verilog Code
module logic_unit(d_out1,logic_u
nit,s0,s1,c0,A,B);
output [3:0] d_out1;
input s0,s1,c0,logic_unit;
input [3:0] A;
input [3:0] B;
reg [3:0] d_out1;
always @(s0,s1,A,B,logic_unit)
begin
if(logic_unit== 1'b1)
begin
begin
begin
d_out1 = ( A | B);
end
else
begin
d_out1 = ( A ^~ B);
end
end
else
begin
d_out1 = 4'b0000;
end
end
end
module
arithmetic(d_out,A,B,cout,arithm
etic_unit,s0,s1,c0,M);
inout [3:0] d_out;
output cout;
input s0,s1,c0,M,arithmetic_unit;
input [3:0] A,B;wire [3:0] d_out;
reg cout;
wire s0,s1,c0,M,arithmetic_unit;
wire [3:0] A,B;wire [3:0]D1;
wire D0;
wire [3:0]L1;
wire L0;
wire [3:0]K1;
wire K0;
reg [3:0] d_out2;
reg [3:0] temp;
reg en;
assign {D0,D1} = A + B;
assign {L0,L1} = (A + (~B));
assign {K0,K1} = ((~A) + B);
assign d_out = d_out2;
always
@(s0,s1,c0,arithmetic_unit)
begin
if(arithmetic_unit)beginif(s1
== 1'b0 & s0 == 1'b0 & c0 == 1'b0)
begin
d_out2 = A;
end
d_out2 = A + 1'b1;
end
d_out2 = D1;
cout = D0;
end
d_out2 = D1 + 1'b1;
cout = D0;
end
d_out2 = L1;
cout = L0;
end
d_out2 = L1 + 1'b1;
cout = L0;
end
d_out2 = K1;
cout = K0;
end
else begin
d_out2 = K1 + 1'b1;
cout = K0;
end
end
else
begin
d_out2 = 4'b0000;
end
end
endmodule`timescale 1ns /
1ps
module
alu(CRY_OUT,DATA_OUT,CRY_
IN,DATA_IN1,DATA_IN2,SEL1,S
EL2,MODE);
output CRY_OUT;
output [3:0] DATA_OUT;
input CRY_IN;
input [3:0] DATA_IN1,DATA_IN2;
input SEL1,SEL2,MODE;
reg logic_unit;
reg arithmetic_unit;
wire [3:0] DATA_OUT1;
.s0(SEL1),
.s1(SEL2),
.c0(CRY_IN),
.A(DATA_IN1),
.B(DATA_IN2),
.
logic_unit(logic_unit));
arithmetic
arithmetic_ins(.d_out(DATA_OU
T1),
.cout(CRY_OUT),
.s0(SEL1),
.s1(SEL2),
.A(DATA_IN1),
.B(DATA_IN2),
.c0(CRY_IN),
.M(MODE),
.
arithmetic_unit(arithmetic_unit));
always @(SEL1,SEL2,MODE)
begin
if(MODE == 1'b0)
begin
logic_unit = 1'b1;
arithmetic_unit = 1'b0;
end
else begin
logic_unit = 1'b0;
arithmetic_unit = 1'b1;
end
end
endmodule
7.