Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
957 views
in Technique[技术] by (71.8m points)

gcc - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...