To answer your question - How to write this prog in MIPS(Mars)?):
Start learning the assemble language.. everything is difficult at the beginning.

Unless you read the sticky and have a more "direct"/precise question, the best we can do is redirect you to google and/or a assemble "manual".
Like this one: http://logos.cs.uic.edu/366/notes/mips%20quick%20tutorial.htm
You can also take at look at http://en.wikibooks.org/wiki/MIPS_Assembly