Skip to content

Commit

Permalink
Fix stalling and add more samples
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterhedges committed Apr 29, 2018
1 parent 37a8c83 commit 7bf2440
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 19 deletions.
1 change: 0 additions & 1 deletion css/styles.min.css

This file was deleted.

7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- Bootstrap CSS -->
<link href="depends/bootstrap-4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<!-- Site CSS -->
<link href="css/styles.min.css" rel="stylesheet" />
<link href="css/styles.css" rel="stylesheet" />
<!-- jQuery -->
<script src="depends/jquery-3.3.1.min.js"></script>
<!-- Bootstrap JS -->
Expand Down Expand Up @@ -202,7 +202,10 @@ <h5 class="modal-title" id="modalTitle"><!-- Modal Title --></h5>
</div>
<!-- End Error Modal -->

<script src="js/mipsSimulator.min.js"></script>
<script src="js/extensions.js"></script>
<script src="js/parseInputFile.js"></script>
<script src="js/mipsInstructions.js"></script>
<script src="js/simulate.js"></script>

</body>
</html>
53 changes: 42 additions & 11 deletions js/mipsInstructions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const ACTIONS = {
DECODE: "decode",
EXECUTE: "execute"
EXECUTE: "execute",
SHOULD_STALL: "stall"
}

// ExecutionResult object returned by MIPS instruction on execute action.
Expand All @@ -10,8 +11,9 @@ const ACTIONS = {
// Memory location and value object affected if applicable
// Bool if the instruction causes a branch
// Integer of branch offset if shouldBranch = true
function ExecutionResult(stallAmount, registerState, memoryState, shouldBranch, branchOffset) {
function ExecutionResult(stallLocation, stallAmount, registerState, memoryState, shouldBranch, branchOffset) {

this.stallLocation = stallLocation;
this.stallAmount = stallAmount;
this.registerState = registerState;
this.memoryState = memoryState;
Expand Down Expand Up @@ -196,13 +198,17 @@ function add(binaryInstructionString, action) {
setRegisterDefault(rs);
setRegisterDefault(rt);

var stallLocation = rd;
var stallAmount = 2;
var registerState = { register: rd, value: registers[rs] + registers[rt] };
var memoryState = null;
var shouldBranch = false;
var branchOffset = 0;

return new ExecutionResult(stallAmount, registerState, memoryState, shouldBranch, branchOffset);
return new ExecutionResult(stallLocation, stallAmount, registerState, memoryState, shouldBranch, branchOffset);
}
else if(action == ACTIONS.SHOULD_STALL) {
return [rs, rt];
}

}
Expand All @@ -222,13 +228,17 @@ function addi(binaryInstructionString, action) {
else if(action == ACTIONS.EXECUTE) {
setRegisterDefault(rs);

var stallLocation = rt;
var stallAmount = 2;
var registerState = { register: rt, value: registers[rs] + imm };
var memoryState = null;
var shouldBranch = false;
var branchOffset = 0;

return new ExecutionResult(stallAmount, registerState, memoryState, shouldBranch, branchOffset);
return new ExecutionResult(stallLocation, stallAmount, registerState, memoryState, shouldBranch, branchOffset);
}
else if(action == ACTIONS.SHOULD_STALL) {
return [rs];
}

}
Expand Down Expand Up @@ -260,7 +270,10 @@ function branchOnEqual(binaryInstructionString, action) {
branchOffset = offset;
}

return new ExecutionResult(stallAmount, registerState, memoryState, shouldBranch, branchOffset);
return new ExecutionResult(null, stallAmount, registerState, memoryState, shouldBranch, branchOffset);
}
else if(action == ACTIONS.SHOULD_STALL) {
return [rs, rt];
}

}
Expand Down Expand Up @@ -292,7 +305,10 @@ function branchNotEqual(binaryInstructionString, action) {
branchOffset = offset;
}

return new ExecutionResult(stallAmount, registerState, memoryState, shouldBranch, branchOffset);
return new ExecutionResult(null, stallAmount, registerState, memoryState, shouldBranch, branchOffset);
}
else if(action == ACTIONS.SHOULD_STALL) {
return [rs, rt];
}

}
Expand All @@ -314,14 +330,17 @@ function loadWord(binaryInstructionString, action) {
setRegisterDefault(rs);
setMemoryDefault(rs + offset);

var stallLocation = rt;
var stallAmount = 2;
var registerState = { register: rt, value: memory[registers[rs] + offset] };
var memoryState = null;
var shouldBranch = false;
var branchOffset = 0;

return new ExecutionResult(stallAmount, registerState, memoryState, shouldBranch, branchOffset);

return new ExecutionResult(stallLocation, stallAmount, registerState, memoryState, shouldBranch, branchOffset);
}
else if(action == ACTIONS.SHOULD_STALL) {
return [rs];
}

}
Expand Down Expand Up @@ -349,7 +368,10 @@ function storeWord(binaryInstructionString, action) {
var shouldBranch = false;
var branchOffset = 0;

return new ExecutionResult(stallAmount, registerState, memoryState, shouldBranch, branchOffset);
return new ExecutionResult(null, stallAmount, registerState, memoryState, shouldBranch, branchOffset);
}
else if(action == ACTIONS.SHOULD_STALL) {
return [rs, rt];
}

}
Expand Down Expand Up @@ -380,11 +402,16 @@ function setOnLessThan(binaryInstructionString, action) {
registerState = { register: rd, value: 0 };
}

var stallLocation = rd;
var stallAmount = 2;
var memoryState = null;
var shouldBranch = false;
var branchOffset = 0;

return new ExecutionResult(stallAmount, registerState, memoryState, shouldBranch, branchOffset);
return new ExecutionResult(stallLocation, stallAmount, registerState, memoryState, shouldBranch, branchOffset);
}
else if(action == ACTIONS.SHOULD_STALL) {
return [rs, rt];
}

}
Expand All @@ -405,13 +432,17 @@ function sub(binaryInstructionString, action) {
setRegisterDefault(rs);
setRegisterDefault(rt);

var stallLocation = rd;
var stallAmount = 2;
var registerState = { register: rd, value: registers[rs] - registers[rt] };
var memoryState = null;
var shouldBranch = false;
var branchOffset = 0;

return new ExecutionResult(stallAmount, registerState, memoryState, shouldBranch, branchOffset);
return new ExecutionResult(stallLocation, stallAmount, registerState, memoryState, shouldBranch, branchOffset);
}
else if(action == ACTIONS.SHOULD_STALL) {
return [rs, rt];
}

}
Loading

0 comments on commit 7bf2440

Please sign in to comment.