How can I execute MIPS assembly programs on an x86

2020-02-17 07:43发布

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.

8条回答
我命由我不由天
2楼-- · 2020-02-17 07:55

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.

  • 查看更多
    放我归山
    3楼-- · 2020-02-17 08:01

    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.

    查看更多
    甜甜的少女心
    4楼-- · 2020-02-17 08:03

    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

    查看更多
    姐就是有狂的资本
    5楼-- · 2020-02-17 08:04

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

    查看更多
    三岁会撩人
    6楼-- · 2020-02-17 08:06

    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.

    查看更多
    一纸荒年 Trace。
    7楼-- · 2020-02-17 08:06

    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.
    查看更多
    登录 后发表回答