• C

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
LVL 3
sundeepgopalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sundeepgopalAuthor Commented:
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

**************************************************************************
bpmurrayCommented:
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.
bpmurrayCommented:
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.
PaulCaswellCommented:
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
sundeepgopalAuthor Commented:
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.
PaulCaswellCommented:
Sorry Sundeep. Here we help students understand their homework, we wont be helping if we do it for you.

A lookup table might be used like this:

char * numbers [] =
{
"Zero",
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine"
}

char * one = numbers[1]; // Make the variable called 'one' point to a string containing the text "One".

See how it works?

Paul

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bpmurrayCommented:
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/
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.