【问题标题】:MIPS Hex OutputMIPS 十六进制输出
【发布时间】:2012-03-13 07:18:30
【问题描述】:

我想知道是否有一种方法可以编写带有 .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

【问题讨论】:

  • github.com/dwelch67/pic32_samples 我有一些示例和说明,说明如何构建您自己的交叉编译器/工具以及您可以下载的工具。
  • 感谢 dwelch,那么我需要为 MIPS 交叉汇编器下载哪些文件?从您的自述文件看来,如果我打算使用 gcc 作为 mips .s 文件的前端,我只需要 binutils 包?
  • binutils 就是你所需要的。现在 spim 可能具有特定于 spim 的语法,gnu 汇编程序可能支持也可能不支持,因此您可能必须修改代码才能从现在的位置获得 gas 喜欢的东西。将 blinker01 示例视为机器代码示例的简单汇编。
  • @dwelch 好的,谢谢,我马上试试。是的,SPIM 支持一些仅作为宏实现的伪指令,但我不希望汇编器处理这些伪指令。出于我的目的,我只想要实际的 MIPS 1 说明。
  • @dwelch 好的,所以我下载了 binutils 并解压了它。然后我做了一个configure make和make install。我现在需要做什么才能让 gcc 识别 mips 指令?

标签: assembly hex mips


【解决方案1】:

您可以使用gcc 等来交叉编译或汇编 MIPS 汇编语言源代码。就过程而言,汇编语言助记符和机器指令之间存在一对一的映射关系。汇编器只是为你做翻译。

编辑:您没有使用交叉汇编程序,您使用的是系统自己的 gcc。该工具链可能是针对没有三操作数add 指令的英特尔处理器。您需要为 MIPS 使用交叉汇编程序。下载并安装一个二进制文件,或者自己构建一个工具链。然后,您将拥有一个交叉编译器(可能称为 mips-gcc 或类似名称),您可以使用它来组装您的 MIPS 源文件。

【讨论】:

  • 谢谢,介意扩展一下如何使用 gcc 进行交叉编译过程吗?有点像整个 C 环境的菜鸟....
  • 好吧,去获取一个 MIPS 工具链(或自己构建一个),然后使用 `gcc -o myApp sourceFile.s" 应该就是这样。你可能需要做一些更复杂的事情取决于你芯片上的环境是什么样的。
  • 我不希望我的芯片运行内核或类似的东西。它应该只是一个执行十六进制指令的状态机,这是您在答案中描述的 sourceFile.s 一对一映射的结果。肯定有一个程序可以为我做一对一的翻译吗?我不打算建立一个 C 库或任何东西。直接从 MIPS 汇编到 MIPS 机器码。
  • 汇编器会这样做。组装源代码后,您可以使用objcopy 从目标文件中获取平面二进制文件。
  • 那会是 GNU 汇编器吗?很抱歉,您给我的关键字没有出现任何直接有用的网站。我想将您的答案标记为正确,因为我确定您知道您在说什么,但除非您可以提供步骤列表或更直接有用的链接,否则我将不得不重新处理问题并再次提问。请详细说明获取 .s 文件和检索由任何 MIPS 汇编程序生成的目标文件所需的确切步骤。谢谢
猜你喜欢
  • 2014-04-26
  • 2017-01-23
  • 2019-03-27
  • 1970-01-01
  • 2014-11-28
  • 1970-01-01
  • 1970-01-01
  • 2015-01-28
  • 1970-01-01
相关资源
最近更新 更多