views:

836

answers:

15

Most people suggest that learning assembly is essential, its important to know the underlying workings of the computer, and so forth. But what I'm looking for are some practical suggestions that will make the effort of learning Assembly to be worth it.

What are your suggestions? What am I missing out on by not learning Assembly and pointers/memory management in general?

A: 

Duplicate: http://stackoverflow.com/questions/143561/is-there-a-need-to-use-assembly-these-days

arul
It's not. This one is about **learning** assembly.
PEZ
IMO that's not really the same question, it's about performance. this one is about benefit in terms of learning the art of programming.
frankodwyer
Learning? The question is 'Why' not 'How'. Read the question again.
arul
Guys, read all answers in the link I posted and you'll see.
arul
I agree. This is one of those "why bother" questions. Upvoting.
BobbyShaftoe
It's Why, yes. Why **learn**. The other one is why **use**. Different.
PEZ
Enjoy you punning, PEZ.
arul
I think it's Bobby who puns. =)
PEZ
There's some overlap but the answers seem differenet enough to keep both open.
Norman Ramsey
A: 

These days many assembly languages are actually fairly high level.

And it's always been true that if you learn 'C', that's close enough to assembly to get most of the learning benefits.

edit: thinking about this a bit more, in Knuth's books he describes an idealised assembly language. You won't go far wrong learning that, and reading those books.

frankodwyer
+4  A: 

Pointers/memory management are more general than assembly language. You need to understand them for C and C++ as well, which you might need if you have to maintain code written in C.

For assembly language, it is sometimes useful to read the assembler code that the C compiler generates, to find out whether it generates correct and efficient code.

Martin v. Löwis
+1 totally agree. Let me add that being able to read assembly is *invaluable* sometimes when you need to debug weird bugs.
DrJokepu
+1  A: 

This is sort of one of those questions that will always be asked: "Why should I know anything." etc. Well, perhaps you could get a job doing something besides building the next generic CRUD application or something like that. If you want to do any sort of system development, having a working knowledge of assembly is very helpful, if not vital. As far as what you're "missing out" perhaps you are missing out on actually knowing how computers work. Some people think this is desirable. Some people don't. Some people build processors. Some people dig ditches. It's all a matter of personal preference :)

BobbyShaftoe
+3  A: 

I think it's great to learn new languages. It opens my mind. Some languages are more mind-opening than others. I'd say assembler is one of those. It forces you to think about stuff like the call stack and instruction pointer. And it'll make you appreciate higher level languages even more. Another fun language to learn is PostScript.

PEZ
+1  A: 

But what I'm looking for are some practical suggestions that will make the effort of learning Assembly to be worth it.

Learn what assembly is. Really learn how to read (and understand) small fragments of it: how to walk/step through it in your mind. Perhaps too, step through some of it with a debugger (including seeing memory and registers being changed). Ideally, find some annotated assembly.

But, don't bother to learn how to write assembly: instead, learning to write C or C++ is probably 'low' enough for most practical purposes.

ChrisW
+3  A: 

I don't think you need to learn assembly for anything practical. However, it will ensure that you understand the real roots of what you are doing as a developer. In essence, assembly programming is a discipline for learning chip logic and architecture. I haven't programmed assembly in over two decades but it still informs the kinds of choices I make when programming C#.

Mark Brittingham
+5  A: 

You need to learn to read assembly so you can figure out what goes wrong when a complex statement bombs out. The CPU debug window shouldn't be a mysterious place.

Loren Pechtel
A: 

Another practical reason I can think of is reverse engineering application code to modify it for educational purposes ONLY, since this is widely used by crackers to bypass shareware application protections like time-limit or serial numbers.

An application like win32Dasm can convert executables into assembly code that can later be modified with a Hex editor like hiew. You can learn quite a lot about the flow of the program.

Epitaph
A: 

Well, on a practical level I did a class in 6502 assembler when I was first learning to code the early 80s. I also did some 8088 assembler. It's been of occasional use of the years since but I can't say it's ever really got my out of a hole on more than one or two occasions in 25 years. Groking C at a pretty fundamental level is of far more use. YMMV and it's certainly helpful as background, but as a direct practical benefit? Marginal really.

Perversely though one thing that has proved useful is at an even lower level. I did a class on chip design (NAND gates and the like) and as part of that was taught formal Boolean logic at some depth. That's been massively useful ever since - it's surprising the number of coders who don't really know what they are doing with ands, ors and nots :-)

Cruachan
+4  A: 

I think the main practical advantage to learning low-level things like assembly language, pointers, and memory management is that when you're writing or reviewing high-level code you're better able to instinctively or subconsciously spot performance issues or other pitfalls.

An average developer, might write a simple loop and think, "This code iterates over a set of integers and writes each to the console."

An expert developer might write the same loop and think, "This code iterates over a set of integers, and has to box each element to call the ToString method and ToString has to format the string in base 10 which is somewhat non-trivial, and then both the boxed integer and the formatted string will soon be eligible for garbage collection as no references will remain, and the first time this method runs, it will need to be JIT'ed..." and so on.

9 times out of 10, it may not matter. But that 1 time out of 10, the expert developer is likely to notice a problem in code that the average developer would never think to consider.

C. Dragon 76
A: 

Pointers and memory management are really a different question than assembly. If you want to do C/C++, then you need to learn pointers and memory management, because those are part of the language. But, even if you plan to use nothing but (say) Java all your life, you should learn something about memory management to keep from writing a memory leak despite the GC, and pointers are just the difference between atomic types and object references. You need the concepts or you'll write programs that don't work!

Practical reasons for learning assembly: debugging and optimization. Even if you don't write any assembly, one of these days you may need to optimize C/C++ code for performance. In that case, you'll need to be able to read the assembly for your inner loop, even if you never need to write another line of it.

Ultimately, I think your distinction between "knowing the underlying workings of your computer" and "practical suggestions that will make the effort of learning assembly worth it" is a false one. Ignorance does not pay. Learning how your computer works is a practical suggestion worth the effort!

I have a prophecy: someday soon, your program will run far too slowly to be practical, and crash intermittently with an out-of-memory exception. On that day, the sheer screaming anxiety of not knowing what the hell is going on or where to start looking in order to fix it will refund your karma debt, with interest...

comingstorm
Aren't there programs for desktop apps that analyze your program and point out which part seems to take the most time? For PHP we have xDebug which does this
Click Upvote
Yes, there are profilers and memory tracers and debuggers for systems languages, and they will probably help even if the associated disassembly displays are a mystery to you. However, as another answer put it: the CPU debug window shouldn't be a mysterious place!
comingstorm
A: 

I think learning about computer architecture, in conjunction of assembly, would open your mind quite a bit.

It would help explain lots of performance issues - e.g. parser's slow because there's lots of branches, and pipeline gets flushed very easily, branch predictor cannot compensate for everything.

Also, different architectures have their quirks. Someone talked about an assembly trick to swap 2 registers in place, involving xor's. It works, and it would run great for in-order execution core (most recent example would be the Intel Atom, and the Via C7 in netbooks), but not so great in out-of-order cores.

Knowing that may help you to detect poorly compiled code by inspecting it in assembly, and possibly be able to write code in higher-level language to sidestep the imperfection of compiler optimizers. I'm not trying to diss them, but they just can't be perfectly in tuned.

Calyth
A: 

I have some practical examples of why you need to know what is under the hood. Some useful links that you may find useful in this context are -

Assembly And The Art Of Debugging

Debugging – Modifying Code At Runtime

tc
A: 

The biggest practical advantage to learning Assembly is performance. You can optimize to near perfection when its required.

Silver Gun
The kind of performance improvement you can get by hand-optimization is almost never important. If you're not writing device drivers or other kernel-level code, and not working with compute-intensive code, then this is not a good reason to learn assembler.
John Saunders