2

My own computer has an Intel Core I5. However, I want to know what the assembly will look like if I use some RISC ISA, for example, ARM or powerPC.

Can I compile C code into assembly using other microarchitecture's ISA?

Mat
  • 202,337
  • 40
  • 393
  • 406
WriteBackCMO
  • 629
  • 2
  • 9
  • 18

2 Answers2

3

No. -march only affects what subarchitecture the compiler will target (e.g, whether it will use features which are not available on all CPUs). It does not allow the compiler to build code for a different architecture altogether.

What you're looking for is a cross-compiler -- a copy of GCC which is compiled for x86 (or whatever), but compiles to PowerPC/ARM/MIPS/whatever code. Building a cross-compiler is a complex process, but there are instructions available online.

  • You don't say what OS you're using, but Ubuntu (for one) has an ARM cross-compiler package in the repo. – ams Feb 23 '12 at 15:44
  • Also, you can download free cross-toolchains for several architectures from here: http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/ – ams Feb 23 '12 at 15:45
2

You'll need to build (or install) a cross-compiler for that. A given build of GCC only targets one CPU "family"; for instance a GCC compiler that targets x86 and x86_64 can be built. But you can't (as far as I know) build a GCC compiler that targets both x86 and PPC.

You can run a compiler that outputs PPC assembly on x86 though - that's called a cross-compiler. Look for them in your distribution's package repositories, or use tools like crossdev to make yourself one.

Mat
  • 202,337
  • 40
  • 393
  • 406