You are on page 1of 6

The MiniMIPS Computer

By Dr. Cesar Ortega-Sanchez

Introduction
To support your learning of computer architecture, a small computer was implemented in the
FPGA board. The computer’s CPU is a reduced version of the MIPS called the MiniMIPS.
As you know, all computers have a Central Processing Unit (CPU), Memory (Instruction and Data)
and Input/Output (I/O) devices. In our computer the CPU and memories are inside the FPGA.
Table 1 shows the input and output devices of the BASYS board and how they are used.
I/O devices Use
LEDs (8) Display the contents of what is written to register 7
7-segment displays (4) Display the status of the system (see below)
Slide switches (8) Provide 8-bit numbers when reading register 7
Push-buttons (4) Control the system (see below)

Controlling the system


The system is controlled with the 4 push-buttons available in the board. The following description
shows how to use each button.
• Button 3 (BTN3) is the clock for the system. Every time you press it, one clock
cycle will be sent to the processor.

• Button 2 (BTN2) changes the content of the 7-segment displays. They present
the following information with every pulse:
Program Counter → Instruction → Operands A and B → ALU result

• Button 1 (BTN1) changes the content of the LEDs. If not pressed, the LEDs show
the content of the LEDs register. When pressed, the control signals generated by the
Main Decoder are presented in the following order:

LD7 LD6 LD5 LD4 LD3 LD2 LD1 LD0

Zero
Jump
MemtoReg
MemWr
Branch
ALUSrc
RegDst
RegWr

• Button 0 (BTN0) is the reset of the system. When pressed, the program counter
is reset to 0x00.
Description of the MiniMIPS processor
The CPU of our computer is a reduced version of the 32-bit MIPS covered in the lectures. Our
MIPS has 8-bit data buses and 16-bit instructions, hence it has been called the MiniMIPS. Apart
from the difference in buses width, the basic architecture remains the same. Figure 1 shows a
block diagram of the MiniMIPS processor. Notice the buses width and how they differ from the
original 32-bit MIPS.

Figure 1. MiniMIPS processor

All MiniMIPS instructions are 16-bit wide. The original MIPS instruction formats had to be modified
to fit in 16 bits. Figure 2 shows the modified instruction formats of the MiniMIPS.

15 12 11 9 8 6 5 32 0

R-type instructions Opcode RS RT RD Funct

15 12 11 9 8 6 5 0

I-type instructions Opcode RS RT imm

15 12 6 0

J-type instructions Opcode addr

Figure 2. Instruction formats for the MiniMIPS

In the MiniMIPS there are only 8 registers, hence 3 bits are sufficient to encode register operands
and destinations.
Immediates are 6-bit signed numbers; hence the range of values goes from -32 to 31.
The number of bits for the opcode was reduced from 6 to 4. Bits indicating the function in register
operations were reduced from 6 to 3. Table 1 presents the instruction set of the MiniMIPS.
Table 1. MiniMIPS instruction set

Instr. Opcode
Assembly instrution Meaning Comments
Format Opcode/Funct
add $rd, $rs, $rt R 0000/000 $rd = $rs + $rt Add contents of two registers
sub $rd, $rs, $rt R 0000/010 $rd = $rs - $rt Subtract contents of two registers
and $rd, $rs, $rt R 0000/100 $rd = $rs and $rt Logical AND of two registers
or $rd, $rs, $rt R 0000/101 $rd = $rs or $rt Logical OR of two registers
addi $rt, $rs, imm I 0100 $rt = $rs + imm Add signed constant to register
lw $rt, imm($rs) I 1011 $rt = M[$rs + imm] Load word from memory
sw $rt, imm($rs) I 1111 M[$rs + imm] = $rt Store word from memory
beq $rt, $rs, imm I 1000 if ($rs == $rt) then PC= PC+Imm*2 Branch if equal
j address J 0010 PC= address*2 Unconditional jump

Registers
The number of registers in the MiniMIPS was drastically reduced from 32 to 8. Register 7 is used to access I/O devices. Register 0 has a constant
value of 0x00. All other registers are general purpose. Table 2 shows the set of registers in the MiniMIPS and how they are used.

Table 2. MiniMIPS register set


Name Addr Comment
$0 0 Constant 0. (Read Only)
$r1 1 General purpose register
$r2 2 General purpose register
$r3 3 General purpose register
$r4 4 General purpose register
$r5 5 General purpose register
$r6 6 General purpose register
SWs 7 Reads from switches. ($rs or $rt) (Read Only)
LEDs 7 Writes to LEDs. ($rd) (Write Only)
Control Unit
As in the MIPS, the control unit is implemented with two decoders: the Main decoder and the ALU
decoder. Figure 3 shows a block diagram of the control unit.

RegWr
Opcode3:0
RegDst
Main ALUSrc
decoder Branch
MemWr
MemtoReg
Jump

ALUOp1:0

Funct2:0
ALU ALUControl2:0
decoder

Figure 3. Block diagram of the MiniMIPS Control Unit

Because the number of bits for the Opcode and Function fields changed, the truth tables defining
the Control Unit also changed. Tables 3 and 4 show the new truth tables for the Main and ALU
decoders respectively.
Table 3. Main decoder truth table
Instr Opcode RegWr RegDst ALUSrc Branch MemWr MemtoReg ALUOp Jump
R-Type 0000 1 1 0 0 0 0 10 0
lw 1011 1 0 1 0 0 1 00 0
sw 1111 0 X 1 0 1 X 00 0
beq 1000 0 X 0 1 0 X 01 0
addi 0100 1 0 1 0 0 0 00 0
j 0010 0 X X X 0 X XX 1

Table 4. ALU decoder truth table


ALUOp Funct ALUControl Operation
00 X 010 Add
X1 X 110 Sub
1X 000 010 Add
1X 010 110 Sub
1X 100 000 AND
1X 101 001 OR

MiniMIPS implementation
All modules in the block diagram of figure 1 as well as the high-level module were implemented in
VHDL. The MIPS can be simulated as a whole or by individual components.
Executing programs in the MiniMIPS
Like for any other computer, you need a tool to translate your assembly programs into the MIPS
machine code. I asked a couple of brilliant students to develop such tool and they delivered the
MiniMIPS simulator. This tool will assist you in the development of programs for the MiniMIPS as
it offers the following functions:
• Context-sensitive code editor. To add new lines of code you will only have to select the
instruction from a drop-down menu and then the operands will be validated accordingly.
No chances for mistyping or making mistakes in the order of operands.
• Save and load programs. Programs are stored as text files with extension .mips. It is
recommended that you save all your .mips files in a directory different to the MiniMIPS
project directory.
• Code simulator. Verify your code by running your programs on the screen and see what
happens to the content of registers, memory and I/O devices as instructions get executed.
• Export to VHDL. Once your code has been verified in the simulator, you can create a
VHDL file ready to substitute the imem.vhd file in your ISE project. You can have only
one imem.vhd file; therefore it is recommended that all files be exported with a different
name each. To test your new program, copy it to the MiniMIPS project directory and
rename it imem.vhd. They you can resynthesise the project and download the new
configuration file to the BASYS board.
Figure 4 shows a screenshot of the MiniMIPS simulator. Listing 1 shows the exported VHDL file.

Figure 4. Screenshot of the MiniMIPS simulator


Listing 1. VHDL file automatically generated by the MiniMIPS simulator

Notice that the code in Listing 1 is ready to be included into ISE’s MiniMIPS project. This code describes the
instruction memory of the computer.

You might also like