Link to home
Create AccountLog in
Avatar of sundeepgopal
sundeepgopal

asked on

Ideas and links for implementing MIPS simulator

Hi experts,
Please help!!!
For this project  I'll create a simple MIPS simulator. My MIPS simulator will be capable of loading a specified MIPS binary file (or text file) and outputting the assembly code equivalent and the cycle-by-cycle simulation of the MIPS binary code.
Initailly I want  to create a disassembler. My program will be capable of loading a provided binary file (or text file) and displaying the MIPS assembly code equivalent along with the binary code.

Could you guys please give me some suggestions and relevant linlks for studying to implement it ?

What language would be good to implement the simulator?

thanks
sundeep
Avatar of sundeepgopal
sundeepgopal

ASKER

For more information , the input text file looks like
***************************************************************
00100000000010000000000000101100
00100000000001100000000000000001
10101100000001100000001001011000
00100000000001110000000000000100
10101100111001100000001001011000
00100000000010100000000000001000
00100001010000111111111111111000
10001100011000010000001001011000
00100001010001001111111111111100
10001100100000100000001001011000
00000000001000100010100000100000
10101101010001010000001001011000
00100001010010100000000000000100
00010001010010000000000000000001
00001000000000000000000010000010
00000000000000000000000000000000
00000000000000000000000000001101
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000

*******************************************************************

         The output file looks like

*******************************************************************
001000 00000 01000 00000 00000 101100     496     ADDI     R8, R0, #44
001000 00000 00110 00000 00000 000001     500     ADDI     R6, R0, #1
101011 00000 00110 00000 01001 011000     504     SW     R6, 600(R0)
001000 00000 00111 00000 00000 000100     508     ADDI     R7, R0, #4
101011 00111 00110 00000 01001 011000     512     SW     R6, 600(R7)
001000 00000 01010 00000 00000 001000     516     ADDI     R10, R0, #8
001000 01010 00011 11111 11111 111000     520     ADDI     R3, R10, #-8
100011 00011 00001 00000 01001 011000     524     LW     R1, 600(R3)
001000 01010 00100 11111 11111 111100     528     ADDI     R4, R10, #-4
100011 00100 00010 00000 01001 011000     532     LW     R2, 600(R4)
000000 00001 00010 00101 00000 100000     536     ADD     R5, R1, R2
101011 01010 00101 00000 01001 011000     540     SW     R5, 600(R10)
001000 01010 01010 00000 00000 000100     544     ADDI     R10, R10, #4
000100 01010 01000 00000 00000 000001     548     BEQ     R10, R8, #4
000010 00000 00000 00000 00010 000010     552     J     #520
000000 00000 00000 00000 00000 000000     556     NOP
000000 00000 00000 00000 00000 001101     560     BREAK
00000000000000000000000000000000           564     0
00000000000000000000000000000000           568     0
00000000000000000000000000000000           572     0
00000000000000000000000000000000           576     0
00000000000000000000000000000000           580     0
00000000000000000000000000000000           584     0
00000000000000000000000000000000           588     0
00000000000000000000000000000000           592     0
00000000000000000000000000000000           596     0
00000000000000000000000000000000           600     0
00000000000000000000000000000000           604     0
00000000000000000000000000000000           608     0
00000000000000000000000000000000           612     0
00000000000000000000000000000000           616     0
00000000000000000000000000000000           620     0
00000000000000000000000000000000           624     0
00000000000000000000000000000000           628     0
00000000000000000000000000000000           632     0
00000000000000000000000000000000           636     0

**************************************************************************
I've written disassemblers in the past and always used C, but that's probably because I'm most comfortable with that, but the disassembler could be written in more or less anything - even JavaScript if you really wanted to go that way :-)

For writing a sumulator, it should be something that compiles to directly executable code, so C or C++ is probably your best bet. I'm not familiar with MIPS hardware, but I imagine it's the usual set of instructions that use memory addresses and registers and flags. It's not easy, but it's certainly not rocket science.
I forgot you were looking for tips, but if you google for "opensource disassembler", you'll get 253000 results. Disassemblers are pretty easy to do.

The only processor emulator I actually played with is for a PIC (http://www.picemulator.com/) which is probably a lot less complex than your MIPS chip. However, this is opensource and it's good, so this is probably a good place to start.
Hi sundeepgopal,

Seems like quite a simple encoding:

001000 00000 01000 00000 00000 101100     496     ADDI     R8, R0, #44
001000 00000 00110 00000 00000 000001     500     ADDI     R6, R0, #1
101011 00000 00110 00000 01001 011000     504     SW     R6, 600(R0)
001000 00000 00111 00000 00000 000100     508     ADDI     R7, R0, #4

Looks like the first bit indicates indirection for one of the registers, the second may be the same for the other one.

The next 4 bits looks like the instruction. Just extract the bits and use their value for a lookup table:

char * Instructions[] = {
"ADD", // 0
...
"J", // 2
"LW", // 3
"BEQ", // 4
...
"ADDI", // 8
...
"SW", // 11


};

The next 5 bits look like the source register. The next 5 destination register. The next 15 is the absolute.

Do you understand how lookup tables work?

Paul
Hey paul,

Thanks,thats precisely I'm looking for....
>>>Do you understand how lookup tables work?
Could you please give me some more details about the lookup tables.
I would appreciate if you could give a sample program on how lookup tables work...

Thanks,
Sundeep.
ASKER CERTIFIED SOLUTION
Avatar of PaulCaswell
PaulCaswell
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
I just realised that the GNU binutils support MIPS of course, so the objdump utility will do just what you want. Have a look at http://www.gnu.org/software/binutils/