diff --git a/README.md b/README.md index 114e4e8..6cb95ff 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # 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) @@ -16,11 +16,57 @@ In this version, all data and control hazards are handled with stalls and there 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" 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" 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. diff --git a/array-max-min.txt b/memory-initial-state/array-max-min.txt similarity index 96% rename from array-max-min.txt rename to memory-initial-state/array-max-min.txt index a9bba1e..88a1957 100644 --- a/array-max-min.txt +++ b/memory-initial-state/array-max-min.txt @@ -36,4 +36,4 @@ 00000000000000000000000000000011 00000000000000000000000000000000 00000000000000000000000000001001 -11111111111111111111111111101001 \ No newline at end of file +11111111111111111111111111101001 diff --git a/memory_state1.txt b/memory-initial-state/memory_state1.txt similarity index 100% rename from memory_state1.txt rename to memory-initial-state/memory_state1.txt diff --git a/memory_state2.txt b/memory-initial-state/memory_state2.txt similarity index 100% rename from memory_state2.txt rename to memory-initial-state/memory_state2.txt diff --git a/memory_state3.txt b/memory-initial-state/memory_state3.txt similarity index 100% rename from memory_state3.txt rename to memory-initial-state/memory_state3.txt diff --git a/mips/memory.go b/mips/memory.go index d804624..a41e60a 100644 --- a/mips/memory.go +++ b/mips/memory.go @@ -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") diff --git a/Instructions.png b/pics/Instructions.png similarity index 100% rename from Instructions.png rename to pics/Instructions.png diff --git a/architecture.png b/pics/architecture.png similarity index 100% rename from architecture.png rename to pics/architecture.png diff --git a/pics/assembly.png b/pics/assembly.png new file mode 100644 index 0000000..d1d6eb7 Binary files /dev/null and b/pics/assembly.png differ