r/AskComputerScience • • Apr 23 '21

Does the "Machine Code" your CPU understands ever receives updates? If so by whom? Do all CPUs follow the same "Machine Code"? If not who are the ones supporting so many models of CPUs?

screw air aback disarm historical rob friendly grab pot elderly

This post was mass deleted and anonymized with Redact

37 Upvotes

7 comments sorted by

34

u/Steve132 Apr 23 '21

Does the machine code your cpu understands ever recieve updates

Theoretically no. In theory the instruction set architecture is part of the hardware itself and cannot be updated. In practice, however, on modern architectures the instructions are decoded and translated to a different, simpler binary called microcode before execution. This translation step is sometimes programmable to a small degree, so small changes can be made using a CPU firmware update.

If so by whom

Your CPU manufacturer might publish and update for the firmware for the CPU. But this is a tiny change not a big change.

If not who are the ones supporting so many models of CPUs?

In general the core binary language supported by a particular CPU is shared across many CPUs in the same family. So programs written for the standard desktop computer instruction set called x86_64 (aka x64, aka amd64) all can run on pretty much any Intel or AMD computer made in the last 10 years. The underlying language is the same and that's why it's not compatible.

However when you look at truly different families of computer, like phones, routers, or arduino, those computers speak an entirely different instruction set binary language. ARM or avr for example. In those cases it's the job of the software developer to make sure that the binary code is in the right format. Sometimes library developers will publish two versions: one for desktop/x64. And one for phone/ARM7

Specifically, 99% of the time, when I say "the developer" I actually mean the compiler. One big reason developers use compilers and don't use assembly language any more is that the compiler can handle all the details of the instruction set architecture for them. So unless you're writing in assembly language or using custom processor intrinsics (or using a library that does) I'm theory switching processor languages is as simple as hitting a switch in your IDE.

The compiler writers are the ones doing all the real work dealing with all the different processor types.

2

u/theamigan Apr 24 '21

As an historical footnote, there were VLIW processors that theoretically could emulate various ISAs by simply changing the internal instruction translator, though the Crusoe only ever really did x86. A Java bytecode proof of concept was produced, though.

9

u/khedoros Apr 23 '21

Does the "Machine Code" your CPU understands ever receives updates?

Many CPUs are designed to receive updates to their microcode, which can change internal details of how the CPU operates, and also potentially introduce new features. There are some really interesting details in Intel's Microcode Update Guidance Document, concerning what can be updated, and how the updates can be applied.

If so by whom?

As far as I'm aware, it would be exclusively the manufacturer of the CPU, since the updates would require unpublished information about the internal operation of the CPU.

Do all CPUs follow the same "Machine Code"?

No. There are families of CPUs, and even within a family, there can be changes that go beyond new features when you compare earlier models to later ones. Differences go beyond the machine code that they accept. For example, the interfaces that they provide to external hardware might have different data and address widths, different access timing and protocols, etc.

If not who are the ones supporting so many models of CPUs?

Documentation from the manufacturers used to develop tools like assemblers and compilers, reaching up into details of the OSes that run on them and system libraries that are reliant on details of the exact CPU they're running on.

9

u/CptCap Apr 23 '21 edited Apr 24 '21

Do all CPU follow the same machine code

No, there are different families of instruction sets (ie: machine code), and instruction sets evolve over time.

The two most common instruction sets right now are x86, used in PC and ARM for embedded devices, phones, and the new Macs.

Does the "Machine Code" your CPU understands ever receives updates

Kinda, depending on what you mean. Instructions are often added to instruction sets by people who owns them. These new instructions are not available on older processors and can not be added through an update.

Some CPU do contain something called micro-code, which govern some aspects of how they execute instructions. This microcode can be updated, but can't really be used to add instructions.

2

u/agerox Apr 23 '21

The CPUs receive updates from the manufacture. The microcode tends to be updated using BIOS updates. Microcode updates can also be loaded by the OS. Here is Intel's microcode updates for Linux: https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files

2

u/claytonkb Apr 23 '21

Good answers so far. I'll add a little more information, FWIW.

Do all CPUs follow the same "Machine Code"? If not who are the ones supporting so many models of CPUs?

If a given compiler can compile for multiple CPU families (for example, g++), then the compiler will have a configuration option that allows the software developer to tell the compiler which CPU the binary should be compiled for. Every CPU will have some instruction that performs addition, some instruction that performs memory move/copy, some instruction that performs if-else logic ("branches"), and so on. So when the compiler is "emitting" instructions, it chooses the sequence of binary code that is suitable for the chosen target CPU (or, usually, CPU family).

Does the "Machine Code" your CPU understands ever receives updates? If so by whom?

For CPUs that support microcode updates (for example, any modern Intel or AMD processor), the ISA[1] can be reconfigured more or less arbitrarily. Obviously, CPU manufacturers do not arbitrarily reconfigure their CPUs but they can change or even disable instructions that cause security flaws. The flexibility to update the CPU after is manufactured is a key risk-mitigation measure in the design and production of CPUs.

[1] - ISA means Instruction Set Architecture and it is the technical term for what you are referring to as "machine code".

0

u/LordNiebs Apr 23 '21

Each CPU manufacturer/designer (e.g. Intel, AMD, ARM) specifies their own "Assembly language" which is roughly equivalent to what you refer to as "machine code". An assembly language is a sequence of instructions and data which specify what the processor should do. An assembly language is similar to a high level programming language, but with a much more limited set of operations to be used. The assembly code is what is generated when you compile a program, thus, the specific assembly code that you wish to compile to needs to be specified at compile time.

CPUs do not all share the same "Machine Code". Rather, all CPUs can be categorized by the Instruction Set Architecture (ISA) they use which defines the specifications of the assembly code (i.e. the syntax, which commands can be used, etc.). Currently, the most popular ISAs are x86, x64, and ARM. Generally speaking, CPUs that already exist can not be updated to handle new instructions, but new CPUs can be designed to handle new instructions.

Generally speaking, there is no need to update ISAs for CPUs that have already been released, except for security reasons.