Skip to content

Commit

Permalink
organize files
Browse files Browse the repository at this point in the history
  • Loading branch information
alabarjasteh committed Aug 10, 2021
1 parent e69af41 commit c414c9d
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 10 deletions.
62 changes: 54 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,72 @@
# FUM-MIPS
## Overview
FUM-MIPS is a 5-stage CPU, that supports a subset of MIPS Instruction Set. It is a 32-bit CPU with 32 general purpose registers.
Figure below shows an overview of the architecture.
FUM-MIPS is a 5-stage CPU, that supports a subset of the MIPS Instruction Set. It is a 32-bit CPU with 32 general-purpose registers.
The figure below shows an overview of the architecture.


![overview of architecture](architecture.png)
![overview of architecture](pics/architecture.png)

Supporting instructions are brought in the table below.

![instructions](Instructions.png)
![instructions](pics/Instructions.png)



In this version, all data and control hazards are handled with stalls and there are no forwarding paths.
My strategy for dealing with data hazards is to use a scoreboard for recognizing the pending registers.

### Code Structure
Each of 5 stages is implemented as a goroutine and stages pass messages using buffered channels. This is the most accurate simulation according to how CPU's pipeline works, as stages work asychronously.
Each of the 5 stages is implemented as a goroutine and stages pass messages using buffered channels. This is the most accurate simulation according to how CPU's pipeline works, as stages work asynchronously.

## Application
The simulator gets a file to load the initial memory state and starts from the first line.
For validating the simulator I write an app "array-max-min.txt" that iterates through an array of size 10 and writes maximum and minimum elements in memory words.
The simulator gets a file to load the initial memory state and starts executing from the first line. To add an application, put your binary code in the "memory-initial-state" folder.\
For validating the simulator I write an app "array-max-min.txt" that iterates through an array of size 10 and writes maximum and minimum elements in memory words. Assembly code is as below:

![assebly](pics/assembly.png)

And its equivalent binary code is:

```
10001100000000010000000001100100
10001100000000100000000001101000
10001100000000110000000001101100
00110100000001000000000000000000
10001100000001010000000001110000
00010000100000010000000000001011
10001100101001100000000000000000
00000000010001100011100000101010
00010000000001110000000000000001
00000000000001100001000000100000
00000000110000110011100000101010
00010000000001110000000000000001
00000000000001100001100000100000
00100000100001000000000000000001
00100000101001010000000000000100
00001000000000000000000000000101
10101100000000100000000010011100
10101100000000110000000010100000
00000000000000000000000000001010
10000000000000000000000000000000
01111111111111111111111111111111
00000000000000000000000001110100
00000000000000000000000101000001
11111111111111111111111111110100
00000000000000000000000010000110
00000000000000000000000000000000
11111111110101111111000001110011
00000000000100110010110101001101
00000000000000000000000000000011
00000000000000000000000000000000
00000000000000000000000000001001
11111111111111111111111111101001
```

### Run
Go to project's directory and enter `go build`, then type `./mips-simulator -file=<filename.txt>`. "filename" is composed of binary code of CPU intructions and data. Each of 32-bit memory words, must be on a new line. See attached example files.
Go to the project's directory and enter `go build`, then type `./mips-simulator -file=<filename.txt>`. "filename" is composed of binary code of CPU instructions and data. Each of the 32-bit memory words must be on a new line. See attached example files.
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
00000000000000000000000000000011
00000000000000000000000000000000
00000000000000000000000000001001
11111111111111111111111111101001
11111111111111111111111111101001
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion mips/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewMemory(fileName string) Memory {
}

func (mem Memory) loadMemoryFromFile(fileName string) {
file, err := os.Open("./" + fileName)
file, err := os.Open("./memory-initial-state/" + fileName)
if err != nil {
log.Fatalf("failed to open")

Expand Down
File renamed without changes
File renamed without changes
Binary file added pics/assembly.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c414c9d

Please sign in to comment.