MIPS 十六进制输出
我想知道是否有一种方法可以编写带有 .s 扩展名的 MIPS 汇编语言文件(只是非常简单的测试文件),就像与 PCSpim 模拟器一起使用一样,然后让它实际编译代码并生成带有十六进制输出的文件就像我要将它加载到实际的 MIPS 芯片上一样。
SPIM 或其他类似软件可以做到这一点吗?您能否更多地解释一下从 MIPS 汇编到微控制器使用的实际可执行文件的汇编过程?
谢谢
编辑:所以我在安装了 gcc 的 ubuntu linux 上运行。我有一个 mips 文件 mipsTest.s 如下
.text
add $7, $0, $0
现在在命令行中我键入
gcc -c -o mipsy.o mipsTest.s
我得到的错误
mipsTest.s: Assembler messages:
mipsTest.s:2: Error: at most 2 immediate operands are allowed.
所以对我来说这意味着汇编器没有读取 mips 语言,它可能假设我的汇编文件位于x86?如何获得交叉编译器设置,以便 gcc 能够识别 MIPS 汇编语言而不是 x86? (或者现在解释我的 mipsTest.s 文件的任何内容)谢谢!
编辑2:所以我用谷歌搜索“mips cross-assembler”并发现了一些东西。最有前途的项目是 Sourceforge 上的 umps 交叉汇编器项目。所以我下载了umps2.0,这应该是一个稳定的版本。我按照自述文件中的说明运行“./configure”并将其解压缩。然后我的控制台给出了以下错误,该错误阻止我运行 make 命令...
jonathan@mini-heiretic:~/Documents/cross-compiler/umps-2.0$ ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking how to run the C preprocessor... gcc -E
checking whether ln -s works... yes
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert i686-pc-linux-gnu file names to i686-pc-linux-gnu format... func_convert_file_noop
checking how to convert i686-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking dependency style of gcc... gcc3
checking for ld used by gcc... (cached) /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... (cached) yes
checking for elf_version in -lelf... no
configure: error: *** Libelf not found. Specify a different path or install it. --help for info.
我应该尝试更好的选择吗?或者任何人都可以提供有关我的错误的输入吗?
编辑 3: 下载 Libelf 后,我现在可以进一步了解 umps 的配置脚本。这是从新成功的 elf_version 行开始的输出
checking for elf_version in -lelf... yes
checking for dlopen in -ldl... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for SIGCPP... no
configure: error: Package requirements (sigc++-2.0) were not met:
No package 'sigc++-2.0' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables SIGCPP_CFLAGS
and SIGCPP_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
所以我运行了快速 sudo apt-get install sigc++-2.0 但找不到包...建议?
编辑4:这是我尝试使用Makefile时遇到的错误
jonathan@mini-heiretic:~/Documents/cross-compiler/dwelch67-pic32_samples-f34fb22/blinker01$ make
mips-sde-elf-as -EL -G0 --warn --fatal-warnings blinker01.s -o blinker01.o
make: mips-sde-elf-as: Command not found
make: *** [blinker01.o] Error 127
I'm wondering if there is a way to write MIPS assembly language file (just really simple test file) with a .s extension like is used with the PCSpim simulator and then have it actually compile the code and produce a file with the hex output as if I were to load it onto an actual MIPS chip.
Can SPIM or some other similar software do this? Can you explain a little more about the assembly process from MIPS assembly to the actual executable that the microcontroller uses?
Thanks
EDIT: So I'm running on ubuntu linux with gcc installed. I have a mips file mipsTest.s that is the following
.text
add $7, $0, $0
Now at the command line I type
gcc -c -o mipsy.o mipsTest.s
And the error that I get says
mipsTest.s: Assembler messages:
mipsTest.s:2: Error: at most 2 immediate operands are allowed.
So to me that means that the assembler is not reading the mips language, it is probably assuming my assembly file is in x86? How do I get a cross compiler setup so that gcc will recognize the MIPS assembly language instead of x86? (or whatever its interpreting my mipsTest.s file as right now) Thanks!
EDIT 2: So I googled "mips cross-assembler" and found a few things. The one that seemed most promising was the umps cross-assembler project on sourceforge. So I downloaded umps2.0 which is supposed to be a stable version. I untarballed it any ran the "./configure" as instructed in the readme file. Then my console gave me the following error which prevents me from running the make command...
jonathan@mini-heiretic:~/Documents/cross-compiler/umps-2.0$ ./configure
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether byte ordering is bigendian... no
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking how to run the C preprocessor... gcc -E
checking whether ln -s works... yes
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert i686-pc-linux-gnu file names to i686-pc-linux-gnu format... func_convert_file_noop
checking how to convert i686-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking dependency style of gcc... gcc3
checking for ld used by gcc... (cached) /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... (cached) yes
checking for elf_version in -lelf... no
configure: error: *** Libelf not found. Specify a different path or install it. --help for info.
Are there any better options I should try or can anyone provide input on my error?
EDIT 3: After downloading Libelf, I can now get a little further in the configure script for umps. Here is the output starting from the newly successful elf_version line
checking for elf_version in -lelf... yes
checking for dlopen in -ldl... yes
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for SIGCPP... no
configure: error: Package requirements (sigc++-2.0) were not met:
No package 'sigc++-2.0' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables SIGCPP_CFLAGS
and SIGCPP_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
So I ran a quick sudo apt-get install sigc++-2.0 but couldn't find the package... suggestions?
EDIT 4: Here's the error I get when I try to use the Makefile
jonathan@mini-heiretic:~/Documents/cross-compiler/dwelch67-pic32_samples-f34fb22/blinker01$ make
mips-sde-elf-as -EL -G0 --warn --fatal-warnings blinker01.s -o blinker01.o
make: mips-sde-elf-as: Command not found
make: *** [blinker01.o] Error 127
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 gcc 等来交叉编译或汇编 MIPS 汇编语言源。就流程而言,汇编语言助记符和机器指令之间存在一一对应的关系。汇编器只是为您进行翻译。
编辑:您没有使用交叉汇编器,您正在使用系统自己的 gcc。该工具链可能针对英特尔处理器,该处理器没有 3 操作数
add
指令。您需要使用 MIPS 的交叉汇编器。下载并安装二进制文件,或者自己构建一个工具链。然后您将拥有一个交叉编译器(可能称为 mips-gcc 或类似的东西),您可以使用它来汇编 MIPS 源文件。You can use gcc, among others, to cross-compile or assemble MIPS assembly language source. As far as the process, there is a one-to-one mapping between assembly language mnemonics and machine instructions. The assembler just does the translation for you.
Edit: You're not using a cross-assembler, you're using the system's own gcc. That toolchain is presumably targeting Intel processors, which don't have a 3-operand
add
instruction. You need to use a cross-assembler for MIPS. Download and install a binary one, or build a toolchain yourself. Then you'll have a cross compiler (maybe called mips-gcc or something like that) that you can use to assemble your MIPS source files.