Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update

  • Loading branch information...
commit f8608111ce0a35b7a47e90dd9d3b83bcce38cb39 1 parent d65afea
@blake-regalia authored
Showing with 22 additions and 9 deletions.
  1. +3 −2 CacheSystem.java
  2. +19 −7 Simulator.java
View
5 CacheSystem.java
@@ -152,8 +152,9 @@ private int addressToIndex(int address, int cacheMask) {
return (address & cacheMask) >> this.indexShift;
}
public boolean isStalling(){
- stalls--;
- return stalls==0;
+ stalls = stalls - 1;
+ stalls = Math.max(0, stalls);
+ return (stalls != 0);
}
public int write(int address, int memData) {
View
26 Simulator.java
@@ -210,15 +210,27 @@ else if(instruction.getAsrc()==0 && r == instruction.getRt()){
if(memory.isStalling()){
stalled = true;
}
+ else {
+ stalled = false;
+ }
}
- if(instruction.getMtr()==1) {
+ else if(instruction.getMtr()==1) {
memoryOut = memory.read(aluResult/4);
if(memory.isStalling()){
stalled = true;
}
+ else {
+ stalled = false;
+ }
}else{
memoryOut = aluResult;
}
+
+ if(stalled) {
+ System.out.println("--- memory stage: stalled ---");
+ break;
+ }
+
instruction.setStage(WRITEBACK_STAGE);
break;
@@ -250,11 +262,11 @@ else if(instruction.getAsrc()==0 && r == instruction.getRt()){
//System.out.println("Added to pipeline size "+pipeline.size());
}
//print stats
- System.out.println("Fetch instruction: "+(fetchInstruction!=null?fetchInstruction.toString():""));
- System.out.println("Decode instruction: "+(decodeInstruction!=null?decodeInstruction.toString():""));
- System.out.println("Execute instruction: "+(executeInstruction!=null?executeInstruction.toString():""));
- System.out.println("Memory instruction: "+(memoryInstruction!=null?memoryInstruction.toString():""));
- System.out.println("Writeback instruction: "+(writebackInstruction!=null?writebackInstruction.toString():""));
+ System.out.println("Fetch: "+(fetchInstruction!=null?fetchInstruction.toString():""));
+ System.out.println("Decode: "+(decodeInstruction!=null?decodeInstruction.toString():""));
+ System.out.println("Execute: "+(executeInstruction!=null?executeInstruction.toString():""));
+ System.out.println("Memory: "+(memoryInstruction!=null?memoryInstruction.toString():""));
+ System.out.println("Writeback: "+(writebackInstruction!=null?writebackInstruction.toString():""));
for(int i = 0; i< 8;i++)
{
@@ -338,7 +350,7 @@ public void start() {
//call clockcycle repeatedly
do {
- System.out.println("Cycle "+index+":");
+// System.out.println("Cycle "+index+":");
index++;
}while (clockCycle());
System.out.println("Cycles: "+index);
Please sign in to comment.
Something went wrong with that request. Please try again.