有没有办法使用 gcc 将 C 转换为 MIPS? [英] Is there a way to use gcc to convert C to MIPS?

查看:52
本文介绍了有没有办法使用 gcc 将 C 转换为 MIPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完成了一个类的 C 到 MIPS 的转换,我想根据程序集检查它.我听说有一种配置 gcc 的方法,它可以将 C 代码转换为 MIPS 架构而不是 x86 架构(我的计算机使用 Intel i5 处理器)并打印输出.

I completed a C to MIPS conversion for a class, and I want to check it against the assembly. I have heard that there is a way of configuring gcc so that it can convert C code to the MIPS architecture rather than the x86 architecture (my computer users an Intel i5 processor) and prints the output.

在Ubuntu(gcc自带)中运行终端,我用什么命令配置gcc转换为MIPS?还有什么我需要安装的吗?

Running the terminal in Ubuntu (which comes with gcc), what command do I use to configure gcc to convert to MIPS? Is there anything I need to install as well?

让我澄清一下.请阅读这个.我不是在寻找要使用的编译器,也不是人们在说好吧,您可以交叉编译,但是您应该使用其他没有关于如何设置的说明的东西."

Let me clarify. Please read this. I'm not looking for which compiler to use, or people saying "well you could cross-compile, but instead you should use this other thing that has no instructions on how to set up."

如果您要发布该内容,请至少让我参考说明.GCC 随 Ubuntu 一起提供.我没有关于如何安装编译器的经验,而且找到 GCC 以外的任何其他内容的在线教程并不容易.然后还有我需要了解的交叉编译的情况.谢谢.

If you're going to post that, at least refer me to instructions. GCC came with Ubuntu. I don't have experience on how to install compilers and it's not easy finding online tutorials for anything other than GCC. Then there's the case of cross-compiling I need to know about as well. Thank you.

推荐答案

GCC 可以 为大量架构生成汇编代码,包括 MIPS.但是当 GCC 本身被编译时,一个给定的 GCC 实例的目标架构是决定的.您将在 Ubuntu 系统中找到的预编译二进制文件了解 x86(可能包括 32 位和 64 位模式)但不了解 MIPS.

GCC can produce assembly code for a large number of architectures, include MIPS. But what architecture a given GCC instance targets is decided when GCC itself is compiled. The precompiled binary you will find in an Ubuntu system knows about x86 (possibly both 32-bit and 64-bit modes) but not MIPS.

使用不同于 GCC 本身将在其上运行的架构的目标架构编译 GCC 被称为准备交叉编译工具链.这是可行的,但需要相当多的文档阅读和耐心;您通常需要先构建一个交叉汇编器和交叉链接器(GNU binutils),然后再构建跨 GCC 本身.

Compiling GCC with a target architecture distinct from the architecture on which GCC itself will be running is known as preparing a cross-compilation toolchain. This is doable but requires quite a bit of documentation-reading and patience; you usually need to first build a cross-assembler and cross-linker (GNU binutils), then build the cross-GCC itself.

我建议使用 buildroot.这是一组脚本和生成文件,旨在帮助生成完整的交叉编译工具链和实用程序.最终,您将获得用于目标系统的完整操作系统和开发工具.这包括您所追求的交叉编译器.

I recommend using buildroot. This is a set of scripts and makefiles designed to help with the production of a complete cross-compilation toolchain and utilities. At the end of the day, you will get a complete OS and development tools for a target system. This includes the cross-compiler you are after.

另一个完全不同的解决方案是使用 QEMU.这是一个适用于各种处理器和系统的模拟器,包括 MIPS 系统.您可以使用它来运行带有 MIPS 处理器的虚拟机,并在该机器内为 MIPS 安装操作系统,例如Debian,Linux 发行版.这样,您就可以获得原生 GCC(在 MIPS 系统上运行并为 MIPS 生成代码的 GCC).

Another quite different solution is to use QEMU. This is an emulator for various processors and systems, including MIPS systems. You can use it to run a virtual machine with a MIPS processor, and, within that machine, install an operating system for MIPS, e.g. Debian, a Linux distribution. This way, you get a native GCC (a GCC running on a MIPS system and producing code for MIPS).

QEMU 方式可能更简单一些;使用交叉编译需要对一些毛茸茸的细节有所了解.无论哪种方式,您都需要大约 1 GB 的可用磁盘空间.

The QEMU way might be a tad simpler; using cross-compilation requires some understanding of some hairy details. Either way, you will need about 1 GB of free disk space.

这篇关于有没有办法使用 gcc 将 C 转换为 MIPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆