Skip to content

Commit d5a302d

Browse files
committed
peter1010
1 parent 867f43d commit d5a302d

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

branchTest.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ addi $1 $0 88
22
addi $2 $1 0
33
beq $1 $2 1
44
addi $2 $2 4
5-
addi $3 $2 0
5+
addi $3 $2 0
6+
haltSimulation

lwTest.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ sw $1 4($2)
44
addi $3 $0 8
55
lw $4 4($2)
66
add $5 $4 $3
7+
haltSimulation

rawTest.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
addi $1 $0 80
22
addi $2 $0 8
33
add $3 $1 $2
4-
addi $4 $3 0
4+
addi $4 $3 0
5+
haltSimulation

sim-mips.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ int main (int argc, char *argv[]){
241241
int IF_c,ID_c,EX_c,MEM_c,WB_c;
242242
IF_c = 0; ID_c = 0; EX_c = 0; MEM_c = 0; WB_c = 0;
243243

244+
244245
while(!HALT_SIMULATION){
245246
printf("\n\n\nPROGRAM COUNT:%d ##################\n",pgm_c);
246247

@@ -283,6 +284,8 @@ int main (int argc, char *argv[]){
283284
}
284285

285286

287+
288+
286289

287290

288291

@@ -1218,12 +1221,15 @@ int MEM(int mem_cycles, struct buffer ExeMem){//should take sim_cycle, c from co
12181221
int address = ExeMem.instruction.rs + ExeMem.instruction.Imm;
12191222

12201223
if(ExeMem.instruction.opcode == sw){
1221-
ExeMem.instruction.rt = dataMemory[address];
1224+
//ExeMem.instruction.rt = dataMemory[address];
1225+
dataMemory[address] = ExeMem.instruction.rt;
1226+
12221227

12231228
cycles += mem_cycles;
12241229

12251230
}else if(ExeMem.instruction.opcode == lw){
1226-
dataMemory[address] = ExeMem.instruction.rt;
1231+
//dataMemory[address] = ExeMem.instruction.rt;
1232+
ExeMem.instruction.rt = dataMemory[address];
12271233

12281234
cycles += mem_cycles;
12291235
}
@@ -1250,7 +1256,7 @@ int WB(long *registers, struct buffer MemWb){
12501256

12511257
cycles++;
12521258

1253-
}else if(MemWb.instruction.opcode == sw){
1259+
}else if(MemWb.instruction.opcode == lw){
12541260
registers[MemWb.instruction.rd] = MemWb.instruction.rt;
12551261

12561262
cycles++;

sim-test.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ int progScanner_Test1(){
104104

105105
char *testStr = progScanner("add $s0,,$s1 , $s2");
106106

107-
printf("Here is the string:%s\n", testStr);
108-
109107
return strcmp(testStr, "add $s0 $s1 $s2") == 0;
110108
}
111109

@@ -183,9 +181,9 @@ int parser_Test3(){
183181
}
184182

185183
int parser_Test4(){
186-
struct inst test = {lw, 8, 16, 0, 8};
184+
struct inst test = {lw, 8, 16, 0, 4};
187185

188-
char *line = regNumberConverter(progScanner("lw $s0 8 $t0"));
186+
char *line = regNumberConverter(progScanner("lw $s0 4 $t0"));
189187
printf("%s\n", line);
190188

191189
struct inst peter = parser(regNumberConverter("lw $s0 8 $t0"));
@@ -225,10 +223,10 @@ int parser_Test6(){
225223
}
226224

227225
int parser_Test7(){
228-
struct inst test = {lw, 8, 16, 0, 8};
226+
struct inst test = {lw, 8, 16, 0, 24};
229227

230228
printf("%s\n", progScanner("lw $s0, 8($t0)"));
231-
char *line = regNumberConverter(progScanner("lw $s0, 8($t0)"));
229+
char *line = regNumberConverter(progScanner("lw $s0, 24($t0)"));
232230
printf("[%s]\n", line);
233231

234232

0 commit comments

Comments
 (0)