is there a standard for machine codes?

When you compile a program it's quite likely that it can run on any computer processor you choose, which surely means there's some kind of standard used either in the making of the processors so the machine code is portable, or that there's a translator for every processor that translates from some other standard.
At a guess I'd say it's the first one, but does anyone know where I could find such a spec?
Last edited on
That's... a lot of instructions...
The PC architecture is known for having a lot of instructions. (And often ridiculed for it, too. Alas.)*

To answer your question, there really isn't any sort of standard. Every processor has it's own standard.

Part of the allure of the x86 series is that each successive processor supports the previous's opcodes and instruction modes. (With minor exceptions.) It isn't the only processor series that does that, though.

But the point is an PC's machine code is specific to the PC, and will not run on, say, a Sun SPARC.

That's why you'll see things like "Pentium II or better" on the list of requirements for software -- because the software has opcodes that only exist beginning with 686 processors -- a 486 would crash with "illegal instruction".

When you compile a program it's quite likely that it can run on any computer processor you choose

...with the caveat that once compiled it will only run on what you chose.

That is, you can compile to target any processor you want (assuming your compiler can output for the target processor). But once you compile, the resulting executable binary is only useful on that processor (and OS) you selected when compiling.


* In contrast, there is an idea of a reduced instruction set, the most prominent of which is MIPS. For the MIPS architecture, check out Wikipedia
http://en.wikipedia.org/wiki/MIPS_architecture


Hope this helps.
Thanks for the link on MIPS architecture, that simplifies things immensely.
Thanks for all the useful links guys, looks like I've got some reading to look forward to.

But what I meant about compiling running on multiple systems is the practice that actually happens with most processors, for a start the windows and Unix systems can be thrown onto almost any processor, imagine it's possible that Intel, AMD and other popular processor companies share like a base standard between them since it's mostly the operating system that stops portability across computers
I don't think they share instructions sets if that's what you mean. Exe's for example have a header which includes architecture specification as a value (x86, etc). I'm assuming part of OS programming includes dealing with multiple processor specs.
SatsumaBenji wrote:
When you compile a program it's quite likely that it can run on any computer processor you choose,

This isn't true at all: while C++ is portable, machine code to which it compiles has almost nothing in common between any two CPU families: x86, arm, sparc, powerpc, itanium, mips, and all the others are completely different.

SatsumaBenji wrote:
imagine it's possible that Intel, AMD and other popular processor companies share like a base standard

Intel, AMD, and VIA are three companies that build CPUs that do indeed share the Intel x86 and x86_64 instruction sets, and their CPUs can execute each other's programs, unless the compiler was allowed to take advantage of some particular CPU's instructions that others didn't implement.
Topic archived. No new replies allowed.