I've started learning assembly recently and as I've looked across the internet I see more and more people saying that assembly is not useless, but it's also not worth the time to program things in a language that requires such time and effort compared to high level languages. Is the efficiency between a high level language program and a low level one really not even noticeable enough to pay attention to nowadays, and is there another low level language like assembly that is more widely used?
Is the efficiency between a high level language program and a low level one really not even noticeable enough to pay attention to nowadays
Oftentimes, compilers generate a lot better assembly than developers can write. There are certain developers who can beat the compiler. But since writing low-level code requires more attention to details and is harder to write and maintain, it is usually only a small specific pieces of code that get implemented in assembly for efficiency. The difference can be noticeable. But it also can be not-noticable if developers do false-optimizations.
I'd recommend you read Michael Abrash's Graphics Programming Black Book — it has a lot on assembly and optimizations + nice stories from real-life.
and is there another low level language like assembly that is more widely used?
Assembler is probably the lowest level application programming language. The only other resort would be to write binary code by hand, but binary opcodes can hardly be called a "language".
However, programming goes beyond software. Hardware needs to be programmed, too. There are hardware description languages (HDL) that can be used to program hardware (i.e. you can create your own CPU). The most popular HDL languages are Verilog and VHDL.
Writing assembly was appropriate in simpler times. Back when the code generator in a C compiler wasn't very smart yet and it was simple to predict the execution time of machine code.
That's over and done with, a human can't beat neither the smarts built into a modern code generator nor its relentless attention to detail. The kind of detail required to know exactly when you insert a cache prefetch so the data is available at exactly the right time. And how reordering instructions just right gets you the best super-scalability. And inserting nops just right so jump targets are aligned. And how to unroll loops mechanically. And how to take advantage of auto-parallelizing provided by SIMD. Etcetera. And to do this not just once, but over and over again as the code changes.
compilers of higher level languages are getting smarter each day. In the past assembler tricks could increase the performance a lot. Nowadays, compilers implement a lot of these tricks themselves.
Examples are: shifting instead of dividing, manipulating the program counter in a jump-table for a switch/case, inlining functions if they are only used once, etc.
There still is room for optimalisation, but the performance gain will be so low that it is better to use a higher level language and to go for maintainability.
Well, "assembly" is more of a collection of different varieties, actually. It's dependent on the architecture you're programming for. For example, assembly for x86 could (and will) greatly differ from assembly for ARM, or MIPS, or any architecture you can think of. This is caused by the fact that assembly is a one-to-one translation of the binary code the processor runs. As different architectures have different instruction sets, their assembly language differs too.
So really, assembly is the lowest you can go without writing plain binary code. But, it is not a specific language, rather than a group of languages. So, if you are talking about, for example, x86 assembly, and you compare that to another language of an equal low level, you would find that that other language would also be some variety of assembly. Then again, it would be for another architecture, so it wouldn't be very useful too.
© 2022 - 2024 — McMap. All rights reserved.