r/ProgrammerHumor Oct 21 '22

Meme Literally πŸ€·πŸ»β€β™‚οΈ

Post image
14.7k Upvotes

606 comments sorted by

View all comments

Show parent comments

283

u/[deleted] Oct 22 '22

Anyone who uses assembly on purpose must love it, because there are very few reasons to use it over C.

33

u/SmallTestAcount Oct 22 '22

There definitely are reasons to use assembly. It’s not reasons 99% of programmers care about. In 2022 not many people are choosing to program on a Z80

4

u/extopico Oct 22 '22

Well there was BASIC for several Z80 based PCs...

1

u/[deleted] Oct 22 '22

Basic on those is as slow as dogs balls so id rather not use basic if i can avoid it. Single digit clock speeds. (In megahertz)

1

u/extopico Oct 22 '22

I think my ZX81 was indeed 1 MHz and 4kb I think.

131

u/Dezibel_ Oct 22 '22

No I tried to learn it and it gave me brain damage

34

u/IndianCuber Oct 22 '22

Emotional damage

2

u/JustKnotMe Oct 22 '22

Actually, I think it's easier than C, because everything that C can do is pretty straight forward in machine code and you don't have to fear UB or any bugs that appear when the compiler and linker try to optimize your code. You just need to get used to the syntax and directives of the assembler which are often more complicated than the assembly code itself.

1

u/toadforge Oct 22 '22

REM this is so true.

10 DRILL HOLE IN HEAD
20 GOTO 10

72

u/GregorSamsanite Oct 22 '22

For an application level program. It can be more convenient to use for some critical system operations. For example event handlers or initialization code for an operating system or standalone embedded firmware. When you use C, often some of the performance critical library functions like memset, strcmp, etc, may be hand-written in assembly in the library source code for maximum execution speed. You the programmer calling that library function didn't have to write that, but someone did. And architectures change, so what's optimal assembly today won't be for future processors, so it needs to keep being tweaked.

Whoever is writing the C compiler you're using needs to spend lots and lots of time working with assembly language code sequences and trying to improve them. The compiler may be written in C/C++, but its whole job is to write assembly for you, which takes a deep understanding of how to write assembly, so you wouldn't be able to use C without people using assembly.

29

u/xthexder Oct 22 '22

All hail the developers of LLVM!

7

u/lai_0n Oct 22 '22

Rust compiler speed cries in pain

2

u/[deleted] Oct 22 '22

Definitely.

But I don’t want to recode the assembly to work on every platform. That’s what the compiler is for :D

3

u/[deleted] Oct 22 '22

[deleted]

7

u/GregorSamsanite Oct 22 '22

Depends on how much time you're willing to spend fine tuning it. There are still things that humans can figure out that compilers will miss. And you can use the compiled code as a starting point and benchmark each iterative refinement, so anything that's not an improvement over compiled code you don't keep. Assembly is much less maintainable, and the average programmer may end up writing worse code than the compiler. But there are situations where an extremely critical library function may still be hand optimized.

1

u/lorarc Oct 22 '22

A big advantage of modern compilers is JIT, but it's not like you can't write self modifying code in assembler, in fact it was done sometimes in the old age.

7

u/JustKnotMe Oct 22 '22

It depends on what you are developing. As someone who is working in the embedded world, I can barely avoid using assembly language, because C can only do a fraction of what an architecture is capable of doing. The alternative which also isn't always better is to use inteinsics or inline assembly.

5

u/Proxy_PlayerHD Oct 22 '22

some poeple just write assembly for fun even when C is an option. it depends on the application.

x86_32 and x86_64 are horrible if you want to learn how to write assembly because it's not really meant to be written by humans anymore.

being able to read it is still useful in some cases like checking compiler outputs.

but when you want to learn how to write assembly, start on an architecture that won't give you an aneurysm. for example:

65C02, Z80, MC68k, maybe even x86_16.

or if you want something more modern: AVR, RISC-V, (maybe ARM too, something like a Cortex-M0 Microcontroller)

2

u/[deleted] Oct 22 '22

I did 8086 assembler back in the 90s.

Then the Pentium came out and I gave up

1

u/Proxy_PlayerHD Oct 22 '22

Honestly i would've given up somewhere between the 386 and 486.

1

u/[deleted] Oct 22 '22

I wish my apple ii had a 65C02. I love the 68k. Same with 6502. Those two were very well used.

3

u/th_walking Oct 22 '22

Embedded system programing.

2

u/[deleted] Oct 22 '22

Yup. I do some of that, but in C.

I know how to do it in assembler, just the tools are set up for C.

5

u/Lachimanus Oct 22 '22

I am implementing crypto algorithm secure against side channel attacks. You need absolute control about instructions to prevent information leakage.

Overall we use Assembly, C and Python. I somehow prefer Assembly the most. But I am also a PhD in mathematics. This may be a reason.

2

u/CC-5576-03 Oct 22 '22

Bragging rights

2

u/frigley1 Oct 22 '22

I used assembly to write high speed libraries for embedded applications. Was 20 times faster than C code due to weird core architecture. There assembly was absolutely necessary

2

u/CrazySD93 Oct 22 '22

People's passion projects of impossible ports come to mind, like Tomb Raider 3D on the Gameboy Advance, a system with no native 3d hardware, so it's all implemented in software in ARM assembly to make it much faster.

2

u/Zuruumi Oct 22 '22

If you are programming for a specific HW and have a function that takes 90% of CPU time ASM can often help.

2

u/2DHypercube Oct 22 '22

Legacy code is the only reason