19

Are there any command line interpreters or any other set of programs around for x86 linux in order to run MIPS assembly programs?

I'd like to be able to write simple MIPS assembly programs and run them from the console on my local machine.

I know of SPIM but it requires X Windows and I'm curious if there are better options out there.

Edit: Turns out it doesn't require X Windows. I still have issues with SPIM. Not the best in my humble opinion. Qemu / Cross compiled toolchain is a little more work but I have less quirks.

VividD
  • 10,456
  • 6
  • 64
  • 111
mmcdole
  • 91,488
  • 60
  • 186
  • 222

8 Answers8

15

Incidentally, Spim does not require X Windows. It has a console interface as well. Run either spim or xspim.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
9

MARS made my assembly programming for MIPS architecture so much easier. If you would like a GUI/IDE, I would recommend MARS for sure.

Derek
  • 982
  • 1
  • 8
  • 19
8

You will need either a cross compilation toolchain, or to build your own cross binutils. For a prebuilt toolchain, you can visit code sourcery. If you just want to compile assembly, then all you need is binutils. There are some guidelines on the Linux Mips wiki

For the emulation part, QEmu would be my choice.

shodanex
  • 14,975
  • 11
  • 57
  • 91
3

I was in the same situation yesterday. I also didn't like SPIM, so this is what I did:

  • installed gxemul and gxemul-doc (those are the package names on debian)
  • installed netbsd on an emulated MIPS machine following the detailed instructions in the documentation
  • since netbsd already includes the standard gcc toolchain and vi, you're good to go.

    Setting up networking is pretty easy and well documented, too. This has the advantage of not needing to fiddle with cross compilation.

  • Kim Stebel
    • 41,826
    • 12
    • 125
    • 142
    • 1
      If you ever find yourself without those, I found MARS to be much supieror to SPIM. It is a Java .jar file so it works across linux/windows. The reason I like it is it has a built in debugger and I can step through my code or codebreak, and see the value of all registers. Helps a ton in debugging. – mmcdole Mar 17 '09 at 19:19
    • 1
      Thanks, that's actually what our university uses. But I wanted to be able to call c functions from assembly code and I don't think MARS supports this. ;) Also, it's nice to be able to examine the output of "gcc -S somecprog.c". – Kim Stebel Mar 18 '09 at 04:40
    • 1
      Where did you get the ISO for FreeBSD? I see that it's actively developed, but I don't see where to get the CD image. I'm trying Debian now, anyway. – new123456 Jun 23 '11 at 02:10
    3

    You could use gxemul, which emulates a MIPS machine (among others, including Dreamcast), and is able to run many Operating systems (included linux, netbsd and some more).

    gxemul-wikipedia

    gxemul-home page

    Tom
    • 43,810
    • 29
    • 138
    • 169
    2

    QEmu has a good MIPS emulator. Combine that with a cross-compiled GCC/binutils (technically you only need binutils to get GAS, the GNU assembler) and you're good to go.

    ΦXocę 웃 Пepeúpa ツ
    • 47,427
    • 17
    • 69
    • 97
    Serafina Brocious
    • 30,433
    • 12
    • 89
    • 114
    • 1
      Oh, and hi again. Apparently we're both emulator dorks on a similar sleep schedule ;) – Serafina Brocious Jan 21 '09 at 07:24
    • 1
      @Cody Brocious, Hi, lol. Have you written your own disassembler or assembler? Is it worth writing either as a learning exercise? I have so many questions I want to throw your way, lol. – mmcdole Jan 21 '09 at 07:37
    • 1
      I've done both on various occasions (written quite a few disasms while doing decompiler dev). Feel free to AIM me at bloomfilter to ask any questions you have. – Serafina Brocious Jan 21 '09 at 07:38
    2

    Assuming you wish to use GCC.

    Steps for compiling for MIPS on an x86-64 system, and then running the executable using an emulator:

    1. Use a cross-compilation toolchain to produce an executable.

      • If you are on Debian/Ubuntu, install a cross-compilation toolchain for MIPS. For example, either of these APT packages: gcc-mips-linux-gnu (MIPS big endian) or gcc-mipsel-linux-gnu (MIPS little endian).

      • Compile using mips-linux-gnu-gcc (mipsel-linux-gnu-gcc for little endian MIPS); assemble using mips-linux-gnu-as; link using mips-linux-gnu-ld.

    2. Run the executable using an emulator.

      • Install an emulator that can launch Linux programs compiled for one architecture (e.g. MIPS) on another architecture (e.g. x86-64): sudo apt-get install qemu-user.

      • Run your executable compiled for MIPS using the emulator: qemu-mips ./a.out (or qemu-mipsel ./a.out for little endian MIPS). Simply running ./a.out might also work; the emulator might be used automagically if you (or your distro's qemu package) has set up binfmt-misc to transparently run qemu-user.

    Flux
    • 9,805
    • 5
    • 46
    • 92
    1

    Maybe you can take a look at these emulators? I'm not an expert but the list seems good.

    PolyThinker
    • 5,152
    • 21
    • 22
    • 2
      This focuses on system emulation, not userland emulation. That is, that reference is good if you want to emulate a complete MIPS box, not just a given MIPS app. – Serafina Brocious Jan 21 '09 at 07:28