-1

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.

  • You write in C. Your program "simulates" the MIPs processor. You need to have a data structure that represent the registers (including the program counter), and presumably some RAM. Read the file , put the values in your "RAM", start with PC pointing to the start of your RAM. Then each instruction has some effect on the registers and RAM, so you program that for each instruction you might encounter. – The Archetypal Paul Nov 01 '22 at 18:15
  • To the first order, you're being asked to write a program. It is not specified (as far as we know from your question post) what language you're supposed to use to write this program; perhaps you're free to use any language, which could range from C#, Java, C++, C, or even MIPS assembly. – Erik Eidt Nov 01 '22 at 20:34
  • Your program is supposed to simulate a MIPS processor. A MIPS processor consumes MIPS programs, which are composed of MIPS instructions; each MIPS instruction has some effect on the MIPS program's running state. So, there's two programs involved, and you have to mentally keep them separate. There's the program you're writing, which is a simulator, and then there's the program that the simulator is running, which is a MIPS binary of some sort. – Erik Eidt Nov 01 '22 at 20:35

1 Answers1

0

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++;
    }
}
puppydrum64
  • 1,598
  • 2
  • 15