From 0f1f3a13ac3c3b23510e142f042d25ca17de2b2f Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Wed, 22 May 2024 15:17:04 -0400 Subject: Fixed Bug with lw and sw --- qdme.c | 12 ++++++++++-- 1 file 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; -- cgit v1.2.3