The MIPS assembly code generated by mips-gcc almost, but doesn't quite, run on the MARS_ MIPS simulator. For example:
- The compiler generates "j $31" instead of "jr $31"
- The compiler puts .align directives in the text segment, which MARS does not allow.
In addition, the generated assembly is not quite set up so that it will start and stop properly (i.e., no syscall 10 at the end).
These problems are all appear to be easily fixable with a simply script; but, before I reinvent the wheel, I was wondering:
- Are there any gcc flags that will make some of these problems go away?
- Is there an existing program that will fix up the mips-gcc output, so that it will run on Mars?
(FWIW, I see the same behavior in both GCC 3.3.6 and 4.6.1.)
The short answer is no. MARS uses custom system calls and is very different in calling conventions.
I don't know of any automated way to convert it. You can do it only manually. I have done it actually.
Roughly, these are the steps I followed:
j main
after.text
.-mregnames
)This is an example I made. It lacks main, because it was intended as a library:
C code:
Godbolt code:
Converted Mars code: