using gcc to get MIPS assembly code

I have the following installed on my opensuse 11.2.

shekhar@pari:~> rpm -qa | grep gcc
gcc-c++-4.4-4.2.i586
libstlport_gcc4-4.6.2-3.1.i586
gcc44-objc-4.4.1_20090817-2.3.4.i586
gcc44-obj-c++-4.4.1_20090817-2.3.4.i586
libgcc44-4.4.1_20090817-2.3.4.i586
gcc44-info-4.4.1_20090817-2.3.4.i586
gcc44-obj-c++-debuginfo-4.4.1_20090817-2.3.4.i586
gcc44-fortran-4.4.1_20090817-2.3.4.i586
gcc44-4.4.1_20090817-2.3.4.i586
gcc-4.4-4.2.i586
gcc-fortran-4.4-4.2.i586
gcc-info-4.4-4.2.i586
gcc44-c++-4.4.1_20090817-2.3.4.i586
gcc44-c++-debuginfo-4.4.1_20090817-2.3.4.i586
gcc44-debugsource-4.4.1_20090817-2.3.4.i586
libgcc44-debuginfo-4.4.1_20090817-2.3.4.i586
shekhar@pari:~>

How do i generate mips assembly code from a c program I have written? I tried this but may be my gcc compiler does not know the -mips2 or any mips related options.

gcc -march=mips2 -S -c fpsc.c                                                                     
fpsc.c:1: error: bad value (mips2) for -march= switch                                           
fpsc.c:1: error: bad value (mips2) for -mtune= switch                                          

What should I do?

The gcc compiler on openSUSE is hardwired to generate x86/x86_64 code. You need to build a separate gcc that will generate mips code. This is known as a cross-compiler. And not just the gcc, but all the other tools in the compiler chain, i.e. as, ld, nm, and so forth.

I am not used to with cross compiling. Can you please show me some way to start with… like raw list of things to start with. I do not want to mess my current installation, and if possible i want to create a separate compiler for mips.

Any suggestions?

I found cross-mips-binutils package, but it is not same as cross-mips-gcc, right?

since iam very very new to programming, and most of the time i use some IDE(eclipse, netbeans) I do not know much about ld, as and other tools, Perhaps some links suse specific guide would help me much.

Googling lost me completely :stuck_out_tongue:

You’ll have to make it separate, if you don’t want to mess up your system. Go to the gcc site for all the details. Basically it’s the same as compiling any other program, you take the gcc sources and run ./configure, specifying the generated language as MIPS assembly. And then you do the same for the as, you configure it to accept MIPS assembly. And for ld, to accept MIPS object format. And to actually be able to build an executable program you need to build some MIPS runtime libraries for libc at least. And of course, you need a real MIPS machine to run the program. And all the executable programs have to be kept separate from the system ones.

Expect to spend many minutes or a few hours, depending on the speed of your system to compile everything needed.

Writing the program can be done with any editor or IDE since the code is still C. After all, C is a machine independent system programming language.

I was reading about compiling the gcc with arm support and also googling for mips gcc, and found this :
MIPS® SDE Lite - MIPS Technologies - MIPS Everywhere - MIPS Technologies
I installed mips-sde-lite, and it works.

I do not have time right now to dig on cross compilation, but I will definitely do so sometime.

Thank you very much ken_yap