How can I execute MIPS assembly programs on an x86

2020-02-17 07:47发布

问题:

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.

回答1:

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.



回答2:

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



回答3:

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



回答4:

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.



  • 回答5:

    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



    回答6:

    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.



    回答7:

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



    回答8:

    Assuming you wish to use GCC.

    Steps for compiling for MIPS on an x84-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-gcc.

    2. Run the executable using an emulator.

      • Install an emulator that can launch Linux processes compiled for one CPU (e.g. MIPS) on another CPU (e.g. x84-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 also works; the emulator will be used.