3

I know that to compile to assembly, I should use the -Soption with gcc or g++, but how do I get MIPS assembly?

I tried

g++ -march=mips2 dll.c 

but that gives the error

dll.c:1:0: error: bad value (mips2) for -march= switch

I saw a suggestion of the compile command mips_gcc, but I can't find how to install that compiler.

I'm using Ubuntu 64-bit, if that helps.

notablytipsy
  • 387
  • 1
  • 4
  • 19
  • Related, for people looking for MARS / SPIM (rather than Linux MIPS or other real OSes), see [Tweak mips-gcc output to work with MARS](https://stackoverflow.com/q/13052444) and [Is there a way to use gcc to convert C to MIPS?](https://stackoverflow.com/a/63386888) – Peter Cordes Dec 12 '22 at 04:48

1 Answers1

5

You need a version of gcc that is built as a MIPS cross compiler. You can download the free Mentor/Codesourcery MIPS gnu/gcc cross compilation tool chain from here. This toolchain is available for both Windows and Linux.

After downloading, installing and adding the tool chain to your path you would say:

mips-linux-gnu-g++ -march=mips32r2 -S dll.c

to compile your code to MIPS32R2 assembly.

UPDATE 8/2017: It looks like Sourcery CodeBench free cross compiler for MIPS is no longer available at Mentor's site. Try the free toolchain at Imagination's site.

markgz
  • 6,054
  • 1
  • 19
  • 41