summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@jacobmcdonnell.com>2024-05-22 15:17:04 -0400
committerJacob McDonnell <jacob@jacobmcdonnell.com>2024-05-22 15:17:04 -0400
commit0f1f3a13ac3c3b23510e142f042d25ca17de2b2f (patch)
tree825b757727213762cf1d097e698b985f84a1997c
parentd77453f48c9bd1a59938da815004feaf9f147d6a (diff)
Fixed Bug with lw and sw
-rwxr-xr-xqdme.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/qdme.c b/qdme.c
index 543f234..7ddd1ce 100755
--- a/qdme.c
+++ b/qdme.c
@@ -227,10 +227,12 @@ void InstExec(const inst_t inst) {
regFile[inst.i.rt] = (uint16_t)imm << 16;
break;
case 35: // lw
- memcpy(regFile + inst.i.rs, memory + inst.i.rt + imm, WORD_SIZE);
+ memcpy(regFile + inst.i.rt, memory + regFile[inst.i.rs] + imm,
+ WORD_SIZE);
break;
case 43: // sw
- memcpy(memory + inst.i.rt + imm, regFile + inst.i.rs, WORD_SIZE);
+ memcpy(memory + regFile[inst.i.rs] + imm, regFile + inst.i.rt,
+ WORD_SIZE);
break;
}
}
@@ -259,6 +261,12 @@ int LoadBinary(const char * const path) {
offset += i;
}
+ for (size_t i = 0; i < offset; i += 4) {
+ uint32_t x;
+ memcpy(&x, memory + i, sizeof(x));
+ printf("%02lu: 0x%08x\n", i, x);
+ }
+
if (ferror(fp) || !feof(fp)) {
perror("fread");
return -1;