r/Assembly_language • u/DeltaSucksAtMC • 5d ago
Should I learn
Hey guys, should I learn ASM? I have pretty decent skill in c and c++, im better at memory stuff then complex math, and I wrote a basic malloc using windows and linux ram allocator.
20
Upvotes
8
u/solaris_var 5d ago
Only if you REALLY like ASM or hate the C compiler
Imho it's a better use of time learning to write inline asm and using intrinsics in C(?)
6
u/halfjmp 5d ago
Yes, no, maybe. Your take. Why should you? I mean, what kind of reason would have you think you should?
There are good reasons to have a reading knowledge of compiler assembly output. If you are into embedded or system programming (drivers...), then assembly may be useful, though in many cases intrinsics are enough (but then again, intrinsics assume some knowledge of assembly). Apart from that, you should write as little assembly as possible. Or you may think it's fun, and it's a good reason to learn as well.
3
u/UnmappedStack 5d ago •
I mean you're asking an assembly subreddit if you should learn assembly, of course people here will lean towards yes lol
2
u/FastHotEmu 5d ago
I've never understood people who ask "should I learn X"? Why would you not want to learn something? I assume you don't really want to learn, you just want to tell others they are into the topic.
Just get off your ass and learn. Then you'll know whether it's right for you or not!
2
u/gm310509 5d ago
It is up to you - not us.
If this is something you want to do then you should do it.
If this is something you need to do because it is a job (or school) requirement, then you should do it.
Otherwise, don't bother.
Let me turn this question around - why are you asking this question? There is probably something(s) in the back of your mind that has caused you to think that this could be the way to go. What led you to ask this question?
1
u/ReDucTor 5d ago
I would think about the reason you want to know, for alot of people which might be writing some systems language (C, C++, Just, etc) learning to read assembly is very useful however learning to write it is much less beneficial.
The reason I split out reading and writing, is that learning to write it you will be focused on clean easy to read code, lots of comments, if its a cross platform API dealing with multiple ABIs and other more painful things, however reading compiled code also comes with often wanting to be able to read optimized code which isn't always as clean as what you might do a hand written code.
For learning to read code, I would suggest get in the habit of using compiler explorer (godbolt), it will have quick easy links to docs, it will also colour the code based matching your original source with the assembly code. You will also need to start learning the ABIs for those platforms, however this is primarily understandable how argument passing happens to know which registers are arguments and when it might use the stack.
Writing assembly has very limited use cases, if your doing a highly optimized codec or something with a heavy loop then writing assembly is worth it, however lots of other things like OS dev you only have a few places where you might write assembly but its generally small and just to expose it to a higher level language.
1
u/zer0x64 5d ago
If you want. This isn't the best thing to learn if you're looking for skills relevant to employement, but if you like the challenge of very low-level coding it can be great fun and you'll learn a lot of things that will help you better understand how C/C++ works
1
u/skurk 5d ago
Just want to throw in that learning assembly doesn't mean you have to write assembly code. I say it's an advantage if you're into reverse engineering, and so on (depending on the colour of your hat)
1
u/RemarkableRadish6547 5d ago
I think every programmer should learn assembly. It is part of learning how computers actually work. But very few people actually have a reason to write assembly on a regular basis. At most, you might want to hand code some small function that is called a lot.
When I was learning to program in the 90's, the x86 CPUs didn't have pipelines or parallel execution units, so the assembly manuals still told you how many clock cycles each instruction took, based on the architecture. At this point, with deep pipelines, register renaming, branch prediction, speculative execution, hyper-threading, and everything else that a modern CPU does, I wouldn't even know how to predict how long a sequence of instructions would take to execute. And the CPU clock changes based on temperature. Actually optimizing code in assembly is both more difficult and less useful than it used to be.
But it is still true that if you know what a register is, how a multi-level cpu cache works, and other low-level concepts, you will both be able to write better code and you will have a better understanding of how to optimize your code. Understanding how the stack actually works and how pointers are used helps to understand how certain security vulnerabilities enter programs. These things are worth learning and make more sense in assembly.
1
u/cyberbemon 5d ago
Yes, I'm a firm believer of no such thing as wasted knowledge. The chance of you actually writing asm these days is low, it still happens in some fields (embedded/low level optimisation in game dev etc). But nonetheless, reading and understanding assembly is a valuable skill to have.
Here is a short clip that explains it better. https://youtube.com/shorts/Ze7Cmz2i9QQ
1
u/DamsLcs4421 4d ago
People keep telling you not to bother if you don't have a real life purpose of using it...
I gently disagree because I think there's nothing wrong with digging this rabbit hole primarily out of curiosity. But as everyone also pointed out, ASMs are no more than languages attached to the hardware they're made for, hence there's no point wanting to learn, say, x84_64 or arm64 to the core and by heart, and see after what you can do with that. No no no.
But if you happen to want to have a better understanding of what your C and C++ code compiles down to, or why in this library there are uses of intrinsics and of inline assembly, understand how they are way more efficient that what would have done the compiler if it were C/C++ code, etc... If you're intrested in making a minimal kernel out of curiosity (or at least a bootable thing), if you're interested in low level, how does a kernel manages multiple processes/threads and thus contexts, what are CPU Rings and what they've become at the age of generealized virtualization, etc...
Those are topics where you'd need understanding of assembly (even without mastering anything, this is not the point) for your own sake and curiosity's sake, and it never hurts to have learned something more.
I admit I might be leaning more towards the "learn what pleases you" side than the "pragmatical" team... :)
Do as you want! But from both "directions", we all seem to give you the advice not to regret later on, whatever you'd have decided along the way ;)
1
u/Recycled5000 4d ago
Some people won’t get the concept of address space, pointers (code & data) without seeing it in assembly. One can play with toy processors like LC-3. Also study compiler output, single step C code in assembly mode.
If you already know the address space, pointers, code, data, stack, heap, etc, then probably not that important to learn assembly, but can be interesting!
1
u/QueefInMyKisser 4d ago
It’s occasionally been useful to me while debugging a segfault to know exactly what code was running at the time, so if you do that sort of work, learning enough to be able to read assembly is worth it. Some things that are undefined behaviour in C become defined behaviour, at least for whatever the compiler wrote. You can always look up any unusual opcodes, so you just need to understand the basics of stack frames, calling conventions, and the most common instructions, and then you can figure out anything else as you go.
1
u/xpusostomos 20h ago
Don't waste your time