Implemented a single-cycle 4-bit MIPS processor implementation that can execute a subset of MIPS instructions. The processor follows the classic five-stage datapath design. The main components include:
- 8-bit D Flip-Flop: Stores the current program counter
- Instruction Memory: ROM containing 16-bit instructions
- PC Logic: Handles sequential execution and jumps
- Multiplexer: Selects between PC+1 (sequential) and jump address
- Input: 4-bit opcode from instruction[15:12]
- ROM-based: Uses a lookup table to generate control signals
- Outputs: 12 control signals including:
- RegDst: Register destination selection
- RegWrite: Enable register writing
- ALUSrc: ALU source selection
- MemRead/MemWrite: Memory operation controls
- MemtoReg: Memory to register data selection
- Branch controls (beq, bneq)
- Jump control
- ALUop: 3-bit ALU operation code
- 5 Registers: $t0, $t1, $t2, $t3, $t4 (4-bit each)
- Dual Read Ports: Can read two registers simultaneously
- Single Write Port: Writes to one register per cycle
- Clock-enabled Writing: Only writes when RegWrite is asserted
- 4-bit inputs: A and B
- 8 Operations: Based on 3-bit ALUop control
- Addition, Subtraction
- Logical AND, OR, NOR
- Shift operations (left/right)
- Zero Flag: Used for branch instructions
- RAM: 4-bit address, 4-bit data width
- Separate Read/Write: Controlled by MemRead/MemWrite signals
- Clock-synchronized: Memory operations occur on clock edge
- PC Arithmetic: Handles PC+1 for sequential execution
- Branch Target: Calculates branch addresses
- Mode Selection: Can add or subtract based on control
[15:12] [11:8] [7:4] [3:0]
Opcode Src1 Src2 Dest
Examples: add, sub, and, or, nor
[15:12] [11:8] [7:4] [3:0]
Opcode Src1 Dest Immediate/Address
Examples: addi, andi, ori, lw, sw, beq, bneq
[15:12] [11:8] [7:4] [3:0]
Opcode Src1 Dest Shift_Amount
Examples: sll, srl
[15:12] [11:4] [3:0]
Opcode Jump_Address 0000
Example: j (jump)
- Instruction Fetch: PC → Instruction Memory → 16-bit instruction
- Decode: Instruction fields split and sent to respective components
- Register Read: Register file outputs source register values
- Execute: ALU performs operation based on ALUop
- Memory Access: Load/Store operations access data memory
- Write Back: Results written to destination register
The control unit uses a ROM lookup table where:
- Address: 4-bit opcode
- Data: 12-bit control word containing all necessary control signals
- ALU Source: Choose between register or immediate value
- Register Destination: R-type vs I-type destination selection
- Write Data: ALU result vs Memory data vs PC+1
- PC Source: Sequential vs Jump vs Branch address
- Zero Detection: ALU zero flag for beq/bneq
- Branch Address: PC + offset calculation
- Branch Decision: AND gate combines branch control with condition
- Instruction Memory: Read-only, addressed by PC
- Data Memory: Read/Write, addressed by ALU result
- Separate Address Spaces: Harvard architecture style
The processor implements 16 different instructions (4-bit opcode):
- Arithmetic: add, sub, addi, subi
- Logic: and, or, nor, andi, ori
- Shift: sll, srl
- Memory: lw, sw
- Control: beq, bneq, j
Write a valid MIPS assembly code and compile the code with MIPS-assembler. Now open the MIPS-simulator with logisim 2.7.1
Then open the machine.txt
file (generated after runnig the C++ code) from the instruction memory.
- R-type:
Opcode | Src Reg 1 | Src Reg 2 | Dst Reg |
---|---|---|---|
4-bits | 4-bits | 4-bits | 4-bits |
- S-type:
Opcode | Src Reg 1 | Dst Reg | Shamt |
---|---|---|---|
4-bits | 4-bits | 4-bits | 4-bits |
- I-type:
Opcode | Src Reg 1 | Src Reg 2/Dst Reg | Addr./Immdt |
---|---|---|---|
4-bits | 4-bits | 4-bits | 4-bits |
- J-type:
Opcode | Target Jump Address | 0 | |
---|---|---|---|
4-bits | 8-bits | 4-bits |
Instruction Opcode | Instruction | MIPS Instruction Format | Instruction Type |
---|---|---|---|
0000 | sub | R | Arithmetic |
0001 | ori | I | Logic |
0010 | bneq | I | Control |
0011 | addi | I | Arithmetic |
0100 | beq | I | Control |
0101 | or | R | Logic |
0110 | sw | I | Memory |
0111 | srl | S | Logic |
1000 | and | R | Logic |
1001 | andi | I | Logic |
1010 | lw | I | Memory |
1011 | add | R | Arithmetic |
1100 | sll | S | Logic |
1101 | subi | I | Arithmetic |
1110 | j | J | Control |
1111 | nor | R | Logic |
The adder takes two 32 bit floating point numbers and adds them together. The numbers are represented in the following format:
Sign | Exponent | Fraction |
---|---|---|
1 bit | 10 bits | 21 bits (Lowest bits) |
The numbers are in normalized form. There are two flags U (underflow) and O (overflow) which are set if the result is too small or too large to be represented in the format.
- Sign check: Checks if a 32 floating point number is positive, negative or the exponent is zero. If the number is positive then the output is the same as input. If the number is negative then it outputs the two's complement of the input. And if the exponent is zero then the output is zero.
- Normalizer: Normalizes a floating point number. But if the number is overflowed or under flowed while trying to normalize then the appropriate flags are set.
- Rounder: Rounds the 32 bit significant to 21 bits.
This ALU contains:
- Two 4 bit inputs A and B
- Three select bits S2, S1, S0 as ALU opcodes
- One 4 bit output
- Four flags: Z (Zero), C (Carry), O (Overflow), N (Negative)
ALU opcodes | Functions | ||
---|---|---|---|
S2 | S1 | S0 (Cin) | |
0 | 0 | 0 | Transfer A |
0 | 0 | 1 | Increment A |
0 | 1 | X | AND |
1 | 0 | 0 | Add |
1 | 0 | 1 | Add with carry |
1 | 1 | X | OR |
ALU opcodes | Required outputs | Adder inputs | Functions | ||||
---|---|---|---|---|---|---|---|
S2 | S1 | S0 (Cin) | Xi | Yi | Zi | ||
0 | 0 | 0 | A | Ai | 0 | Ci | Transfer A |
0 | 0 | 1 | A + 1 | Increment A | |||
0 | 1 | 0 | A ^ B | AiBi | 0 | 0 | AND |
0 | 1 | 1 | |||||
1 | 0 | 0 | A + B | Ai | Bi | Ci | Add |
1 | 0 | 1 | A + B + 1 | Add with carry | |||
1 | 1 | 0 | A OR B | AiBi' | Bi | 0 | OR |
1 | 1 | 1 |
Xi = A(S1' + S2 XOR B)
Yi = S2B
Zi = S1'Ci