Pre-Lab4 Digital Design
Pre-Lab4 Digital Design
A SIMPLE PROCESSOR
OBJECTIVES
➢ The purpose of this lab is to learn how to connect simple input (switches) and output devices
(LEDs and 7-segment) to an FPGA chip and implement a circuit that uses these devices.
➢ Examine a simple processor.
REFERENCE
1. Intel FPGA training
Requirement: Use the information in the introduction, convert these instructions to machine codes.
mv R1,R4
mv R3,R2
mvi R2,#5
mvi R4,#-6
add R3,R7
add R2,R0
sub R5,R6
Check: Your report has to show two results:
Requirement: Use the information in the introduction, sketch the FSM of the control unit.
➢ FSM diagram.
Requirement: A diagram of the random access memory (ROM) module that we will implement is
shown in Figure 2a. It contains 32 four-bit words (rows), which are accessed using a nine-bit
address port, a four-bit data port.
Instruction: The System Verilog code for ROM (nine-bit address port, a four-bit data port) is
shown:
module MyROM
#(parameter int unsigned width = 9,
parameter int unsigned depth = 32,
parameter intFile = "inst_mem.mif",
localparam int unsigned addrBits = 5)
(
input logic CLK,
input logic [addrBits-1:0] ADDRESS,
output logic [width-1:0] DATAOUT
);
The $readmemh task reads a hex file to the rom array which is effectively the memory. The name
of the hex file is passed to the spROM module as a parameter.
After constructing ROM, data inside is empty. We can define data in ROM by using
“my_ROM.mif” file. This file is only used with Quartus tool (see comments for details). An
example of ‘.mif’ file is shown below. In ‘.mif’ file, the comments are written between two ‘% %’
signs (both single line and multiline). Further, we need to define certain parameters i.e. data and
address types (see comments for details). Lastly, in file, we set the values at all the addresses as
‘0’ and then values are assigned at each address. This can be useful, when we want to store data at
fewer locations. (Remember that in this file mif example, ROM is 16x7).
% rom_data.mif %
% ROM data for seven segment display %
%
format of data and address stored in this file
uns : unsigned, dec : decimal, hex : hexadecimal
bin : binary, oct : octal
%
address_radix=uns; % address is unsigned-type %
data_radix=bin; % data is binary-type %
% ROM data %
content begin
[0..15] : 0000000; % optional : assign 0 to all address %
0 : 1000000; % format => signed : binary %
1 : 1111001;
2 : 0100100;
3 : 0110000;
4 : 0011001;
5 : 0010010;
6 : 0000010;
7 : 1111000;
8 : 0000000;
9 : 0010000;
10 : 0001000;
11 : 0000011;
12 : 1000110;
13 : 0100001;
end;
System Verilog top module for ROM is:
module top_mem (
input logic CLK,
input logic [4:0] ADDRESS,
output logic [8:0] DATA
);
MyROM U0 (
.CLK (CLK ),
.ADDRESS (ADDRESS ),
.DATAOUT (DATA )
);
endmodule : top_mem
Check: Modify the code above to construct the circuit in Figure 2b. Data in ROM is defined by
the machine code in exercise 1.