How would I write a MIPS behavioral simulator for the machine code created using the assembler code provided?

231 views Asked by At

This MIPS simulator will read in a text file consisting of LC3100 machine code instructions (represented as decimal values), and execute the program, then display the values of register files and memory after each instruction is completed.

I do not understand how this can be done and simply need a format for what steps I need to take in order to create the simulator in MIPS. Do I write code in C++ or write the code in MIPS? How do I read files if it is in MIPS? Honestly, just confused.

I do not know where I need to start from. This is what I am asking to help figure out.

1

There are 1 answers

0
puppydrum64 On

I'd imagine you'd want to create some global variables that represent your registers and memory:

int memory[0x80000000/4];
int reg_v0;
int reg_t0;
int* reg_pc;
// etc

And then define some functions that mimic the way MIPS behaves. You'll need to read up on how the CPU operates (which is why this example function may seem arbitrary but really it isn't.)

void MIPS_multu(int regA, int regB)
{
// void because we're writing to global variables.
     uint64_t temp = regA * regB;
     reg_hi = temp >> 32;
     reg_lo = (temp & 0x00000000FFFFFFFF);
}

Finally, you'll need to understand how MIPS instructions are encoded and create a routine that can unpack them and select the correct function.

int memory[0x80000000/4];
int reg_v0;
int reg_t0;
int* reg_pc;
// etc

int main()
{
reg_pc = &memory[0];

while (reg_pc < &memory[0x80000000/4])
// chances are this is either invalid C or just bad practice, 
// but I can't think of a better way to express the idea
    {
    int temp = *reg_pc;
    // use bitwise operators etc to figure out what the instruction represents, 
    // and switch cases to pick the functions.
    reg_pc++;
    }
}