r/AskComputerScience • • Sep 10 '19

Why have cpu designers not standardized the assembler language so that there is only one (and that it is portable) ?

48 Upvotes

26 comments sorted by

26

u/Steve132 Sep 10 '19

Different machines have different architectures and different goals. Different features in a cpu implies a different machine language to control those features. Different architectures make different design tradeoffs which make different sequences of instructions effective

19

u/hash_define Sep 10 '19

This question is actually quite interesting.

The obvious statement people make is that C and other systems languages can be used when you need portability. But the idea of an assembly language is to map directly to the CPU instructions with no ambiguity. Specifically, the language must operate with the objects and paradigms of the CPU such as registers and not high level concepts like the stack.

So a reworded question might be: can you build a generic assembly language that maps to the objects and paradigms of multiple architectures.

This idea is generally called High Level Assembly Languages. My summary is that it is easier to make a HLASM for RISC like instructions that are common across all CPUs and impossible for CISC instructions.

48

u/trevorsears Sep 10 '19

The ever relevant xkcd: https://xkcd.com/927/

15

u/Shabam999 Sep 10 '19

Kinda but in this case u/Steve132 and u/hash_define are more correct. Different assembly languages will have different performance advantages/disadvantages so designing/adapting your assembly language for each CPU will have noticeable differences. Plus, there's pretty much only Intel and AMD who are developing these these days so if either company wanted to enforce a single assembly language, they easily could, at least for their own family of processors.

9

u/deong Sep 10 '19

The various flavors of ARM that completely dwarf x86-64 in the wild would have something to say there, but yes, this is really the answer. CPU designs dictate assembly languages, and the are different tradeoffs to make.

2

u/oligIsWorking Sep 11 '19

This is an ill informed answer, that seems to confuse Silicon providers with CPU Architectures.

CPU Architectures are defined by their ISA (Instruction Set Architecture) - There are different tradeoffs to availability of different functionality and CPU features.

9

u/khedoros Sep 10 '19

We sometimes call that language "C" (/s). It's great for representing the operations in something like a PDP-11.

More seriously, you could start writing programs in something like LLVM-IR, which is a RISC-like strongly-typed instruction set that abstracts away the details of the target CPU.

If you're asking why the instruction sets haven't become more standardized, I'd like to propose a thought experiment. Suppose that car manufacturers got together to standardize on a single car body type, to be used for all transportation purposes, so that components can be shared.

The first proposal is by someone thinking of an individual commuter, and they propose a design based on the Smart ForTwo. It's physically compact, can be made cheaply, has an efficient engine, decent top speed, and even has a spare seat for cargo or a passenger. Cars can be connected into trains for more passengers, or to tow large loads. However, it uses an odd fuel mixture, and the entire world's fuel production, refining and supply networks will need to be rebuilt to match.

Any architecture that we choose will be ill-adapted to some use-case, and any architecture will require at least recompilation of a lot of our existing software, redesign of hardware devices that use a deprecated design, etc.

3

u/Syde80 Sep 10 '19

Because they all aim for a competitive advantage.

-4

u/unfixpoint Sep 10 '19

All?

5

u/Syde80 Sep 10 '19

Really want to be that guy?

-3

u/unfixpoint Sep 10 '19

Whether I want or not doesn't matter, I am ;)

4

u/visvis Sep 10 '19

Pretty much by definition, an assembly language maps one-to-one to the CPU's machine code. This means every CPU architecture needs its own assembly language. If you need to be portable between CPU architectures, you use a high-level language (which in this context includes even C).

Of course, this begs the question why there are different CPU architectures. There are many reasons, including competition/intellectual property, history/backward compatibility, and different design goals (for example high performance vs low power vs low cost).

2

u/Bottled_Void Sep 10 '19

For the same reason they don't standardize car engines.

2

u/011101000011101101 Sep 11 '19

x86 and ARM are fairly standard. In desktop PCs its all x86.

2

u/Felicia_Svilling Sep 11 '19

Because that would hinder them from adding new machine instructions, which is one of the major ways you can innovate in processor design.

2

u/bimbar Sep 11 '19

Assembly instructions are tightly coupled with cpu design. Assembly isn't only a frontend to the cpu, it's in most cases literally how the cpu works, so different cpus do need different instruction sets.

See also CISC vs RISC where this is most obvious.

2

u/crypto_mind Sep 11 '19 edited Sep 11 '19

I've seen a lot of answers in terms of hardware specific reasons, but I feel compiler theory should probably be mentioned as well. Compilers essentially turn high level language into a CPU independent intermediate representation. The IR then gets optimized, both CPU independent and CPU specific. Adding a new ISA to the compiler is orders of magnitude simpler than the architecture itself, although still not trivial obviously. Modern compilers have come a long way and, other than low level system programming, writing assembly is very rare these days. Compilers will also nearly always generate more efficient assembly than a human.

1

u/alicekdev Sep 11 '19

Slight differences in the architecture possibly, however most likely proprietary reasons

0

u/foadsf Sep 10 '19

I think OpenCL, not C, is the closest thing to a portable and vendor neutral low level machine language. Sadly Apple and NVIDIA did their best to kill it off.

3

u/Steve132 Sep 10 '19

Huh? OpenCL is explicitly targeting a workitem oriented machine and has a ton of features that almost no processor will be able to implement except for GPUs.

1

u/foadsf Sep 10 '19

Opencl is hetrogenious API, including CPU, FPGA, GPU any several other computational platforms and architectures.

2

u/Steve132 Sep 10 '19

Implement an OpenCL compiler targeting an Atmega328 I dare you.

0

u/foadsf Sep 10 '19

you could search the internet before daring people like this. The first result for example here

1

u/Steve132 Sep 11 '19

Which example are you referring to? I don't see an OpenCL compiler targeting an atmel atmega328 on that list. In fact, I don't see any examples of OpenCL targeting ANY single threaded hardware platform with no support for atomics.

In fact, it says this: "The embedded system will need support for OpenCL, but there are a number of microcontrollers and SoCs that have sufficient resources, along with OpenCL support, to make their use worthwhile....Still, OpenCL is not a free lunch. The necessary hardware costs money and uses power. "