Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×

Is Assembly Programming Still Relevant, Today? 676

intelinsight asks: "Consider the following question given the current software development needs, and also the claims of the Assembly lovers for it being a language that gives one insights of the internal working of a computer. How relevant or useful is it to learn Assembly programming language in the current era? "
This discussion has been archived. No new comments can be posted.

Is Assembly Programming Still Relevant, Today?

Comments Filter:
  • Yes. (Score:3, Insightful)

    by bladx ( 816461 ) on Thursday March 22, 2007 @07:28PM (#18451677)
    It's good to know how things work underneath the hood.
  • by madhatter256 ( 443326 ) on Thursday March 22, 2007 @07:29PM (#18451689)
    Isn't knowledge of assembly language for microprocessors required to create a higher level programming language?
  • by QuantumG ( 50515 ) <qg@biodome.org> on Thursday March 22, 2007 @07:30PM (#18451701) Homepage Journal
    Please remain ignorant of all lowlevel details of your deployment and development platforms.
    Please continue to treat both computers and the tools you use to program as magic black boxes.
    That way old dogs like me will still have a job.
  • by CosmeticLobotamy ( 155360 ) on Thursday March 22, 2007 @07:31PM (#18451723)
    For good programmers, yes.
  • Honestly... (Score:3, Insightful)

    by CyberBill ( 526285 ) on Thursday March 22, 2007 @07:35PM (#18451801)
    You really only need to know how to program assembly if you want to be a good programmer. If you want to be a crappy one, learn Java or C#, pretend pointers are magical, and be happy with your life. (I'm not saying those are bad languages, I'm just saying they're opposite from assembly)

    Also, a lot of embedded work is still done in assembly because with a lot of low-level industrial work having very precise clock-counts on everything is very important.
  • Very relavent (Score:5, Insightful)

    by Forrest Kyle ( 955623 ) on Thursday March 22, 2007 @07:38PM (#18451831) Homepage
    Well, given that the world runs on embedded systems, and will probably become more reliant on even greater numbers of even more complex embedded systems, I'd say assembler will be around for quite a while. However, in terms of game programming or something, it's probably not amazingly useful any more. It is my understanding that most of the API calls to advanced graphics libraries are about as optimized as they are going to get. Clearly you don't need it to write a medical billing application.

    I would not encourage universities to start pumping out CS graduates who have never seen assembly laguage, and don't expect it to phased out of the average Electrical Engineering curriculum any time soon.

    Frankly, I don't think it's a very good question. It's sort of like saying, "Given that we now have calculators and computer algebra systems that will do the math for us, is it really worth it to waste students' time learning the nuts and bolts of mathematics?" It has been my (limited) experience in software engineering that knowing how something works on a deeper level will almost always be an asset, and at the worst have no effect at all.
  • Yes (Score:5, Insightful)

    by Starji ( 578920 ) on Thursday March 22, 2007 @07:44PM (#18451911)
    Do you write drivers? Or do you need highly optimized algorithms? What about really low level firmware stuff?

    In other words, yes, there are good reasons for knowing assembly. Whether or not you'll actually use it is another matter entirely. Just depends on what you're working on.

    Actually I wouldn't be surprised if in about 10-15 years assembly programmers are in higher demand since none of the CS schools these days ever teach assembly anymore.
  • by grub ( 11606 ) <slashdot@grub.net> on Thursday March 22, 2007 @07:48PM (#18451971) Homepage Journal

    How do compilers know what to compile to? Magic? Imagine if all the assembly programmers died: who'd maintain & update compilers, embedded devices, many realtime instruments, etc. ?
  • by KokorHekkus ( 986906 ) on Thursday March 22, 2007 @07:51PM (#18451999)

    Isn't knowledge of assembly language for microprocessors required to create a higher level programming language?
    To create - yes. To use as a programmer - no. You can still be a good programmer if you know the cost (in terms of resources) for the operations you choose to make use of. A higher level language will most likely give you a wider range of ways to solve a problem within the given limitations. But only if you actually know the computational characteristics of the system (as a whole) that you are using. Simply put you need to realise which operations are expensive and which are cheap from a total perspective.
  • by dgatwood ( 11270 ) on Thursday March 22, 2007 @07:51PM (#18452003) Homepage Journal

    That's a pretty fine line there. If you can understand asm well enough to debug such issues, I would argue that you also probably know enough to write it, or at least very nearly so.

    I would say that you need to know how to program in assembly language, though it doesn't really matter much which ISA you use---MIPS, x86, PPC, ARM, whatever. What matters is the ability to understand what's really happening at a low level so that you don't do stupid things in high level code that cause your machine to have a seizure.

    For example, once you understand that your CPU only has a limited number of registers, you'll understand why (on some CPU architectures) it is a good idea to limit the number of function arguments so that they can be passed via registers, and that you should put the arguments that you are most likely to use at the beginning of your prototype so that they have the best chance of already being in a register.

  • Re:Yes. (Score:2, Insightful)

    by fm6 ( 162816 ) on Thursday March 22, 2007 @07:58PM (#18452069) Homepage Journal
    Looking at assembly code tells you very little about how modern software systems work. Any more than sheet metal fabrication tells you how an airplane works. Ever hear the expression "can't see the forest for the trees?" With assembly language, you're focusing on the individual leaves!
  • by LionKimbro ( 200000 ) on Thursday March 22, 2007 @08:04PM (#18452107) Homepage
    Yes; Understand too, how the gates work, all the details of how the chips work, (the myriad chips your program may run on,) and have a good understanding of quantum mechanics, as well. Understand all the business supply chains, as well.

    Anything else, is just-- pshaw... Black boxing it.
  • by MenTaLguY ( 5483 ) on Thursday March 22, 2007 @08:25PM (#18452411) Homepage
    Um, I know you were being facetious, but that's not a bad idea at all, actually. A comprehensive knowledge of those fields isn't normally worth it for most things, but basic literacy in all the areas you mention is actually very helpful at times.
  • Re:All's quiet (Score:5, Insightful)

    by Anonymous Coward on Thursday March 22, 2007 @08:25PM (#18452421)
    • Vertex Shader
    • Pixel Shader
  • Re:Yes. (Score:5, Insightful)

    by Lehk228 ( 705449 ) on Thursday March 22, 2007 @08:48PM (#18452683) Journal
    i agree that everyone should have decent understanding of what's going on behind the curtain, though rather than focus on the what, i would prefer to see more experience with limited environments.

    as in your example, too many people code like the only platform is the multi-GHz PC.


    even a year doing tools in Graphing calculator basic will teach appreciation for not wasting cycles doing everything the lazy way, 'cause sure, you usiung strcat doesn't slow the system in a noticable way, but when half the processes running are using it, and using it in "hotspots" suddenly you need a new machine because it's just not fast enough.
  • by davidwr ( 791652 ) on Thursday March 22, 2007 @08:50PM (#18452707) Homepage Journal
    Knowing assembly language is like knowing how to an internal combustion engine works.

    For most drivers, it's a curiosity.
    For most auto mechanics, it's somewhat useful.
    For anyone doing engine repair, it's very important.

    If you are programming at a hight level like Java, .NET, or web-based programming, knowing assembly language won't help much.

    It's only when you are using a language like C where knowing how the chip works can actually help you write your code does it really matter.

    Anyone doing systems programming, real-time programming, or anyone who needs fine control over their program's execution should learn assembly.

    For non-programmers and very high level programmers, it's about as useful as studying Shakespeare or business law. It'll make you a more well-rounded person but it won't help your code run faster.
  • by Bogtha ( 906264 ) on Thursday March 22, 2007 @09:17PM (#18452979)

    I don't think that's the case. It really depends on what you want to do. Typical desktop applications don't need any assembly language, nor in-depth knowledge of how the CPU works. In fact, it's probably a bad thing to worry about things like this — premature optimisation being the root of all evil and all that. You don't want to put a lot of work into making your application 1% faster and then realise you've ruined your portability.

    In fact, these days, there's a case for even doing away with languages like C for a lot of desktop applications. With the speed of today's computers, if you can write your application quicker in a scripting language, it's a worthwhile trade-off for many organisations.

    Sure, if you want to work with operating systems or things like games where performance is critical, then knowing assembly will make you a better developer even if you don't end up using it. But most of the software industry is working at a level far higher than that, and if you are at that level and making your decisions based on what instructions the CPU is getting, then you're probably doing a worse job than somebody who is entirely ignorant of assembly.

  • Re:easy as 1 2 3 (Score:2, Insightful)

    by nitrocloud ( 706140 ) on Thursday March 22, 2007 @09:28PM (#18453075)
    Like Duke knows anything of electrical engineering. It only takes a State student to tell you that (or a Carolina student, but they can go to hell).

    Curriculum here started with learning about what a gate was, how it was made from transistors (which were magic black boxes then), from gates we learned adders and other MSI devices, and eventually got to an abstraction of a microcomputer. Assembly then was a Godsend and now using that same assembly language, we've implemented C.

    Point is, reference a school for electrical engineering, make a better choice than masking Duke to the country. I mean, look here at State, Ga Tech, Va Tech, MIT, Stanford, Princeton, USC, etc.
  • Re:Yes. (Score:3, Insightful)

    by BillyBlaze ( 746775 ) <tomfelker@gmail.com> on Thursday March 22, 2007 @09:39PM (#18453163)
    Could you design an airplane without a basic knowledge of sheet metal fabrication? I think not.
  • by sterno ( 16320 ) on Thursday March 22, 2007 @09:49PM (#18453233) Homepage
    Frankly I think a good programmer is somebody who writes well documented and designed code. I don't think somebody's knowledge of the low level assembly programming necessarily helps with that. I'd rather somebody wrote somewhat inefficient code that I could read and, as needed, optimize, then have some spaghetti pile that nobody could understand but was lightning fast.
  • The C Conspiracy (Score:4, Insightful)

    by jd ( 1658 ) <imipak@yahoGINSBERGo.com minus poet> on Thursday March 22, 2007 @09:51PM (#18453265) Homepage Journal
    There really isn't a language called C. It's just a bunch of assembler macros. :)

    Seriously, assembly is important for all the reasons you noted, but also for some others. If you know assembly, the chances are:

    • You know how to design the software, because you got sick of trying to debug in a disassembler
    • You know how to express the design cleanly - unclean assembly is longer, so takes more effort, and is murder to debug
    • You know how to add structure to the code, as it's easier to test and fix a small subroutine than a gigantic blob
    • You know how to avoid unnecessary structure, as exploding stacks is generally not a good idea
    • You know how to re-use code, as it is pure hell to repeatedly reinvent anything in assembly

    All software engineering, computer science and programming courses should start by requiring people to program a non-trivial application on an ARM processor, or something with an equally limited instruction set, in pure assembly. Why? Because then you get people who think, who program with care and forethought, who think of bloat not in terms of adding more RAM, but in terms of opportunities for bugs, glitches and gremlins. Sure, you'll get more dropouts. The computing world doesn't need more code monkeys, so it's no loss if they did. Who needs a society of half-baked, semi-literate coders?

    This is not elitism, because I'm not saying that anyone should be excluded from the profession. I don't think they should. What I do think is that society needs to make damn sure that the typical coder isn't the worst coder, which is what you get if people are trained to NOT think but to let the computer do the thinking for them. Windows may act like a HAL-9000 at times, but trust me, it isn't remotely capable of anything resembling thought. A bad design or a poor implementation will not be rectified by some magical intelligence in the machine, because there isn't any.

  • Re:Yes. (Score:2, Insightful)

    by Anonymous Coward on Thursday March 22, 2007 @10:01PM (#18453363)
    At no point is it required that you know exactly what order your algorithim is. You should just have a good feel for how good its doing. Use code profilers, etc to help with this.

    Wait a minute. You're going to go all the way through design, design review, and code it up, all based on a "good feeling". And THEN you're going to check it's efficiency with a profiler? You take "iterative" software design very literally, don't you.

  • Re:Yes. (Score:5, Insightful)

    by Dachannien ( 617929 ) on Thursday March 22, 2007 @10:04PM (#18453397)
    I don't think that's a very apt analogy (though few analogies ever are apt). Driving a car to and from work is more akin to using Word (or OpenOffice) on your computer. You don't really need to understand the nuts and bolts of how either one works, but you do need to know what the controls do.

    Programming in a high-level language is more like doing basic maintenance on said car. You definitely need to know something about how the car works, and the more you know, the more work you can do on that car yourself. Programming in assembly is sort of like taking the engine out and repairing or modding it. You may never need or want to do that, but knowing how an engine works on a detailed level can help you diagnose and remedy things that don't actually require going to those lengths. Similarly, knowing how a microprocessor works can help you understand more about what you're doing when you program in a high-level language.

    It also gets you into a mindset where you're thinking about this sort of thing, which is why assembly should still be required teaching in an undergraduate computer science curriculum.

  • Re:Yes. (Score:5, Insightful)

    by smallpaul ( 65919 ) <paul@@@prescod...net> on Thursday March 22, 2007 @10:04PM (#18453399)
    My philosophy is that you should know the layer beneath the layer you program on. Let's say you're working on Groovy code which is half-interpreted and half-compiled on a JVM which is written in C, perhaps using JIT or perhaps not, running on a CPU. Nothing that you can possibly known about how registers work or how jumps work will help you to understand the performance of your program several layers up -- especially given that your program will run on several different runtimes optimized in several different ways on several different CPUs.

    But if you're going to program in Groovy then you should know Java and perhaps JVM IL. If you're going to program in C then you should know assembly. If you're programming in assembly then you should know about how CPUs will reorder your instructions etc. If you're building a CPU, then you'd better know physics.

    I really don't think that if you're writing an app in Rails/Javascript/SQL you are going to achieve any performance or debugging benefits by understanding assembly language. It's just knee-jerk to say that every programmer, no matter what they do day-to-day should be knowledgeable about assembly. The same effort expended learning about the layer UNDER your development environment would have a much better payoff. E.g. a Javascript programmer reading the Firefox source code (or at least benchmarking FireFox and IE on important operations). With each level deeper you go, you achieve quickly diminishing returns.
  • Re:Yes. (Score:5, Insightful)

    by thecheatah ( 977630 ) on Thursday March 22, 2007 @10:07PM (#18453413)
    Wow, the first programming language I learned was z80 assembly :-). I use to make games for the ti86.

    here is a side scroller i made written all in assembly (includes animated screen shot)

    http://www.ticalc.org/archives/files/fileinfo/232/ 23280.html [ticalc.org]

    The things I learned:
    1. 4mhz processor is REALLY fast!
    2. How the stack works.
    3. How absolute and relative jumps work.
    4. How to create "objects" and implement "methods"
    5. How the smallest variable, the register works.

    I have to say that after making games in assembly, I am actually disappointed in how well the current consoles handle them. I would expect them to be able to crazy things with the hardware they are given. That is also why I am interested in the ps3, it forces programmers to understand the underlying hardware.

  • by pinkfloydhomer ( 999075 ) on Thursday March 22, 2007 @10:08PM (#18453431)
    Hmm. Assembly is still relevant and useful for certain tasks, of course.

    But two things come to mind:

    1: Handcoders can code better than good compilers?

    Yeah, in some cases after a lot of refining. But it is not as easy as it once was.

    Compilers have gotten much better and processors have gotten a lot more complex. It's not just "how many clock cycles does this instruction use?", you also have to take various forms of micro-parallelism (pipelining, branch prediction, etc.) and cache hierachy issues into account.

    2: It's good to know what goes on under the hood, sure.

    But in many, many software developer tasks, early optimization is the root of all evil.

    I would actually much rather recommend a top-down approach for most problems, abstracting away low-level details, rather than going bottom-up. The teaching approach of the great "Accelerated C++" comes to mind.

    A lot of developers that know a little or a lot about low-level programming write less than excellent code in other regards (algorithmic complexity, design, re-use, etc.) and they can't seem to stop focusing on performance throughout the process.

    For most problems, performance isn't critical, and even when it is, it might be better to look for algorithmic enhancements (lowering complexity) rather than do low-level fiddling. /David
  • Re:Yes. (Score:4, Insightful)

    by aj50 ( 789101 ) on Thursday March 22, 2007 @10:12PM (#18453469)
    I think they should know about big-O notation, as in what it means and how it will affect the scaling of your algorithm but I don't think it's useful to have to prove it formally. It's useful to express what usually you should be able to see quite quickly in a way that other people understand. It allows you to say A is better than B because it's O(nlog(n)) rather than O(n^2) without trying to explain why a recursive algorithm can be quicker than one which just has two for loops.

    It's also handy for sanity checking when a quick calculation shows that your algorithm which works fine for n=10 will take something in the order of three years to complete for n=1000.

  • Re:All's quiet (Score:5, Insightful)

    by doti ( 966971 ) on Thursday March 22, 2007 @10:13PM (#18453471) Homepage

    Those bastards make you study it in one of your college courses.
    That is justified by all your previous points.

    I see it this way: assembly is still used today, but only in a smaller niche. But that's not the only reason it's relevant. I think it's a good knowledge to have, even if you'll never use in practice, but it's concepts help you understand the whole. Much like Math, or basic Physics.
  • Re:All's quiet (Score:3, Insightful)

    by kyashan ( 919683 ) <dpasca@gmail.com> on Thursday March 22, 2007 @10:15PM (#18453503) Homepage
    I think some assembly knowledge is important, at least to understand pointers.
    But, shaders are hardly written in assembly anymore, for all the good reasons.
  • by NormalVisual ( 565491 ) on Thursday March 22, 2007 @10:20PM (#18453559)
    680x0 assembly was similar in that respect - the register set was very orthogonal, and the chip in general was a blast to code for. Oh, and no segmentation either. ;-)
  • by DoctorPepper ( 92269 ) on Thursday March 22, 2007 @10:21PM (#18453569)
    Communicating in Morse code. It's a pain in the ass to learn, but when you do, you find the rewards more than justify the effort spent.

    Also, it's good to remember that Assembly language is just one more tool in a programmer's tool box. I wouldn't write throw-away scripts in Assembly language, just like I wouldn't use C. I'd probably use Perl, Python or shell script, as necessary. When you need to hand-tune that algorithm to get that last little boost in performance, being able to drop down to Assembly language can save the day. Too bad it is a dying art.

    On another note, I agree with the other posters that said learning Assembly language allows you to learn the hardware better. 8086 Assembly language was my second language (after BASIC), and I used it for several years, until I started using Windows and found it was much easier to write a Windows program in C :-)
  • Re:debugging (Score:2, Insightful)

    by Anonymous Coward on Thursday March 22, 2007 @10:23PM (#18453601)
    They stare at the code for a while, make wild guesses about how the problem could have happened, add a lot of couts, and hope for the best. Seriously.
  • Re:Well, no. (Score:2, Insightful)

    by TwobyTwo ( 588727 ) on Thursday March 22, 2007 @10:26PM (#18453617)
    I think you're suggesting that for certain kinds of optimization it's as important to know about machine architecture and organization, I.e. things like cache associativity and size, relative speed of memory vs. registers vs. cache, etc., as it is to know or optimize the use of particular "assembler" (actually machine) language instructions. Good point. Still, if you want to know how many memory accesses either the presupplied strcat or your own alternative are going to issue, and which addresses they're going to hit, knowing machine language is a big help.
  • Re:Yes. (Score:3, Insightful)

    by ivan256 ( 17499 ) on Thursday March 22, 2007 @10:44PM (#18453769)
    I hate to tell you but pretty much every "modern" system has components that are written in assembly. Some of us still know how to write low-level software, and that's a good thing, because otherwise all of your fancy "modern" languages wouldn't have a system to run on.
  • by tlambert ( 566799 ) on Thursday March 22, 2007 @10:49PM (#18453815)
    Answer to "What's hard about pointers?"...

    There are people who cannot grasp the difference between "a thing" and "a respresentation of a thing". In fact, there was an entire century where almost the entire school of French philosophers were unable to grasp that there was a difference.

    For pointers, it comes down to realizing that a pointer to memory is not the memory, it's a representation, and the real memory lives somewhere else: at the dereference of the pointer. And at that location it takes up real space. And so does the representation (but it's comparatively tiny).

    The ability to make this disctinction comes naturally when you've written assembly code of any complexity, since you've had to manage the memory yourself. But if you've never done that, or, worse, you've only ever programmed in languages which eschew pointers and try to pretend that their own internal implementations don't use them, even if they won't let you use them, well, then, you've got a conceptual problem. An that conceptual problem is going to be very hard for you to overcome.

    It also makes it very, very hard for someone to understand row-major vs. column major languages, or how you would link a program in one against a library in another, and be able to usefully communicate your data between the two. Or it makes it hard to understand the difference between "call by value" and "call by reference.

    If I'm interviewing someone, and it becomes clear that they need a "code interview" because some things don't add up between their banter and their resume, the first thing I whip out is a pointer problem.

    -- Terry
  • Re:Yes. (Score:2, Insightful)

    by damiam ( 409504 ) on Thursday March 22, 2007 @11:18PM (#18454055)
    Well, on Slashdot you never know. :-) If you know those algorithms, you know most of what you need to know about big-O notation. Why does selection sort require n^2 comparisons to sort n items? Why does merge sort only require n*log2(n) comparisons? If you can answer those questions, then you can say that selection sort is O(n^2) and merge sort is O(n*log2(n)). You don't need to know the formal mathematical definition of O() as long as you have a working knowledge of what it means and how it's generally used.
  • Re:All's quiet (Score:2, Insightful)

    by Qwertie ( 797303 ) on Thursday March 22, 2007 @11:35PM (#18454231) Homepage
    You're writing software for any chip, on any platform, that requires direct hardware level access, e.g. device drivers, boot code, or core-features. No machine, no matter how fast can be programmed exclusively in C. For example, in C you simply cannot a DCR on a PowerPC. You need a special instruction w/o a high-level language equivalent.

    You're certainly right, but programming language extensions could get around these limitations. For instance, I think the PIC C compiler, which is not really standard C, has an extension that lets you write and install an interrupt service routine without any assembly. One could imagine such extensions for almost any hardware feature; it's just that compiler-writers rarely bother to offer such extensions.
  • Re:Here's another (Score:5, Insightful)

    by countach ( 534280 ) on Thursday March 22, 2007 @11:45PM (#18454305)
    Maybe, except that not many assembly programmers can make faster code than a C compiler anyway. It's no use being a mediocre assembly programmer.
  • Re:Yes. (Score:3, Insightful)

    by Sigma 7 ( 266129 ) on Thursday March 22, 2007 @11:48PM (#18454333)

    The fact is, that computers today can run even the slowest of code fast enough.


    No, they can't.

    In the current Standings [recmath.org] for Al Zimmerman's programming contest, you see a lot of entries that have many submissions, but aren't even close to the optimal result. Even on the smallest scale, the slowest of code would go through all 20 trillion possible cominbations - the next smallest is an order of magnitude larger, and anything larger is within don't-even-bother territory.

    And yet, there's a person who has effectivly maxed-out their score, with a significant lead in the third category compared to the many other submissions. While he has at least one non-top submission, it's not something obtainable just by throwing as much computer power as possible.
  • by nadador ( 3747 ) on Friday March 23, 2007 @12:01AM (#18454427)
    As a marketable skill, assembly won't get you anywhere. There are a handful of places were knowing a specific assembly language is a prerequisite (boot loaders, deeply embedded applications, etc.) but these are just a fraction of the overall job-space for software engineers. Most software engineers never mess with assembly; they are, in fact, afraid of it and think that it's evil.

    Given all of that, assembly language *is* the hardware/software boundary. It's where all of the fancy abstractions from CS dissertations meet reality. Understanding computer architecture is a huge asset as a software engineer, and to properly understand how software and hardware interact, you have to learn at least one assembly language. There is no alternative. For most people, it is an unpleasant experience, but the payoff is enormous. The learning process that you undergo while learning assembly will change the way that you see your software and will help you understand why your code is so slow and how to make it fast by design.

    I have one last point. When you tell a potential employer about the low-level stuff that you know or work that you've done, your assembly skills are a proxy for understanding how hardware works (at least to interviewers with half a brain). If their software needs to run fast, they'll be happy that you understand the deep magic of hardware.

    (Incidentally, I think that the fraction of software jobs that require an understanding of hardware and knowledge of assembly languages, linker internals, etc., are the only fun ones and the only ones worth having. So I learned MIPS, ARM, PowerPC, and TMS320C6 assembly, and they have all served me very well because I don't have to refactor C# for a living.)
  • Re:YES! (Score:1, Insightful)

    by BritneySP2 ( 870776 ) on Friday March 23, 2007 @12:12AM (#18454511)
    > Seriously

    Yeah, right, let me go and find myself an IBM/360 to get exposed to... "Seriously" - you are suggesting to ignore, what, 90% of computers in the world - hell, the one sitting on your desk.

    How can this be serious (or insightful).

  • by davidwr ( 791652 ) on Friday March 23, 2007 @12:52AM (#18454769) Homepage Journal
    In most programs, easy-to-read, easy-to-maintain code is worth a size and speed penalty of up to several times that of hand-optimized assembly code, and it's almost always worth a 0-50% penalty.

    This is particularly true for programs that
    • don't need to be shoehorned into memory or onto disk
    • spend most of their time waiting, not running

  • Re:Yes. (Score:1, Insightful)

    by Anonymous Coward on Friday March 23, 2007 @01:48AM (#18455047)

    Even after explaining it to him, yes he will avoid it, but he does not really understand why.

    I am not a C programmer; I learned a bit of C, a little more C++ and a small bit of assembly either on my own or during various courses at school. I understood your explanation fine. Why do you think somebody who is otherwise good at C would not understand if explained to them in precisely that way?

    but they simply have no concept of the fact that some operations take longer than others

    I don't buy this at all. I know it's a fairly lame example, I doubt you'll find any programmer who couldn't tell you that "x = x + 1; x = x + 1; x = x + 1;" is going to be a quicker than "while(x < 100000) x++;" even though the latter is less lines of code. I also find it hard to believe that they wouldn't be able to abstract that concept more to understand that two ways of doing things don't always work equally fast. Heck, hasn't just about EVERY programmer at the very least had a basic introduction to sorts? Even if they never profiled them in any way, I bet every programmer at least knows that there are multiple algorithms available that would give the same result with the same input. The logical reason for that is that one is faster than the other, either generically or in some special use case.

    If you want to argue that they won't know which is which, okay. I'm not sure learning a lower-level language is going to help with that though.

    If you are ignorant of the very basics of internal combustion engines and can't understand the dangers of lugging or redlining an engine and the importance of using the right RPM, you will never be a good driver.

    I assume you don't mean "a good driver" in the sense that most people mean it; rather, as some sort of measurement of technical ability. This is why I don't really follow this "you have to learn it or you're the suxxors!" argument.

    The things that people keep mentioning in this thread that assembly teaches--registers, stack, heap, queue, blah blah blah--can definitely be taught in abstraction, and probably much simpler than throwing an assembly manual at them and telling them to go to town. In fact, I would be surprised if most assembly lessons/classes don't begin with those very same abstracted explanations, before or alongside the throwing them in the pool approach.

    Maybe it helps them learn better, maybe it's more in depth, etc etc. Maybe it's just a really nice way to teach all of these sorts of things at exactly the same time. These are things you can argue, and probably relatively successfully. I just don't think you can really argue that it's not possible to understand the concepts if they are abstracted a little bit. Especially when you're talking about programmers who are writing in languages that are more abstracted from the concepts.

    Besides which, I don't really hear anybody argue that a well-written assembly program isn't going to be faster--perhaps substantially faster--than a well-written, for example, Java program. But isn't the whole point of C, C++, C#, Java, the majority (or all) of scripting languages, etc ad naseum to get you AWAY from the assembly to varying degrees? The argument being largely that the speed increase you would get simply isn't worth the extra development time, especially on near-modern systems?

    If you're coding in some niche markets, where speed is absolutely vital or direct, precision control is vital, assembly may be important. (Of course if you're writing the very lowest level things it is necessary.) Other than that, I think much more abstract concepts of efficiency, especially compared with some nice practical examples of performance testing, will do the trick. I'm not saying people shouldn't strive for efficiency, just that there are probably easier, shorter, more applicable ways of getting there.

  • Re:All's quiet (Score:2, Insightful)

    by wtarreau ( 324106 ) on Friday March 23, 2007 @02:03AM (#18455099) Homepage
    100% agree. There are a lot of missing features in C which require assembly nowadays :

    - bit rotations => have to be coded by ORing bit shifts and masks
    - bit counting (FFS/FLS) => have to be cleverly coded to avoid iterations
    - locking => you need the lock instructions/prefixes of CPUs
    - prefetching => idem
    - memory barriers => idem

    And the list is long. What do we do instead ? typically, bit operations are done by hand with 100 times slower operations and using jumps and loops while a single instruction almost always exists. Locking accesses is performed through calling functions from heavy and slow libraries such as pthreads.

    It always strikes me to see code doing such a thing :
            pthread_mutex_lock(&counter_lock);
            counter++;
            pthread_mutex_unlock(&counter_lock);

    While in assembly you would be able to do this on many platforms :

            LOCK INC counter

    Which is basically what is done in the mutex_lock (with added tests).

    We really need some C extensions to access the lower level, but unfortunately,
    the trend is the other way :-(

    Willy
  • Re:Yes. (Score:1, Insightful)

    by Anonymous Coward on Friday March 23, 2007 @02:43AM (#18455245)
    saying that you don't need knowledge about assembly language because the compiler does it for you is like saying that you dont need to know addition because your calculator can do it for you. That you have a tool to do it faster is nice, but understanding what is going on is better.

    Some might say that it's more like saying you don't need to know how to use an astrolabe because GPS can do it for you.

    That analogy is just as apt.
  • Re:All's quiet (Score:4, Insightful)

    by aztracker1 ( 702135 ) on Friday March 23, 2007 @04:37AM (#18455663) Homepage
    Sorry, but that "multiplatform code" you speak of requires a lot of Assembly code under the covers. For the most part assembly is delegated to hardware integration, drivers, and performance tweaks. It is still vital to the industry... I will say that most developers have no need to learn it, but it is far from obsolete. C is still widely used for lower-level libraries and APIs, I wouldn't suggest it as a career path for most developers, but it's still pretty necessary.

    Personally, I like higher-level languages that abstract a lot of the inner workings such as C#/.Net, Python or Java. I like to concentrate on solving problems or making things work. However without those that *DO* write in assembly, nothing I write would *RUN* anywhere.
  • Re:Here's another (Score:4, Insightful)

    by Anonymous Coward on Friday March 23, 2007 @05:43AM (#18455955)
    To consistently beat a C compiler: Write your code in C with inline assembly if required, then compile through Assembler to get assembler source code. Next, hand tweak the assembler code and add C as comments. Pretty soon you will start to think like a compiler and your C code will get better too!
  • by justthinkit ( 954982 ) <floyd@just-think-it.com> on Friday March 23, 2007 @08:42AM (#18456991) Homepage Journal
    I've worked with people with very focused high-level programming skills and found that while they could write mostly decent code, their code was also most likely to fail in production since they were completely mentally removed from concepts like disk-seek times or bandwidth constraints.

    I'm not a great programmer, but I've always had a good "sense" (for lack of a better word) about technical things. I worked a bit at a company doing mid to high level (V)FoxPro programming. They put me on the least desired machine and I set to work. Within minutes I realized the machine was not running right, CPU at 100% or close to it most of the time. Turns out it was virus-infected (despite NAV, of course). I found the name of the EXE, renamed it in autoexec.bat before it loaded, then deleted same. Problem solved and the oldest 'clunker' became a quite acceptable computer.

    I think this story illustrates the two broad classes of programmers. (1) those able to get a task done, no matter how nerdy or obscure (but who are pathologically incapable of documenting their work, or teaching others) [e.g. my co-worker who had used that computer for months or years without noticing the virus] and (2) those who are good at interface, optimization, and documentation but lack the penetrating power to solve the more difficult problems [e.g. myself -- I had to leave that job because I couldn't 'crack' the OO stuff].

    Speaking to this thread's main question: both classes of programmer would need to understand some assembly, but for different reasons. Group 1ers would likely end up using it (or having to debug/change it) from time to time -- and it would be no big deal to them to learn it, use it, whatever. Group 2ers would likely want to know _when_ to use it, and probably get someone else to do that coding.

    In the geek cred hungry world of /., not many would want to admit to being a Group 2er but I have no problem with it. For example, Group 2ers would also know when a Group 1er's code sucked, from a performance standpoint. Coders with a trailblazer mindset are rarely good optimizers.

    BTW, in considering where Woz, Ciarcia [circuitcellar.com], Kahn [wikipedia.org] and Hertzfeld fit into this, I think they are Group 1ers who simply took an interest in Group 2 stuff. If you can learn both mindsets, you are one powerful programming dude, IMO. [Pity that 2ers like myself can't easily (ever?) become 1ers.] Most 1ers just want to get the job done and move on, yet so much can be learned after you think you have finished your program. [MS deserves props for realizing this and assigning a second unit to work on optimizing the code already working -- Win95 crap became slightly less crappy Win98 through this process (pdf [ieee.org])]
  • by mikehoskins ( 177074 ) on Friday March 23, 2007 @08:59AM (#18457151)
    The original post asks if Assembly is still relevant today. I'll ask some rhetorical questions (the only kind in a blog) and see how they apply:

    * Would you want an astronaut to understand physics and math?
    * Would you want a doctor to understand chemistry and biology?
    * Should somebody studying to be a Literature teacher take their full set of liberal arts courses, including history?
    * Should somebody earning a business degree take music appreciation?

    Most of us probably said, "Yes" to most or all of those above. Even if the study seems irrelevant or too "low-level" or too "high-level" at the time, there are areas of coursework that help us understand things better.

    I see a lot of dead wood in the IT industry. There are enormous numbers of people who either have no passion or who do not have a deep-enough or broad-enough knowledge of computer science to do their daily data processing job well. They are dependent on others around them for everything, even though they may be very skilled in one area.

    By having both a broader and a deeper knowledge, people are necessarily better at troubleshooting and at understanding the areas outside their particular specialty. It makes them be better at all of IT and helps them do their specific role.

    You should learn IT two ways -- deeply and broadly. You should deeply learn specific skills (Java/C#/Linux/Windows/scripting in Ruby/whatever) and you should learn broad skills (computing theory/relational databases/networking/troubleshooting/programming/a nalysis/architecture/whatever). The difference is training vs. education.

    There is an enormous difference between training and education. Training is learning specific skills for specific tasks (narrow/specific), while education is broader and teaches you how to think, understand, and apply (broad/general).

    While taking Assembly may not seem relevant at the time and you may never directly use it again, for every programming task, having a strong background in all of computing theory (including how the CPU handles its low-level instructions) educates you and gives you a deeper understanding. (Don't just be trained, be educated!)

    My recommendation is the book My Job Went to India (And All I Got was this Lousy Book). If you can't afford it, read the sample chapters, especially the "Being a Generalist" and "Being a specialist" chapters at http://www.pragmaticprogrammer.com/titles/mjwti/in dex.html [pragmaticprogrammer.com].

    Personally, unless you need the specific class/training, I'd say that FORTRAN or COBOL ought to be abolished as required material in all colleges and shouldn't be in the degree program. Those should be electives only. Assembly, on the other hand, should remain required, for a deeper and broader education. (Don't settle for a dumbed-down program).

    The difference, again, is training (specific/skill-oriented/task-oriented) vs. education (general/broad/understanding-oriented). Education and being a generalist will reap large rewards, long term. So stick with it and take that class. Assembly is a very important foundation class that educates you, long-term....

    Another rhetorical question I have is this: "Are you passionate for IT or is it just a high-paying (presumably) job?" If it isn't a passion of yours, find you passion and do it well. If it is, take Assembly and like it -- it'll help you appreciate IT, your computer, your high-level language, and give you a more educated view of the "soul" of your computer.

    (They don't make you take Assembly at many/most schools for their health. It would be a crying shame to remove it from the required courses).
  • Re:YES! (Score:3, Insightful)

    by Ihlosi ( 895663 ) on Friday March 23, 2007 @09:24AM (#18457451)
    So how does one learn assembly today?

    Many different ways.

    Using an emulator of a legacy machine would be one way. You could also use evaluation kits for various microcontrollers ('51, ARM, PIC, AVR, whatever suits you best). They have the added bonus that you're running on actual hardware. You could also try a processor simulator, which comes with many uC/DSP development kits.

    Say I would learn 68000 Assembler, would that knowledge be much useful when switching to x86?

    Yes, because you have already mastered the concepts behind assembly (registers, processor flags, pointers, etc). A different processor may have different rules, but the concepts stay the same. Some of the rules are the same on many architectures ("If the processor has a zero flag, then counting down in loops is preferable to counting up.", for example). Mnemonics and Opcodes are something you just look up in the documentation.

  • Re:Yes. (Score:2, Insightful)

    by Anonymous Coward on Friday March 23, 2007 @09:45AM (#18457665)
    You might want to consult the Wright brothers on that one.
  • by suggsjc ( 726146 ) on Friday March 23, 2007 @10:05AM (#18457929) Homepage

    Should somebody earning a business degree take music appreciation?
    All of your other examples had a direct correlation. I'm not knocking music appreciation, but it does seem like more of a stretch than the others.

    Anyway, the real question/headline should be "Is Assembly Programming Still Relevant to Mainstream Developers, Today?" and the answer is simply no. Because that analogy would be something more like:
    Should an elementary school teacher have an MBA so that she can understand the inner-workings of the business environment of her school system in order to be able to more cost effectively teach her students in a manner that maximizes her usage of government funding?

    You made some other good points, but I'm just too lazy to comment on those.
  • by starX ( 306011 ) on Friday March 23, 2007 @10:24AM (#18458219) Homepage
    Here here!

    Asking why study Assembler is a little like asking "why study Latin." It's important to have an understanding of the low level programming because it will help you understand what's going on when using something higher level like malloc(), which will in turn help you write better programs.

    Just my $.02
  • Re:All's quiet (Score:1, Insightful)

    by Anonymous Coward on Friday March 23, 2007 @11:08AM (#18458885)
    You missed an important one and that's debugging.

    In my current job I spend the majority of my time looking at stress failures (either crash dumps or live remotes), some of which were on production servers running optimized builds. In order to effectively debug these kinds of failures you really need to understand the following:
    • Assembly language for the architecture you're working on. This doesn't necessarily mean that you need to be able to write an asm app from scratch but you do need to be comfortable with the instruction set.
    • The various calling conventions so you know how a stack frame is laid out. Especially helpful when the stack is corrupted so the debugger gives a bad call stack and you need to try to reconstruct the call stack manually (not always possible but you get lucky sometimes).
    • The memory models for the various CPUs (especially important for Itanium, if you're unfortunate enough to have to support this architecture ;)).
    • For C++ code, know how your compiler lays out class objects and how vtables work.
    • Depending on the type of app, some OS internals can also be helpful.


    Ok so I guess some of isn't directly related to assembly, but it is in the same spirit other people have pointed out which is to know how things work under the hood.
  • Re:Yes. (Score:1, Insightful)

    by Anonymous Coward on Friday March 23, 2007 @11:30AM (#18459237)
    Nice work. Ashame most current day programmer's could never write something like that even in a high level language.
  • Re:Yes. (Score:2, Insightful)

    by ravenlock ( 693538 ) on Friday March 23, 2007 @12:13PM (#18459855)
    Make it work.
    Make it right.
    Make it fast.

    Or,

    The rules of optimization:
    Rule 1: Don't do it.
    Rule 2 (only for experts): Don't do it (yet).
  • by drolli ( 522659 ) on Friday March 23, 2007 @01:24PM (#18460867) Journal
    > Yes; Understand too, how the gates work, all the details of how the chips work, (the myriad chips your program may run on,) and have

    If you understand what the gate does, there is no semantical level to break it down any more. Howver, be aware that it consumes Energy.

    > a good understanding of quantum mechanics, as well.

    That is not so important.

    > Understand all the business supply chains, as well.

    Yipp, this indeed is important. Understanding why sometimes a technologically favourable solution is not the best makes you a good engineer. (E.g.: Instead of asking "Could we not transport four video streams more over our ethernet if we use an adapted divx coding with increased buffer size?", it may be better to ask: We need a camera, well tested, avaialble in thousands, weatherproof, from an reliable supplier with a standard protocol, because handling a problem in the firmware of a device which is distributed in hundreds over this large industrial facility will consume time and money.)

    > Anything else, is just-- pshaw... Black boxing it.

    Yepp. More than one Comapany died in such a way.
  • Re:Yes. (Score:1, Insightful)

    by Anonymous Coward on Friday March 23, 2007 @01:32PM (#18460979)
    There appears to be a very big misunderstanding of the scope of projects and design in your post (not your code; not that I looked).

    It is naive to compare Assembly coding on a Ti86 to Assembly programming on an x86 processor, or a PowerPC processor. yes, the basics are the same, but there is still a lot more going on and necessary to understand than you seem to be acknowledging (albeit, probably unintentionally).

    On the scale of a modern game, it takes 50+ people working simultaneously to release the game within 2-4 years (of course not all of them are programmers), and that's in higher level languages, plus some Assembly for the verious graphic's shaders. When you begin to make games on this scale, it's not always just the fact that they didn't make the game in Assembly that brings out the occasional slow down (just to be clear, there are hand optimized Assembly parts, and a lot of developers will write their code in a high level language, then optimize the resulting Assembly). In most cases, it has nothing to do with the fact that they did not do parts in Assembly, but simply has to do with everything that's going on is simply too much to handle especially with graphics, which ironically probably have the most Assembly hand-made in them across the code base.

    If you want to code games in Assembly, then more power to you, but good luck trying to do it in a multithreading environment while trying to get something usable that is worthwhile on a deadline.

Say "twenty-three-skiddoo" to logout.

Working...