SlideShare a Scribd company logo
1 of 24
Laboratory #4:
The Simple Processor
Kyle Villano, Tim Kindervatter and Ian Patel
ELC 363-02
Dr. Jesson
The College of New Jersey
November 12th, 2014
Table of Contents
Introduction..................................................................................................................................... 3
Problem Description ....................................................................................................................... 3
Materials and Procedure.................................................................................................................. 4
Results............................................................................................................................................. 4
Discussion....................................................................................................................................... 6
Conclusion ...................................................................................................................................... 7
Appendix......................................................................................................................................... 9
Introduction
In this lab we used Xilinx ISE to create a simple processor. This processor needed to
perform a variety of different functions, including not, add, jump, load accumulator and store and
clear accumulator processes, among others. We also needed to split up our code into four distinct
sections that dealt with the datapath, ALU, controller, and the actual processor module itself. In
order to do this, we wrote code in Verilog that would be able to define and implement these
various processes. Once the code was written, we used built-in features of ISE to simulate the
output of the processor and confirm that it indeed functioned in the desired manner. After
completing the design of the modules related to our simple processor, we concluded our work by
instantiating a test bench and using it to run a simulation that showed the actual outputs of the
code, which verified that we had indeed satisfied the original tasks of the lab.
Problem Description
The primary task of this lab experiment was to create a simple processor through the
implementation and simulation of Verilog code. In order to accomplish this task, we needed to
focus our work in four distinct sections: the datapath, the ALU, the control values, and the actual
processor module itself. Tables of information regarding control values and function definitions,
along with an overall data path diagram were given in order to aid us in this task. After writing
our code that accurately represented and defined these modules, we needed to verify our results
through the simulation and analysis of the overall ModelSim waveform. In essence, our task
could only be solved by creating, simulating, verifying, and analyzing Verilog code that acted as
a simple processor.
Materials and Procedure
Materials Used:
o XILINX ISE 14.2
Procedure:
1. Study the supplied architecture that uses a minimum CPI Von Newman approach.
2. Study the supplied controller flow diagram.
3. Design and code necessary modules.
4. Perform ModelSim simulation of simple processor code to verify project accuracy.
Results
Once we had all of our code working correctly, we used the ModelSim capabilities of
Xilinx to simulate the simple processor. The waveform of this simulation is shown below in
Figures 1 through 3. The processor started operation at time 100ns and ended at 171ns.
Figure 1: Simulation Waveform
Figure 2: Simulation Waveform
Figure 3: Simulation Waveform
Looking at the PresentState variable, we could see how the processor would move through the
various states to perform the necessary operations. The state of the accumulator (y variable)
could also be observed to see how each instruction would change the result. For instance, at time
105ns the NOT instruction is processed and the contents of the accumulator changes from all
zeros to all ones.
Discussion
In this lab, we were tasked with building a simple processor. This processor required us
to define the behavior of 4 specific components: Datapath, Control, ALU, and Processor.
The datapath is used to define how the processor handles different instructions. Every
instruction set architecture has a certain format to its instructions that is represented as a binary
string. The datapath must be able to recognize these binary strings and send them to different
portions of the hardware so that they can perform different operations. Some of these
destinations include the processor’s registers, the ALU, and memory, among others.
The control portion is used to set various control values that will be used by the datapath.
By reading the initial instruction, the control module sets all the necessary control bits, so that
the other modules can react accordingly to incoming instructions.
The ALU, which stands for Arithmetic Logic Unit, is used to perform arithmetic
operations, such as addition and subtraction, on incoming values. It can be used to perform
operations such as “add,” which simply adds the values contained in two registers and puts it in a
third register. It can also be used to perform operations such as load word, which adds an
immediate value to the value of a register in order to locate a different register, and then load the
value contained in that register. Many other operations require the use of arithmetic operations as
well, which makes the ALU an integral component of the processor.
The processor module was simply a portion of code that tied all of the other components
together and made sure they functioned properly. With each portion working in tandem, we were
able to input a few select instructions and have to processor implement them accordingly.
The main difficulty with this lab was actually get started and figuring out how all the
modules would work together. We were able to design the ALU module fairly easily, but it took
some time before we understood how the datapath and control modules would fit together. Once
we had that understanding though, we realized how the control module would set all the control
values and that the datapath would use these control values to actually perform most of the
desired operations.
Conclusion
In this lab, we learned how to design very complex Verilog code, and how one can
simulate and verify these results in the Xilinx software. We also learned how to design a simple
processor, and how to effectively code and implement such a program in computer architecture
projects. We also were able to ascertain information regarding various errors that could occur
during the coding process, and how to identify and correct them with the software and various
debugging methods.
Using this newly gained knowledge, we were able to successfully design, code, and
analyze the various modules that we needed to successfully implement a simple processor. We
were also able to run one overarching ModelSim waveform generation that allowed us to see the
entire performance and accuracy of our program. We were also able to understand the function
of the many functions and variables utilized in our modules, but more importantly, we were able
to identify the ways in which we needed to alter these components to fit the necessary tasks for
our overall project.
Overall, the simple processor is an important program to be able to understand and create
in Xilinx. Although considered one of the most difficult tasks we will be assigned as
undergraduates, the knowledge and experiences gained from successfully completing such a task
will prove to be invaluable. This lab is also important in that it helps us understand the higher-
level functions of our complex code as well as the various applications that may be able to utilize
it in order to further our knowledge in this field and help us solve future electrical and computer
engineering projects.
Appendix: Code
ALU Module:
`timescale 1ns / 1ps
module alu(y, MD, ALUc, z, c, c);
input [15:0] y; //input 1
input [15:0] MD; //input 2
input [2:0] ALUc; //opcode for ALU
output [15:0] z; //output
output c; //carry in/out
reg [15:0] z;
reg c;
always @ (y or MD or ALUc) begin
case (ALUc)
0: //NOT
z = ~y;
1: //ADC
{c, z} = y + MD;
//JPA doesn't use ALU
3: //INCA
z = y + 1;
4: //STA
z = 0'b000;
5: //LDA
z = MD[15:0];
endcase
end
endmodule
Datapath Module:
`timescale 1ns / 1ps
module Datapath(RD, clk, rstn, enableMD, enableAC, enablePC, enableIR, enableMA,
selectmuxMA, selectmuxPC, selectmuxA, ALUc, WD, A, RWn, PC, MA, y, IR, MD, c);
input clk, rstn;
input [15:0] RD;
input enableAC, enableIR, enableMA, enableMD, enablePC, selectmuxA, selectmuxMA;
input [2:0] ALUc;
input [1:0] selectmuxPC;
input RWn;
output [11:0] A;
output [15:0] y;
output [15:0] IR;
output [11:0] MA;
output [15:0] MD;
output [11:0] PC;
output [15:0] WD;
output c;
reg [11:0] A;
reg [15:0] IR;
reg [11:0] PC;
reg [15:0] y; //Accumulator
reg [11:0] MA;
reg [15:0] MD;
reg [15:0] WD;
reg c; //Corresponding to carry in state 15
wire enableAC, enableIR, enableMA, enableMD, enablePC, selectmuxA, selectmuxMA;
wire [1:0] selectmuxPC;
wire [2:0] ALUc;
wire [15:0] z; //ALU store output
initial begin
A = 0;
y = 0;
c = 0;
PC = 0;
end
alu ALU(y, MD, ALUc, z, c, c);
always @ (posedge clk or MD or ALUc) begin
if (enableAC == 1)
y = z; //Load y with ALU store output
end
always @ (posedge clk or negedge rstn) begin
case (RWn)
0 : begin
if (enableAC == 1)
WD = y;
end
1 : begin
if (enableMD == 1)
MD = RD;
else if (enableIR == 1)
IR = RD;
end
endcase
case (selectmuxMA)
0 : begin
if (enableMA == 1 && enableIR == 1)
MA <= IR[11:0];
end
1 : begin
if (enableMA == 1 && enableMD == 1)
MA <= MD[11:0];
end
endcase
case (selectmuxPC)
0 : begin
if (enablePC == 1)
PC <= PC + 1;
end
1 : begin
if (enablePC == 1)
PC <= IR[11:0];
end
2 : begin
if (enablePC == 1)
PC <= MD[11:0];
end
endcase
end
always @ (posedge clk or MA or MD or PC) begin
case (selectmuxA)
0 : begin
if (enablePC == 1)
A = PC;
end
1 : begin
if (enableMA == 1)
A = MA;
end
endcase
end
endmodule
Controller Module:
`timescale 1ns / 1ps
module Controller(IR, clk, rstn, y, enableMD, enableAC, enablePC, enableIR, enableMA,
ALUc, RWn, selectmuxMA, selectmuxPC, selectmuxA, PresentState);
input [3:0] IR;
input clk;
input rstn;
input [15:0] y; //Accumulator
output enableAC, enableIR, enableMA, enableMD, enablePC, selectmuxA,
selectmuxMA, RWn;
output [1:0] selectmuxPC;
output [2:0] ALUc;
output [4:0] PresentState;
reg c, enableAC, enableIR, enableMA, enableMD, enablePC, selectmuxA,
selectmuxMA;
reg [1:0] selectmuxPC;
reg RWn;
reg [4:0] PresentState, NextState;
parameter S0 = 5'd0, S1 = 5'd1, S2 = 5'd2, S3 = 5'd3,
S4 = 5'd4, S5 = 5'd5, S6 = 5'd6, S7 = 5'd7,
S8 = 5'd8, S9 = 5'd9, S10 = 5'd10,
S11 = 5'd11, S12 = 5'd12, S13 = 5'd13,
S14 = 5'd14, S15 = 5'd15, S16 = 5'd16;
assign ALUc = IR[3:1];
always @ (posedge clk or negedge rstn) begin
if (rstn == 1'b0)
PresentState = S0;
else
PresentState = NextState;
end
always @(PresentState) begin
enableAC = 0;
enableMD = 0;
enablePC = 0;
enableIR = 0;
enableMA = 0;
selectmuxMA = 0;
selectmuxPC = 2'b00;
selectmuxA = 0;
RWn = 0; //Reset enables for every state
case(PresentState)
S0: begin
// enableAC = 0;
// enableMD = 0;
RWn = 1;
enablePC = 1;
enableIR = 1;
// enableMA = 0;
// selectmuxMA = 0;
selectmuxPC = 2'b11;
// selectmuxA = 0;
// IR[15:0] <= M[PC];
NextState = S1;
end
S1: begin
// enableAC = 0;
// enableMD = 0;
enablePC = 1;
// enableIR = 0;
// enableMA = 0;
// selectmuxMA = 0;
selectmuxPC = 2'b00;
// selectmuxA = 0;
// PC[11:0] <= PC[11:0] + 1; //Handled by Datapath
if (IR[3:1] == 3'b000) begin
NextState = S2;
end
else if (IR[3:1] == 3'b011) begin
NextState = S3;
end
else if (IR[3:1] == 3'b010) begin
if (y > 0) begin
if (IR[0] == 1'b1) begin
NextState = S4;
end
else begin
NextState = S7;
end
end
else begin
enablePC = 1;
selectmuxPC = 2'b11;
NextState = S0;
end
end
else
NextState = S8;
end
S2: begin
enableAC = 1;
// enableIR = 0;
// enableMA = 0;
// enableMD = 0;
enablePC = 1;
selectmuxPC = 2'b11;
// y <= ~y; //AC
NextState = S0;
end
S3: begin
enableAC = 1;
// enableIR = 0;
// enableMA = 0;
// enableMD = 0;
enablePC = 1;
selectmuxPC = 2'b11;
// y <= y+1; //AC
NextState = S0;
end
S4: begin
// enableAC = 0;
enableIR = 1;
enableMA = 1;
// enableMD = 0;
// enablePC = 0;
selectmuxA = 1;
// MA[11:0] <= IR[11:0];
NextState = S5;
end
S5: begin
// enableAC = 0;
// enableIR = 0;
enableMA = 1;
enableMD = 1;
// enablePC = 0;
selectmuxA = 1;
RWn = 1;
// MD[15:0] <= M[MA];
NextState = S6;
end
S6: begin
// enableAC = 0;
// enableIR = 0;
// enableMA = 0;
enableMD = 1;
enablePC = 1;
selectmuxPC = 2'b10;
// PC[11:0] <= MD[15:0];
NextState = S0;
end
S7: begin
// enableAC = 0;
enableIR = 1;
// enableMA = 0;
// enableMD = 0;
enablePC = 1;
selectmuxPC = 2'b01;
// PC[11:0] <= IR[11:0];
NextState = S0;
end
S8: begin
// enableAC = 0;
enableIR = 1;
enableMA = 1;
// enableMD = 0;
// enablePC = 0;
selectmuxMA = 0;
// MA[11:0] <= IR[11:0];
if (IR[3:1] == 3'b100 && IR[0] == 1)
NextState = S9; //STA & AM
else if (IR[3:1] == 3'b100 && IR[0] == 0)
NextState = S11; //STA & ~AM
else
NextState = S12;
end
S9: begin
// enableAC = 0;
// enableIR = 0;
enableMA = 1;
enableMD = 1;
// enablePC = 0;
selectmuxA = 1;
RWn = 1;
// MD[15:0] <= M[MA];
NextState = S10;
end
S10: begin
// enableAC = 0;
// enableIR = 0;
enableMA = 1;
enableMD = 1;
// enablePC = 0;
selectmuxMA = 1;
// MA[11:0] <= MD[15:0];
NextState = S11;
end
S11: begin
enableAC = 1;
// enableIR = 0;
enableMA = 1;
// enableMD = 0;
enablePC = 1;
selectmuxPC = 2'b11;
// M[MA] <= y;
// y <= 0'b000;
NextState = S0;
end
S12: begin
// enableAC = 0;
// enableIR = 0;
enableMA = 1;
enableMD = 1;
// enablePC = 0;
selectmuxA = 1;
RWn = 1;
// MD[15:0] <= M[MA];
if (IR[0] == 1)
NextState = S13; //AM
else begin
if (IR[3:1] == 3'b001)
NextState = S15; //ADC
else
NextState = S16;
end
end
S13: begin
// enableAC = 0;
// enableIR = 0;
enableMA = 1;
enableMD = 1;
// enablePC = 0;
selectmuxMA = 1;
// MA <= MD;
NextState = S14;
end
S14: begin
// enableAC = 0;
// enableIR = 0;
enableMA = 1;
enableMD = 1;
// enablePC = 0;
selectmuxA = 1;
RWn = 1;
// MD <= M[MA];
if (IR[3:1] == 3'b001)
NextState = S15; //ADC
else
NextState = S16;
end
S15: begin
enableAC = 1;
// enableIR = 0;
// enableMA = 0;
enableMD = 1;
// enablePC = 0;
// y <= y+MD[15:0]+C;
NextState = S0;
end
S16: begin
enableAC = 1;
// enableIR = 0;
// enableMA = 0;
enableMD = 1;
enablePC = 1;
selectmuxPC = 2'b11;
// y <= MD[15:0];
NextState = S0;
end
endcase
end
endmodule
Processor Module:
`timescale 1ns / 1ps
module processor(RD, clk, rstn, WD, A, IR, MD, y, PC, MA, PresentState, enableIR, enableMD,
enableAC, enablePC, enableMA, selectmuxMA, selectmuxPC, selectmuxA, ALUc, c);
input clk;
input rstn;
input [15:0] RD;
output [11:0] A;
output [15:0] IR;
output [11:0] PC;
output [11:0] MA;
output [15:0] MD;
output [15:0] WD;
output [15:0] y;
output enableAC;
output enableIR;
output enableMA;
output enableMD;
output enablePC;
output [2:0] ALUc;
output selectmuxA;
output selectmuxMA;
output [1:0] selectmuxPC;
output [4:0] PresentState;
output c;
wire [15:0] IR;
wire [11:0] PC;
wire [11:0] MA;
wire [15:0] MD;
wire [11:0] A;
wire [15:0] y;
wire clk;
wire rstn;
wire [2:0] ALUc;
wire enableAC;
wire enableIR;
wire enableMA;
wire enableMD;
wire enablePC;
wire RWn;
wire selectmuxA;
wire selectmuxMA;
wire [1:0] selectmuxPC;
Datapath datapath(RD, clk, rstn, enableMD, enableAC, enablePC, enableIR, enableMA,
selectmuxMA, selectmuxPC, selectmuxA, ALUc, WD, A, RWn, PC, MA, y, IR, MD, c);
Controller controller(IR[15:12], clk, rstn, y, enableMD, enableAC, enablePC, enableIR,
enableMA, ALUc, RWn, selectmuxMA, selectmuxPC, selectmuxA, PresentState);
endmodule
Testbench:
`timescale 1ns / 1ps
module Testbench;
reg [15:0] RD;
reg clk;
reg rstn;
wire [15:0] IR;
wire [11:0] PC;
wire [11:0] MA;
wire [15:0] MD;
wire [15:0] WD;
wire [11:0] A;
wire [15:0] y;
wire enableAC;
wire enableIR;
wire enableMA;
wire enableMD;
wire enablePC;
wire [2:0] ALUc;
wire c;
wire selectmuxA;
wire selectmuxMA;
wire [1:0] selectmuxPC;
wire [4:0] PresentState;
reg [15:0] M[4096:0]; //4096 is 2^12
// Instantiate the Unit Under Test (UUT)
processor uut (
.RD(RD),
.clk(clk),
.rstn(rstn),
.WD(WD),
.A(A),
.IR(IR),
.MD(MD),
.y(y),
.PC(PC),
.MA(MA),
.PresentState(PresentState),
.enableIR(enableIR),
.enableMD(enableMD),
.enableAC(enableAC),
.enablePC(enablePC),
.enableMA(enableMA),
.selectmuxMA(selectmuxMA),
.selectmuxPC(selectmuxPC),
.selectmuxA(selectmuxA),
.ALUc(ALUc),
.c(c)
);
initial begin
// Initialize Inputs
clk = 0;
rstn = 0;
//Memory to set every opcode and addressing
M[0] <= 16'b0000000000000000;
M[1] <= 16'b0010000000000100;
M[2] <= 16'b0011000000001010;
M[3] <= 16'b0110000000000000;
M[4] <= 16'b0100000000000111;
M[5] <= 16'b0101000000001011;
M[6] <= 16'b1000000000000000;
M[7] <= 16'b1001000000001011;
M[8] <= 16'b1010000000000010;
M[9] <= 16'b1011000000001010;
M[10] <= 16'b0000000000001000;
M[11] <= 16'b0000000000001010;
// Wait 100 ns for global reset to finish
#100;
// Add stimulus here
rstn = 1;
RD <= M[A];
end
always @(clk) #1 clk <= ~clk; //Create clock
always @ (posedge clk or negedge rstn or A) begin
RD <= M[A];
end
always @ (WD) begin
if (WD == 0 && enableAC == 1)
M[A] <= WD;
end
endmodule

More Related Content

What's hot

hajer
hajerhajer
hajerra na
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)k33a
 
Et3003 sem2-1314-6 network layers iii (arp)
Et3003 sem2-1314-6 network layers iii (arp)Et3003 sem2-1314-6 network layers iii (arp)
Et3003 sem2-1314-6 network layers iii (arp)Tutun Juhana
 
Final networks lab manual
Final networks lab manualFinal networks lab manual
Final networks lab manualJaya Prasanna
 
Introduction of tcp, ip & udp
Introduction of tcp, ip & udpIntroduction of tcp, ip & udp
Introduction of tcp, ip & udprahul kundu
 
Ch 19 Network-layer protocols - section 2
Ch 19   Network-layer protocols - section 2Ch 19   Network-layer protocols - section 2
Ch 19 Network-layer protocols - section 2Hossam El-Deen Osama
 
Transport layer interface
Transport layer interface Transport layer interface
Transport layer interface CEC Landran
 
Tcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport LayerTcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport Layertmavroidis
 
Wireshark course, Ch 03: Capture and display filters
Wireshark course, Ch 03: Capture and display filtersWireshark course, Ch 03: Capture and display filters
Wireshark course, Ch 03: Capture and display filtersYoram Orzach
 
Ch 09 -- ARP & IP Analysis
Ch 09 -- ARP & IP AnalysisCh 09 -- ARP & IP Analysis
Ch 09 -- ARP & IP AnalysisYoram Orzach
 
Routing table and routing algorithms
Routing table and routing algorithmsRouting table and routing algorithms
Routing table and routing algorithmslavanyapathy
 
Client server examples for tcp abnormal conditions
Client server examples for tcp abnormal conditionsClient server examples for tcp abnormal conditions
Client server examples for tcp abnormal conditionsCEC Landran
 
UDP - User Datagram Protocol
UDP - User Datagram ProtocolUDP - User Datagram Protocol
UDP - User Datagram ProtocolPeter R. Egli
 

What's hot (20)

hajer
hajerhajer
hajer
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)
 
Et3003 sem2-1314-6 network layers iii (arp)
Et3003 sem2-1314-6 network layers iii (arp)Et3003 sem2-1314-6 network layers iii (arp)
Et3003 sem2-1314-6 network layers iii (arp)
 
Final networks lab manual
Final networks lab manualFinal networks lab manual
Final networks lab manual
 
Introduction of tcp, ip & udp
Introduction of tcp, ip & udpIntroduction of tcp, ip & udp
Introduction of tcp, ip & udp
 
Ch 19 Network-layer protocols - section 2
Ch 19   Network-layer protocols - section 2Ch 19   Network-layer protocols - section 2
Ch 19 Network-layer protocols - section 2
 
TCP Vs UDP
TCP Vs UDP TCP Vs UDP
TCP Vs UDP
 
Transport layer interface
Transport layer interface Transport layer interface
Transport layer interface
 
Tcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport LayerTcp Udp Icmp And The Transport Layer
Tcp Udp Icmp And The Transport Layer
 
Wireshark course, Ch 03: Capture and display filters
Wireshark course, Ch 03: Capture and display filtersWireshark course, Ch 03: Capture and display filters
Wireshark course, Ch 03: Capture and display filters
 
Presentation on arp protocol
Presentation on arp protocolPresentation on arp protocol
Presentation on arp protocol
 
Tcp Udp Notes
Tcp Udp NotesTcp Udp Notes
Tcp Udp Notes
 
Routing
RoutingRouting
Routing
 
Cn lab manual 150702
Cn lab manual 150702Cn lab manual 150702
Cn lab manual 150702
 
Ch 09 -- ARP & IP Analysis
Ch 09 -- ARP & IP AnalysisCh 09 -- ARP & IP Analysis
Ch 09 -- ARP & IP Analysis
 
Routing table and routing algorithms
Routing table and routing algorithmsRouting table and routing algorithms
Routing table and routing algorithms
 
Client server examples for tcp abnormal conditions
Client server examples for tcp abnormal conditionsClient server examples for tcp abnormal conditions
Client server examples for tcp abnormal conditions
 
UDP - User Datagram Protocol
UDP - User Datagram ProtocolUDP - User Datagram Protocol
UDP - User Datagram Protocol
 
Week14 lec2
Week14 lec2Week14 lec2
Week14 lec2
 
Mod4
Mod4Mod4
Mod4
 

Similar to Lab 4 final report

Minor Project Report on - short range personal 'RADAR'.
Minor Project Report on - short range personal 'RADAR'.Minor Project Report on - short range personal 'RADAR'.
Minor Project Report on - short range personal 'RADAR'.Sarvesh Kushwaha
 
The Principle Of Ultrasound Imaging System
The Principle Of Ultrasound Imaging SystemThe Principle Of Ultrasound Imaging System
The Principle Of Ultrasound Imaging SystemMelissa Luster
 
Rodrigo Almeida - Microkernel development from project to implementation
Rodrigo Almeida - Microkernel development from project to implementationRodrigo Almeida - Microkernel development from project to implementation
Rodrigo Almeida - Microkernel development from project to implementationFelipe Prado
 
Building Cultural Awareness through EmotionPresented By Team .docx
Building Cultural Awareness through EmotionPresented By Team .docxBuilding Cultural Awareness through EmotionPresented By Team .docx
Building Cultural Awareness through EmotionPresented By Team .docxhartrobert670
 
System verilog important
System verilog importantSystem verilog important
System verilog importantelumalai7
 
Design the implementation of CDEx Robust DC Motor.
Design the implementation of CDEx Robust DC Motor.Design the implementation of CDEx Robust DC Motor.
Design the implementation of CDEx Robust DC Motor.Ankita Tiwari
 
Fpga implementation of a functional microcontroller
Fpga implementation of a functional microcontrollerFpga implementation of a functional microcontroller
Fpga implementation of a functional microcontrollereSAT Publishing House
 
Siemens s7 300 programming
Siemens s7 300 programming Siemens s7 300 programming
Siemens s7 300 programming satyajit patra
 
EELE 5331 Digital ASIC DesignLab ManualDr. Yushi Zhou.docx
EELE 5331 Digital ASIC DesignLab ManualDr. Yushi Zhou.docxEELE 5331 Digital ASIC DesignLab ManualDr. Yushi Zhou.docx
EELE 5331 Digital ASIC DesignLab ManualDr. Yushi Zhou.docxtoltonkendal
 

Similar to Lab 4 final report (20)

Minor Project Report on - short range personal 'RADAR'.
Minor Project Report on - short range personal 'RADAR'.Minor Project Report on - short range personal 'RADAR'.
Minor Project Report on - short range personal 'RADAR'.
 
ES-CH5.ppt
ES-CH5.pptES-CH5.ppt
ES-CH5.ppt
 
The Principle Of Ultrasound Imaging System
The Principle Of Ultrasound Imaging SystemThe Principle Of Ultrasound Imaging System
The Principle Of Ultrasound Imaging System
 
Tutor1
Tutor1Tutor1
Tutor1
 
Introduction to Microcontrollers
Introduction to MicrocontrollersIntroduction to Microcontrollers
Introduction to Microcontrollers
 
PID2143641
PID2143641PID2143641
PID2143641
 
Rodrigo Almeida - Microkernel development from project to implementation
Rodrigo Almeida - Microkernel development from project to implementationRodrigo Almeida - Microkernel development from project to implementation
Rodrigo Almeida - Microkernel development from project to implementation
 
Building Cultural Awareness through EmotionPresented By Team .docx
Building Cultural Awareness through EmotionPresented By Team .docxBuilding Cultural Awareness through EmotionPresented By Team .docx
Building Cultural Awareness through EmotionPresented By Team .docx
 
System verilog important
System verilog importantSystem verilog important
System verilog important
 
Design the implementation of CDEx Robust DC Motor.
Design the implementation of CDEx Robust DC Motor.Design the implementation of CDEx Robust DC Motor.
Design the implementation of CDEx Robust DC Motor.
 
CP Handout#1
CP Handout#1CP Handout#1
CP Handout#1
 
Design Verification
Design VerificationDesign Verification
Design Verification
 
Innoslate 4.5 and Sopatra
Innoslate 4.5 and SopatraInnoslate 4.5 and Sopatra
Innoslate 4.5 and Sopatra
 
UDP Report
UDP ReportUDP Report
UDP Report
 
Fpga implementation of a functional microcontroller
Fpga implementation of a functional microcontrollerFpga implementation of a functional microcontroller
Fpga implementation of a functional microcontroller
 
Siemens s7 300 programming
Siemens s7 300 programming Siemens s7 300 programming
Siemens s7 300 programming
 
CE150--Hongyi Huang
CE150--Hongyi HuangCE150--Hongyi Huang
CE150--Hongyi Huang
 
Training report on embedded sys_AVR
Training report on embedded sys_AVRTraining report on embedded sys_AVR
Training report on embedded sys_AVR
 
Bidirect visitor counter
Bidirect visitor counterBidirect visitor counter
Bidirect visitor counter
 
EELE 5331 Digital ASIC DesignLab ManualDr. Yushi Zhou.docx
EELE 5331 Digital ASIC DesignLab ManualDr. Yushi Zhou.docxEELE 5331 Digital ASIC DesignLab ManualDr. Yushi Zhou.docx
EELE 5331 Digital ASIC DesignLab ManualDr. Yushi Zhou.docx
 

Lab 4 final report

  • 1. Laboratory #4: The Simple Processor Kyle Villano, Tim Kindervatter and Ian Patel ELC 363-02 Dr. Jesson The College of New Jersey November 12th, 2014
  • 2. Table of Contents Introduction..................................................................................................................................... 3 Problem Description ....................................................................................................................... 3 Materials and Procedure.................................................................................................................. 4 Results............................................................................................................................................. 4 Discussion....................................................................................................................................... 6 Conclusion ...................................................................................................................................... 7 Appendix......................................................................................................................................... 9 Introduction
  • 3. In this lab we used Xilinx ISE to create a simple processor. This processor needed to perform a variety of different functions, including not, add, jump, load accumulator and store and clear accumulator processes, among others. We also needed to split up our code into four distinct sections that dealt with the datapath, ALU, controller, and the actual processor module itself. In order to do this, we wrote code in Verilog that would be able to define and implement these various processes. Once the code was written, we used built-in features of ISE to simulate the output of the processor and confirm that it indeed functioned in the desired manner. After completing the design of the modules related to our simple processor, we concluded our work by instantiating a test bench and using it to run a simulation that showed the actual outputs of the code, which verified that we had indeed satisfied the original tasks of the lab. Problem Description The primary task of this lab experiment was to create a simple processor through the implementation and simulation of Verilog code. In order to accomplish this task, we needed to focus our work in four distinct sections: the datapath, the ALU, the control values, and the actual processor module itself. Tables of information regarding control values and function definitions, along with an overall data path diagram were given in order to aid us in this task. After writing our code that accurately represented and defined these modules, we needed to verify our results through the simulation and analysis of the overall ModelSim waveform. In essence, our task could only be solved by creating, simulating, verifying, and analyzing Verilog code that acted as a simple processor. Materials and Procedure
  • 4. Materials Used: o XILINX ISE 14.2 Procedure: 1. Study the supplied architecture that uses a minimum CPI Von Newman approach. 2. Study the supplied controller flow diagram. 3. Design and code necessary modules. 4. Perform ModelSim simulation of simple processor code to verify project accuracy. Results Once we had all of our code working correctly, we used the ModelSim capabilities of Xilinx to simulate the simple processor. The waveform of this simulation is shown below in Figures 1 through 3. The processor started operation at time 100ns and ended at 171ns. Figure 1: Simulation Waveform
  • 5. Figure 2: Simulation Waveform Figure 3: Simulation Waveform Looking at the PresentState variable, we could see how the processor would move through the various states to perform the necessary operations. The state of the accumulator (y variable) could also be observed to see how each instruction would change the result. For instance, at time 105ns the NOT instruction is processed and the contents of the accumulator changes from all zeros to all ones.
  • 6. Discussion In this lab, we were tasked with building a simple processor. This processor required us to define the behavior of 4 specific components: Datapath, Control, ALU, and Processor. The datapath is used to define how the processor handles different instructions. Every instruction set architecture has a certain format to its instructions that is represented as a binary string. The datapath must be able to recognize these binary strings and send them to different portions of the hardware so that they can perform different operations. Some of these destinations include the processor’s registers, the ALU, and memory, among others. The control portion is used to set various control values that will be used by the datapath. By reading the initial instruction, the control module sets all the necessary control bits, so that the other modules can react accordingly to incoming instructions. The ALU, which stands for Arithmetic Logic Unit, is used to perform arithmetic operations, such as addition and subtraction, on incoming values. It can be used to perform operations such as “add,” which simply adds the values contained in two registers and puts it in a third register. It can also be used to perform operations such as load word, which adds an immediate value to the value of a register in order to locate a different register, and then load the value contained in that register. Many other operations require the use of arithmetic operations as well, which makes the ALU an integral component of the processor. The processor module was simply a portion of code that tied all of the other components together and made sure they functioned properly. With each portion working in tandem, we were able to input a few select instructions and have to processor implement them accordingly. The main difficulty with this lab was actually get started and figuring out how all the modules would work together. We were able to design the ALU module fairly easily, but it took
  • 7. some time before we understood how the datapath and control modules would fit together. Once we had that understanding though, we realized how the control module would set all the control values and that the datapath would use these control values to actually perform most of the desired operations. Conclusion In this lab, we learned how to design very complex Verilog code, and how one can simulate and verify these results in the Xilinx software. We also learned how to design a simple processor, and how to effectively code and implement such a program in computer architecture projects. We also were able to ascertain information regarding various errors that could occur during the coding process, and how to identify and correct them with the software and various debugging methods. Using this newly gained knowledge, we were able to successfully design, code, and analyze the various modules that we needed to successfully implement a simple processor. We were also able to run one overarching ModelSim waveform generation that allowed us to see the entire performance and accuracy of our program. We were also able to understand the function of the many functions and variables utilized in our modules, but more importantly, we were able to identify the ways in which we needed to alter these components to fit the necessary tasks for our overall project. Overall, the simple processor is an important program to be able to understand and create in Xilinx. Although considered one of the most difficult tasks we will be assigned as undergraduates, the knowledge and experiences gained from successfully completing such a task will prove to be invaluable. This lab is also important in that it helps us understand the higher-
  • 8. level functions of our complex code as well as the various applications that may be able to utilize it in order to further our knowledge in this field and help us solve future electrical and computer engineering projects. Appendix: Code ALU Module: `timescale 1ns / 1ps module alu(y, MD, ALUc, z, c, c); input [15:0] y; //input 1 input [15:0] MD; //input 2 input [2:0] ALUc; //opcode for ALU
  • 9. output [15:0] z; //output output c; //carry in/out reg [15:0] z; reg c; always @ (y or MD or ALUc) begin case (ALUc) 0: //NOT z = ~y; 1: //ADC {c, z} = y + MD; //JPA doesn't use ALU 3: //INCA z = y + 1; 4: //STA z = 0'b000; 5: //LDA z = MD[15:0]; endcase end endmodule
  • 10. Datapath Module: `timescale 1ns / 1ps module Datapath(RD, clk, rstn, enableMD, enableAC, enablePC, enableIR, enableMA, selectmuxMA, selectmuxPC, selectmuxA, ALUc, WD, A, RWn, PC, MA, y, IR, MD, c); input clk, rstn; input [15:0] RD; input enableAC, enableIR, enableMA, enableMD, enablePC, selectmuxA, selectmuxMA; input [2:0] ALUc; input [1:0] selectmuxPC; input RWn; output [11:0] A; output [15:0] y; output [15:0] IR; output [11:0] MA; output [15:0] MD; output [11:0] PC; output [15:0] WD; output c; reg [11:0] A; reg [15:0] IR; reg [11:0] PC; reg [15:0] y; //Accumulator reg [11:0] MA; reg [15:0] MD; reg [15:0] WD; reg c; //Corresponding to carry in state 15 wire enableAC, enableIR, enableMA, enableMD, enablePC, selectmuxA, selectmuxMA; wire [1:0] selectmuxPC; wire [2:0] ALUc; wire [15:0] z; //ALU store output initial begin A = 0; y = 0; c = 0; PC = 0; end alu ALU(y, MD, ALUc, z, c, c); always @ (posedge clk or MD or ALUc) begin
  • 11. if (enableAC == 1) y = z; //Load y with ALU store output end always @ (posedge clk or negedge rstn) begin case (RWn) 0 : begin if (enableAC == 1) WD = y; end 1 : begin if (enableMD == 1) MD = RD; else if (enableIR == 1) IR = RD; end endcase case (selectmuxMA) 0 : begin if (enableMA == 1 && enableIR == 1) MA <= IR[11:0]; end 1 : begin if (enableMA == 1 && enableMD == 1) MA <= MD[11:0]; end endcase case (selectmuxPC) 0 : begin if (enablePC == 1) PC <= PC + 1; end 1 : begin if (enablePC == 1) PC <= IR[11:0]; end 2 : begin if (enablePC == 1) PC <= MD[11:0]; end endcase end always @ (posedge clk or MA or MD or PC) begin
  • 12. case (selectmuxA) 0 : begin if (enablePC == 1) A = PC; end 1 : begin if (enableMA == 1) A = MA; end endcase end endmodule
  • 13. Controller Module: `timescale 1ns / 1ps module Controller(IR, clk, rstn, y, enableMD, enableAC, enablePC, enableIR, enableMA, ALUc, RWn, selectmuxMA, selectmuxPC, selectmuxA, PresentState); input [3:0] IR; input clk; input rstn; input [15:0] y; //Accumulator output enableAC, enableIR, enableMA, enableMD, enablePC, selectmuxA, selectmuxMA, RWn; output [1:0] selectmuxPC; output [2:0] ALUc; output [4:0] PresentState; reg c, enableAC, enableIR, enableMA, enableMD, enablePC, selectmuxA, selectmuxMA; reg [1:0] selectmuxPC; reg RWn; reg [4:0] PresentState, NextState; parameter S0 = 5'd0, S1 = 5'd1, S2 = 5'd2, S3 = 5'd3, S4 = 5'd4, S5 = 5'd5, S6 = 5'd6, S7 = 5'd7, S8 = 5'd8, S9 = 5'd9, S10 = 5'd10, S11 = 5'd11, S12 = 5'd12, S13 = 5'd13, S14 = 5'd14, S15 = 5'd15, S16 = 5'd16; assign ALUc = IR[3:1]; always @ (posedge clk or negedge rstn) begin if (rstn == 1'b0) PresentState = S0; else PresentState = NextState; end always @(PresentState) begin enableAC = 0; enableMD = 0; enablePC = 0; enableIR = 0; enableMA = 0; selectmuxMA = 0; selectmuxPC = 2'b00; selectmuxA = 0;
  • 14. RWn = 0; //Reset enables for every state case(PresentState) S0: begin // enableAC = 0; // enableMD = 0; RWn = 1; enablePC = 1; enableIR = 1; // enableMA = 0; // selectmuxMA = 0; selectmuxPC = 2'b11; // selectmuxA = 0; // IR[15:0] <= M[PC]; NextState = S1; end S1: begin // enableAC = 0; // enableMD = 0; enablePC = 1; // enableIR = 0; // enableMA = 0; // selectmuxMA = 0; selectmuxPC = 2'b00; // selectmuxA = 0; // PC[11:0] <= PC[11:0] + 1; //Handled by Datapath if (IR[3:1] == 3'b000) begin NextState = S2; end else if (IR[3:1] == 3'b011) begin NextState = S3; end else if (IR[3:1] == 3'b010) begin if (y > 0) begin if (IR[0] == 1'b1) begin NextState = S4; end else begin NextState = S7; end end else begin enablePC = 1; selectmuxPC = 2'b11; NextState = S0;
  • 15. end end else NextState = S8; end S2: begin enableAC = 1; // enableIR = 0; // enableMA = 0; // enableMD = 0; enablePC = 1; selectmuxPC = 2'b11; // y <= ~y; //AC NextState = S0; end S3: begin enableAC = 1; // enableIR = 0; // enableMA = 0; // enableMD = 0; enablePC = 1; selectmuxPC = 2'b11; // y <= y+1; //AC NextState = S0; end S4: begin // enableAC = 0; enableIR = 1; enableMA = 1; // enableMD = 0; // enablePC = 0; selectmuxA = 1; // MA[11:0] <= IR[11:0]; NextState = S5; end S5: begin // enableAC = 0; // enableIR = 0; enableMA = 1; enableMD = 1; // enablePC = 0; selectmuxA = 1;
  • 16. RWn = 1; // MD[15:0] <= M[MA]; NextState = S6; end S6: begin // enableAC = 0; // enableIR = 0; // enableMA = 0; enableMD = 1; enablePC = 1; selectmuxPC = 2'b10; // PC[11:0] <= MD[15:0]; NextState = S0; end S7: begin // enableAC = 0; enableIR = 1; // enableMA = 0; // enableMD = 0; enablePC = 1; selectmuxPC = 2'b01; // PC[11:0] <= IR[11:0]; NextState = S0; end S8: begin // enableAC = 0; enableIR = 1; enableMA = 1; // enableMD = 0; // enablePC = 0; selectmuxMA = 0; // MA[11:0] <= IR[11:0]; if (IR[3:1] == 3'b100 && IR[0] == 1) NextState = S9; //STA & AM else if (IR[3:1] == 3'b100 && IR[0] == 0) NextState = S11; //STA & ~AM else NextState = S12; end S9: begin // enableAC = 0; // enableIR = 0;
  • 17. enableMA = 1; enableMD = 1; // enablePC = 0; selectmuxA = 1; RWn = 1; // MD[15:0] <= M[MA]; NextState = S10; end S10: begin // enableAC = 0; // enableIR = 0; enableMA = 1; enableMD = 1; // enablePC = 0; selectmuxMA = 1; // MA[11:0] <= MD[15:0]; NextState = S11; end S11: begin enableAC = 1; // enableIR = 0; enableMA = 1; // enableMD = 0; enablePC = 1; selectmuxPC = 2'b11; // M[MA] <= y; // y <= 0'b000; NextState = S0; end S12: begin // enableAC = 0; // enableIR = 0; enableMA = 1; enableMD = 1; // enablePC = 0; selectmuxA = 1; RWn = 1; // MD[15:0] <= M[MA]; if (IR[0] == 1) NextState = S13; //AM else begin if (IR[3:1] == 3'b001) NextState = S15; //ADC
  • 18. else NextState = S16; end end S13: begin // enableAC = 0; // enableIR = 0; enableMA = 1; enableMD = 1; // enablePC = 0; selectmuxMA = 1; // MA <= MD; NextState = S14; end S14: begin // enableAC = 0; // enableIR = 0; enableMA = 1; enableMD = 1; // enablePC = 0; selectmuxA = 1; RWn = 1; // MD <= M[MA]; if (IR[3:1] == 3'b001) NextState = S15; //ADC else NextState = S16; end S15: begin enableAC = 1; // enableIR = 0; // enableMA = 0; enableMD = 1; // enablePC = 0; // y <= y+MD[15:0]+C; NextState = S0; end S16: begin enableAC = 1; // enableIR = 0; // enableMA = 0; enableMD = 1;
  • 19. enablePC = 1; selectmuxPC = 2'b11; // y <= MD[15:0]; NextState = S0; end endcase end endmodule
  • 20. Processor Module: `timescale 1ns / 1ps module processor(RD, clk, rstn, WD, A, IR, MD, y, PC, MA, PresentState, enableIR, enableMD, enableAC, enablePC, enableMA, selectmuxMA, selectmuxPC, selectmuxA, ALUc, c); input clk; input rstn; input [15:0] RD; output [11:0] A; output [15:0] IR; output [11:0] PC; output [11:0] MA; output [15:0] MD; output [15:0] WD; output [15:0] y; output enableAC; output enableIR; output enableMA; output enableMD; output enablePC; output [2:0] ALUc; output selectmuxA; output selectmuxMA; output [1:0] selectmuxPC; output [4:0] PresentState; output c; wire [15:0] IR; wire [11:0] PC; wire [11:0] MA; wire [15:0] MD; wire [11:0] A; wire [15:0] y; wire clk; wire rstn; wire [2:0] ALUc; wire enableAC; wire enableIR; wire enableMA; wire enableMD; wire enablePC; wire RWn; wire selectmuxA; wire selectmuxMA;
  • 21. wire [1:0] selectmuxPC; Datapath datapath(RD, clk, rstn, enableMD, enableAC, enablePC, enableIR, enableMA, selectmuxMA, selectmuxPC, selectmuxA, ALUc, WD, A, RWn, PC, MA, y, IR, MD, c); Controller controller(IR[15:12], clk, rstn, y, enableMD, enableAC, enablePC, enableIR, enableMA, ALUc, RWn, selectmuxMA, selectmuxPC, selectmuxA, PresentState); endmodule
  • 22. Testbench: `timescale 1ns / 1ps module Testbench; reg [15:0] RD; reg clk; reg rstn; wire [15:0] IR; wire [11:0] PC; wire [11:0] MA; wire [15:0] MD; wire [15:0] WD; wire [11:0] A; wire [15:0] y; wire enableAC; wire enableIR; wire enableMA; wire enableMD; wire enablePC; wire [2:0] ALUc; wire c; wire selectmuxA; wire selectmuxMA; wire [1:0] selectmuxPC; wire [4:0] PresentState; reg [15:0] M[4096:0]; //4096 is 2^12 // Instantiate the Unit Under Test (UUT) processor uut ( .RD(RD), .clk(clk), .rstn(rstn), .WD(WD), .A(A), .IR(IR), .MD(MD), .y(y), .PC(PC), .MA(MA), .PresentState(PresentState), .enableIR(enableIR), .enableMD(enableMD), .enableAC(enableAC),
  • 23. .enablePC(enablePC), .enableMA(enableMA), .selectmuxMA(selectmuxMA), .selectmuxPC(selectmuxPC), .selectmuxA(selectmuxA), .ALUc(ALUc), .c(c) ); initial begin // Initialize Inputs clk = 0; rstn = 0; //Memory to set every opcode and addressing M[0] <= 16'b0000000000000000; M[1] <= 16'b0010000000000100; M[2] <= 16'b0011000000001010; M[3] <= 16'b0110000000000000; M[4] <= 16'b0100000000000111; M[5] <= 16'b0101000000001011; M[6] <= 16'b1000000000000000; M[7] <= 16'b1001000000001011; M[8] <= 16'b1010000000000010; M[9] <= 16'b1011000000001010; M[10] <= 16'b0000000000001000; M[11] <= 16'b0000000000001010; // Wait 100 ns for global reset to finish #100; // Add stimulus here rstn = 1; RD <= M[A]; end always @(clk) #1 clk <= ~clk; //Create clock always @ (posedge clk or negedge rstn or A) begin RD <= M[A]; end always @ (WD) begin if (WD == 0 && enableAC == 1) M[A] <= WD; end