Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ to MIPS Assembly

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.

like image 457
notablytipsy Avatar asked Dec 04 '25 17:12

notablytipsy


1 Answers

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.

like image 54
markgz Avatar answered Dec 06 '25 16:12

markgz