Slashdot Mirror


Why Learning Assembly Language Is Still Good

nickirelan writes "Why Learning Assembly Language Is Still a Good Idea by Randall Hyde -- Randall Hyde makes his case for why learning assembly language is still relevant today. The key, says Randall, is to learn how to efficiently implement an application, and the best implementations are written by those who've mastered assembly language. Randall is the author of Write Great Code (from No Starch Press)."

206 of 667 comments (clear)

  1. Because you can kill any 2.6.x kernel by xiando · · Score: 3, Interesting

    Assembly is great because you can kill any linux system you got ssh access to using assembly.

    1. Re:Because you can kill any 2.6.x kernel by Nasarius · · Score: 2, Informative
      Interesting stuff. It's not clear whether it's the Gentoo patches or the move to 2.4.26 that fixes the bug, though. Hang on, I'll check...I run Gentoo, but always with a vanilla kernel.

      Yep, it kills 2.6.6.

      --
      LOAD "SIG",8,1
    2. Re:Because you can kill any 2.6.x kernel by ceswiedler · · Score: 4, Insightful

      From your link:

      "This bug is confirmed to be present when the code is compiled with GCC version 3.3 and 3.3.2 and used on Linux kernel versions 2.4.2x and 2.6.x. It has been tested to work on, and crash, several lame free-shell provider servers."

      If it affects all 2.4 and 2.6 linux kernels, I wouldn't call servers affected 'lame'. Especially free-shell provider servers. That's lame, testing a local exploit on a public shell server.

    3. Re:Because you can kill any 2.6.x kernel by 42forty-two42 · · Score: 2, Interesting

      Has anyone brought this to the attention of the lkml yet? I can't find it using google groups...

    4. Re:Because you can kill any 2.6.x kernel by xiando · · Score: 3, Insightful

      When I first stumbled upon this I had no idea how many system this actually works on: When I tested on my system, by chance of faith, nothing happened. I am using 2.4.26-rc3-gentoo. So I thought "no big deal". I now know my kernel seems to be the only version on this planet protected.

      I then asked people on irc channels if anyone were willing to test this before compiling other kernels myself and I instantly got replies like "Works, took down free-shell provider #ali on EFNet". People who tested on their own systems also confermed crashes. I'm not sure if I cut&paste the phrase "lame free-shell provider" from my irc window or if I actually did type this myself.

      I do not encourage hacking, doing so is bad whatever your target it.

      Btw, the "l33t howto" is meant to be funny, you know.. a joke.

    5. Re:Because you can kill any 2.6.x kernel by Anonymous Coward · · Score: 4, Funny

      Quiet! Here on /. we only talk about Windows exploits, and how insecure Windows is! We don't want anyone knowing that Linux has its own problems.

    6. Re:Because you can kill any 2.6.x kernel by RPoet · · Score: 2, Informative

      Yes, here.

      --
      "Oppression and harassment is a small price to pay to live in the land of the free." -- Montgomery Burns.
    7. Re:Because you can kill any 2.6.x kernel by EsbenMoseHansen · · Score: 2, Informative
      Misquoting is not nice. The actual quote was
      This exploit has been reported used to take down several "lame free-shell providers" servers (this is illegal in most parts of the world and strongly discouraged)
      Emphasized left as in the original.
      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    8. Re:Because you can kill any 2.6.x kernel by AndreyF · · Score: 2, Insightful

      Assembly is great because you can kill any linux system you got ssh access to using assembly.

      If only you had said "any Windows system", you would have gotten +5 insightful w/o a second thought.

  2. Debugging by Ann+Elk · · Score: 5, Insightful

    Another reason: Sooner or later, you'll need to debug something without a source-level debugger. Knowing how to debug raw assembly language has saved my ass many times.

    1. Re:Debugging by dduardo · · Score: 4, Funny

      Microsoft not giving their employees access to the Window's source code eh?

    2. Re:Debugging by Tony-A · · Score: 5, Interesting

      Absolutely.

      Disclaimer: I learned to debug before I learned to code.
      With extremely few exceptions, machine code performs exactly as advertised. When things are not exactly as they should be, it helps to be able to see exactly what is going on.

      Performance is much more a matter of structure (exponential complexity) than language (poor linear complexity). As to level, "high level" languages limit you to their implementation of a few concepts. Depending on where the heavy lifting is, Perl could easily outperform optimized C.

    3. Re:Debugging by Ninwa · · Score: 4, Insightful

      No, you can't exactly debug a fubar memory stack with just printf. Maybe in your hello world program, but not when things get complicated. :) Trust me, I know. I'm writing a rather large network application at the moment and somewhere along the line I must've overshot an array, but one mistake can ruin a whole application, and printf'ing wont help you.

      Learning how to debug is just as precious to a programmer as learning how to code.

    4. Re:Debugging by eidechse · · Score: 2, Insightful

      Damn straight.

      Especially if you're trying to slay one of those infernal "only shows up in a release build" bugs.

    5. Re:Debugging by Profane+MuthaFucka · · Score: 2, Informative

      http://www.datatek.net/Humor/Mel,%20the%20Programm er

      Or, just Google for Mel the Programmer and hit I'm feeling lucky.

      --
      Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!
    6. Re:Debugging by addaon · · Score: 3, Insightful

      Please explain how printf will let you debug the following (more than just a binary chop):

      1) A race condition.
      2) A deadlock.
      3) A performance anomaly in I/O bound code.
      4) A stack-smasher.
      5) Heap corruption.
      6) The, uh, printf family of functions.

      --

      I've had this sig for three days.
    7. Re:Debugging by Percy_Blakeney · · Score: 5, Insightful
      Depending on where the heavy lifting is, Perl could easily outperform optimized C.

      But if Perl is written in C, wouldn't that mean that Perl can never be "faster" than C?

      To put it more concretely, couldn't I just write a program in C that does EXACTLY what the Perl program does, down to the last data structure? And if I did, wouldn't that mean that Perl can't ever (theoretically) be faster than C?

      You could even take it a step further. You could write an exact duplicate of the Perl program, leave out the parts of the Perl interpreter that you don't use, and you probably would end up with an overall faster program. Thus, in most cases, C could trump Perl.

    8. Re:Debugging by adamruck · · Score: 2, Informative

      in a word... no

      I can write two programs to do the same thing... one that takes a second one that takes a year. Both written in C of course. If optimized C takes a year and perl takes a second... there ya go... counterexample.

      Of course I would have to see it to believe it.

      --
      Selling software wont make you money, selling a service will.
    9. Re:Debugging by globalar · · Score: 4, Insightful

      Your point is taken. However time is the most valuable resource of the programmer. A tool which can provide the fastest solution in both development and execution can be an attractive option. Computer resources are meant to be spent, but a programmer's should be invested.

      As tools have matured, I think we can see that the emphasis on time has only increased. Reusability and abstraction for more reliable interfacing are important OOP goals. Standard and broad libraries, IDE's, gc, etc. are all geared towards saving someone time. There are less obvious perspectives to this paradigm as well - low, economical maintenaince and error-free code, for example.

      I think a lot of programmers have gotten into the habit of sacrificing time for performance, and vice versa. In some form, this will always be true. However it is an asset of the programmer to have the choice of exactly what component of his project he should spend the most time on. Hopefully, this is the design.

    10. Re:Debugging by damiam · · Score: 2, Informative

      Huh? When you write a Perl program, it's run by an interpreter, which is written in C. Your argument would make sense if assembly was an interpreted language, which it's not (Bochs, VPC, and JVMs excepted).

      --
      It's hard to be religious when certain people are never incinerated by bolts of lightning.
    11. Re:Debugging by damiam · · Score: 4, Insightful

      The parent's point was that if Perl takes a second, then perfectly-optimized C cannot take more than a second, because the Perl interpreter is written in C. That said, it's a fairly moot point, because you could probably have written 500 Perl programs in the time it takes to optimize that one C prog.

      --
      It's hard to be religious when certain people are never incinerated by bolts of lightning.
    12. Re:Debugging by Tony-A · · Score: 2, Insightful

      To put it more concretely, couldn't I just write a program in C that does EXACTLY what the Perl program does, down to the last data structure?

      Oh yes. Furthermore, if you can analyse what is doing the heavy lifting and somehow, anyhow, gain an advantage, you can make a program which is overall faster, but everywhere except the heavy lifting, is significantly slower.

      You could even take it a step further. You could write an exact duplicate of the Perl program, leave out the parts of the Perl interpreter that you don't use

      Now you reach the turf where the hackers and home-grown systems have an unfair advantage. About three significant problems that you don't have to worry about is sufficient for poor talent to triumph. Downsides are that you wind up with archaic systems that no one dares touch and circumstances can change so that the non-problems now become problems.

    13. Re:Debugging by cowbutt · · Score: 4, Interesting
      Tell me about it; I once had a C program that segfaulted without the debugging printf()s but ran perfectly with them.

      Turns out I was overruning an array, and the static strings for the debug printf()s gave my process just enough space that it stopped trying to trash another process' memory (just its own).

      Luckily, as a former assembly language programmer, from the mere change in behaviour, I had an inkling of what was going on...

      --

    14. Re:Debugging by gnu-generation-one · · Score: 4, Insightful

      "No, you can't exactly debug a fubar memory stack with just printf. Maybe in your hello world program, but not when things get complicated. :) Trust me, I know. I'm writing a rather large network application at the moment and somewhere along the line I must've overshot an array, but one mistake can ruin a whole application, and printf'ing wont help you."

      Okay, I'm also writing a large network application, and I find printf statements very helpful indeed. It's Windows, so my main debugging tools tend to be message-boxes and fprintf to files. Even though there's a good "debugger" available, it's quite often at too low a level to see what's actually happening in the program.

      One problem is running multi-process, multi-threaded code on several computers at once. Sure, debuggers can be made to work that way if you install Visual Studio on each machine you're testing on, but it can be inconvenient to say the least.

      With print statements, your program can alert you in real time, using all the functions available in code but not in a debugger, and doesn't need to be carefully compiled as debug with the appropriate modules running in a debugger with the right break-points set. Just add a message box, and your program will tell you what it's doing.

      Debuggers are great for examining memory structures, or for when you really don't know what the hell your program is doing, but for most purposes a few well-placed print statements and a logical series of tests can help you find the problem.

    15. Re:Debugging by griann · · Score: 2, Insightful
      In general, I agree. However, in practical terms I am moved to contextualise the question from one of "couldn't a C implementation of the same function outperform an equivalent Perl function under all conceivable circumstances?" to "could a C function written by me outperform an equivalent Perl function as written by Larry Wall?"

      This is the rub, as it were. And, I believe the core of the article's message.

      It is not merely an issue of what level language the implementation is written in but the ability and skill of the programmer based on their underlying knowledge and ability with the medium.

      Optimising C code or Perl can be done until the cows come home, but in each case it will depend on the efficiency and power of the compiler or interpreter that it depends on to render it into something the machine can understand.

      In human languages it is similar to reading a foreign text based on our own fluency with that language or reading it via babelfish. Any given processor only knows its own language. It relies on how good babelfish is at converting what we write.

      An ability to write in assembler puts us much closer to the needs of the target audience. In this case, the processor.

      Even if we then choose to write in a higher level language, we will, at least, be able to "massage" the function to the processor's requirements where that is possible in our chosen language.

      Code optimisation will be based on making things as efficient for the thing actually doing the work, in this case the processor, rather than making things easier for us. This requires us to have an understanding of what it is doing and writing to that objective and end.

    16. Re:Debugging by Ann+Elk · · Score: 4, Insightful

      Just because you have access to source code does not mean you can do source-level debugging. Under Windows at least, the target binary must be built correctly, the correct symbols must be available, the source used to actually build the target must be available, etc.

      While I was at Microsoft, most of my debugging was done using the console-based debuggers: i386kd/alphakd/etc for kernel-mode, and cdb/ntsd for user-mode. For many years, these debuggers were incapable of any form of source-level debugging, so we did without.

      Knowing how to read disassembled code in the debugger and match it up with source code is a vital skill, far more important than the ability to write assembly language from scratch.

    17. Re:Debugging by Erik+Hensema · · Score: 2, Insightful

      And that's exactly why assembly is mostly irrelevant (with a few exceptions, of course).

      Assembly is faster than C only if you have a lot of time to spare. And C is faster than [your favorite higher lever language here] only if you have lots and lots of time to spare.

      The problem is: there is no REALLY good high level language for generic application development (things like word processors, web browsers, etc). However, a language like C# could become such a thing.

      I think that in a few years time only the time critical parts of an application are written in C and the hardware dependant parts are written in assembly. For all the rest there is [insert future high level language here].

      --

      This is your sig. There are thousands more, but this one is yours.

    18. Re:Debugging by johnnyb · · Score: 2, Interesting

      Perl isn't faster than C, Perl is faster than _you_ writing C (no offsense to you personally, I mean you in the generic).

    19. Re:Debugging by gnu-generation-one · · Score: 2, Interesting

      "Do you mean coordinating multiple distributed debuggers, or installing devenv in various places? Coordination can definitely be a pain, but there's no need to install devenv all over the place - just use ntsd."

      To debug a piece of code on your development machine, just press F5 to start the program, run to a breakpoint, step through, etc.. And if you have a program that consists of 10 .exe files, then you usually have to run 9 of them normally and one in the debugger. Still not that much of a problem, and you can run more than one process in a debugger if you don't mind it being a bit more complicated to synchronise.

      If you've got a feature that you can only test by having the code running on 4 machines talking to each other, then it becomes that much more difficult to use debuggers without really confusing yourself.

      However, if a program crashes in a function, you can just put a MessageBox() after each block of code, compile it, and run it normally. The last messagebox displayed tells you where the crash is, and you can then narrow your search. It's very useful for finding crashes (which in Windows are normally null pointers).

      For debugging networking-type code you can dump "events" (i.e. logging, which we probably should do even when not debugging) into a file. This is useful when there're lots of threads or processes communicating, and you want to know who sent what, and who received it. "Thread x on computer y received message z" and you can get all the messages in order. fprintf can also handle loads of different data types quite easily, so you can send strings to the file without having to allocate new memory to create a debug message in.

      I still find the visual studio debugger quite good for looking at linked-lists and stuff, but it seems to get overwhelmed quite easily when you've got more than one program running at once.

    20. Re:Debugging by prisonernumber7 · · Score: 3, Informative

      This is called a heisenbug, in case you are wondering. They occur mostly due to a smashed stack and are indeed damn hard to track.

      You can of course use assembly to track the bug, but I myself find that tedious. If you are programming in plain C (and not C++), you can use lint, a tool that evaluates sourcecode, very often. When lint reports no more possible problems you are done.

      If you happen to use C++ you'll probably have to shell out big bucks for a linter or be out of luck because there are only commercial linters available.

      Tho, that's why I always have a Linux system with valgrind, which is amongst other things a memory debugging tool, available on it (unfortunately valgrind does not work on any of the BSDs). Valgrind will scream and give a stack backtrace when your program does something wrong - be it an off-by-one error, be it memory being read uninitialized or whaterver. A truly genial tool.

      --
      && aemula C. ab stirpe interiit
    21. Re:Debugging by Elladan · · Score: 2, Informative

      1) A race condition.

      Debuggers are useless for this, since they permute the execution order of a program. Only some hardware-level debuggers running on external machines are any use here.

      The normal way to find these is print statements and thinking.

      2) A deadlock.

      Debuggers are useful here. But you can debug a deadlock with print statements by putting a timeout in your lock primitives that dumps the call stack. That's useful if you don't have a debugger, for example if your software is deployed somewhere and you need to debug the production system.

      3) A performance anomaly in I/O bound code.

      Debuggers are essentially useless here. Since it's IO bound, you probably want to use logging and possibly some sort of profiler code if you don't think it's a network issue.

      4) A stack-smasher.

      Debuggers tend to be useless here since the stack gets shredded before the program trips an exception. You might be able to find some stack information with a lot of effort, but it's sketchy.

      Try logging instead - you'll hopefully be able to localize where the error comes from. At that point, maybe the debugger can help, but usually you can just look at the code and see the error.

      5) Heap corruption.

      Debuggers are mostly useless here. What you want to use is a heap debugging library. Usually writing your own is best, since you usually need to write your own hacks to only track the source of the problem if possible.

      6) The, uh, printf family of functions.

      Heh. write(2)

      I program for a living, and I hardly ever use a debugger. For that matter, I hardly ever *have* a debugger. I do recognize that this is somewhat unusual though - most programmers do more apps work, where debuggers are common.

      The ironic thing is, in systems level work, I really need to understand assembly. ;-)

    22. Re:Debugging by Nevyn · · Score: 2, Interesting
      Well, there is a really good high level language for application development: the problem is that there are few good programmers. The language, of course, is Lisp. Extensible, powerful and high-performance: what more could one ask for?

      Yeh, silly me, forgetting about all those lisp applications I'm running. xemacs is probably the only one, I personally run, and it's slow, ugly and has more than a few annoying bugs (mainly with the UI). In fact it's so bad I keep looking for ways to migrate from it, but keep whimping out.

      Fewer damned parentheses, I suppose:-)

      I actually like the parens, but I still don't write any real lisp apps. ... and have no intention of starting. Here's a free clue, I didn't learn python because I thought appending commas to the end of print statements was a great idea ... I learnt it because of pygtk. When there's a free (as in perl and python) lisp language that's useful for doing things in ... those things will start to be done in lisp (I had hopes for rep, but that turned out not to be ... again).

      --
      ustr: Managed string API with ave. 44% overhead over strdup(), for 0-20B
    23. Re:Debugging by cowbutt · · Score: 2, Interesting
      Jeez, you need to know assembly to tell that you have overrun your arrays in C? If that's the case, we'll never get rid of buffer overflows until we kill C and all it's siblings.

      BTW, it's not the case. Segfaulting was an easy clue, and what you needed to understand is how your program was allocating memory. People need to start managing their data or the language needs to start doing it for them.

      Whoah, less caffeine for this man! ;-)

      Seriously, I know, and knew back then, that the segfault indicated my process was overwriting someone else's memory. What I didn't know was whether it was a) a function in a library I was using, or b) my own code (which I seem to recall was something written recursively for added spice). If the latter, then I needed to know /where/ I was over-running an array, and peppering the source code with printf()s was no use (which was the original point of my post and its parent) as it made the program run "correctly".

      --

  3. Why it's still good... by WilliamsDA · · Score: 5, Interesting

    Also, don't forget, a good deal of programming is still done in assembly. Both in a job I've had coding stuff and in my current research (crypto), I did/do a lot of assembly programming. Yes, learning assembly will make a better programmer out of those who never will code assembly again, but for some people, assembly is a valuable and often-used skill

    1. Re:Why it's still good... by gfody · · Score: 4, Insightful

      I agree. It sucks that a lot of programmers think learning assembly is just something they should do some day to gain better insight.

      Personally I think the curriculum for coding should begin with asm, and the student should work his way up to the higher level languages.. c, pascal, and finally java or perl.

      Than it wouldn't be an afterthought that some things are actually easier to accomplish in asm (most things depending on your line of work). Not to mention the eventual nested nested nested loop that just needs to be optimized.. shouldn't be a roadblock for any programmer.

      --

      bite my glorious golden ass.
  4. Schools not teaching assembly anymore by csimpkins · · Score: 5, Interesting

    It's a shame that schools are phasing assembly classes out of their computer science curriculums. If anything, it makes for a great foundation on which to learn more modern languages while teaching students things about computers that they probably wouldn't take the time to learn otherwise.

    1. Re:Schools not teaching assembly anymore by thegrassyknowl · · Score: 5, Insightful

      I was fortunate enough to learn assembly on a few architectures. Admittedly all of them are microcontrollers (PIC, AVR, HC11), but it really does force you to understand how the machine is working.

      Some of the more serious asselbly languages still scare the hell out of me though; have you ever looked at the assembly for the TI C6x DSPs? It took me quite a while to come to terms with something simple, and the C compiler can better use the 8 parallel execution units better than I can...

      --
      I drink to make other people interesting!
    2. Re:Schools not teaching assembly anymore by dsheeks · · Score: 5, Interesting

      Knowing something about the low level hardware / machine instructions and what compilers do to translate high level languages definitely helps programmers make better programming decisions.

      Given the rise of byte code environments like Java and .NET and the sophisticated tools available for working with them, I would think schools would do well to teach a class programming at that level. While obviously not a true assembly language, something like Java byte code is a lower level look at how programs really work, and since Java is highly portable you wouldn't have to worry about what hardware the students used like you would with an actual assembly language course. I still think doing some work with assembly and getting some exposure to hardware architectures is best, but this might be a reasonable alternative.

    3. Re:Schools not teaching assembly anymore by DaveAtFraud · · Score: 4, Insightful

      I have to agree. I run into quite a few people looking for programming jobs who don't understand what the CPU has to do to execute their code. They do dumb things like multithread something that is CPU bound becuase they have no understanding of how what they write actually gets executed. Same thing with regard to data representation mistakes.

      I'm not saying that everyone has to become a proficient assembly level programmer but I think a lot of people would be a lot better HOL programmers if they understood something about assembly language. I wonder how many Windows buffer overflow exploits are simply the result of someone not understanding that just because you can't express it in a HOL doesn't mean you can't exploit it from assembly code.

      --
      They that can give up essential liberty to obtain a little temporary safety deserve neither safety nor liberty.
      Ben
    4. Re:Schools not teaching assembly anymore by Trigulus · · Score: 3, Interesting

      AHA! I found it! I had the name slightly wrong.
      http://www.polylith.com/~brendan/ClassicCo mputers/Tandy/uCptrTrain.html

      --
      If something exists that does not need a creator (god) then why must the cosmos need one?
    5. Re:Schools not teaching assembly anymore by dexterpexter · · Score: 4, Insightful

      I am assuming you said this to be funny, otherwise it is indeed a shame.

      ECE (especially those with a heavy electrical engineering lean) people deal with microprocessors. Motorola chips have special features that you can't access with most C compilers and thus it is necessary to know assembly.

      Also, until recently, finding a good C compiler wasn't cheap. Now, of course, there are free ones.

      Coming from an ECE program without a microprocessors class in which you apply Assembly will make you less competitive than the graduates coming from schools in which engineers are taught both practical assembly application, and high level languages.

      --

      *-*-*-*-*-*-*-*
      "We are Linux. Resistance is measured in Ohms."
    6. Re:Schools not teaching assembly anymore by etaylor · · Score: 2, Insightful

      I would agree with that. I looked at an introductory computer science class that used Java. The first few weeks involved basic programming concepts. Then they would spend a week or two on multithreading, a week on file I/O, a week on inheritance, and so on. No wonder some of the students ended up being a little fuzzy on basic concepts, like how a computer executes one instruction after another...

    7. Re:Schools not teaching assembly anymore by PaulBu · · Score: 4, Insightful

      They do dumb things like multithread something that is CPU bound...

      Not that I disagree with your point (actually I do agree with it alot! ;-) ), but, I'd guess, almost a half of the people thinking in multithreading terms in this world (definitely half the total IQ, not to offend anyone ;-) ) use it to solve CPU-bounded problems on SMP boxes/multithreaded CPUs (Tera SMT; Intel's Hyperthreading on massive (ASCI) scale, things like that...)

      When you just start throwing processors (or thread contexts) on the problem, you will find soon enough that any problem is I/O bound... ;-)

      Paul B.

    8. Re:Schools not teaching assembly anymore by Morganth · · Score: 2, Insightful

      They teach assembler in my school's CS program second year. The whole class is basically 8086 assembler and then the end of the class gets into more advanced assembler coding (like AT&T style and NASM). The class ended with an overview of Jasmin, which is basically a Java assembler... the purpose being to understand how the JVM works and to code directly for it. At the time I thought this was strange, but considering the only "Programming Language" courses my CS program has are in Java, this actually made sense. (Note: other classes expect a lot of programming, but expect that you already know C/C++/Java/whatever.) This teaches the graduates here who aren't thinking about it already to be wary of what kind of code is being executed by the JVM.

      I do think this is important, and am spending a lot of time on my own to learn as much as I can assembler/C-wise, since I know jobs I get here and there (like my summer job) will require high-level languages (Java, C#) and I don't want to lose that low-level knowledge.

      It's actually harder for us (the younger generation), because there have been so many abstractions that you really have to be on top of things to understand what's going on at the machine level. At this point, programs tend to go from source to bytecode to being executed on the physical machine, and in order to optimize programs you have to know what's going on at every step. That and you have to have a lot of discipline to learn the low level stuff, since the high level stuff can make you so productive without even thinking about it or putting in any effort. But this discipline ultimately makes you a better high-level programmer too, so it's worth it regardless...

    9. Re:Schools not teaching assembly anymore by johnnyb · · Score: 4, Interesting

      I agree. In fact, that's one of the things that motivated me to write my book (see my sig). That, and the fact that TAOCP needed a prequel.

    10. Re:Schools not teaching assembly anymore by plover · · Score: 2, Insightful
      Because in many (most?) fields of employment, COBOL is far more widely used than ASM.

      Retail, banking, most all of the big financial companies all have decades of legacy COBOL programs hanging around that need maintenance and upgrades. It's not uncommon for a Fortune 500 company to have several hundred programmers writing in COBOL, but have fewer than a dozen programmers capable of writing in assembler. Of those, perhaps one or two is fluent enough to maintain an ancient BAL (Basic Assembly Language) program.

      There are many more jobs for COBOL speakers than there are for BAL speakers. A community college's primary focus is very different from that of a research university. They are there to teach skills that will make its students employable. A COBOL coder can get a job. A BAL coder can get in the unemployment line behind the IBMer with 20 years BAL experience.

      --
      John
    11. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 2, Insightful

      > They do dumb things like multithread something that is CPU bound becuase they have no understanding of how what they write actually gets executed.

      Erm, if you want interactive response out of a CPU-bound application, multithreading is exactly what you want to do. Timeslices are smooth, waiting til your computation finishes is jerky. You want snappy interaction if it's user input driving the calculation in the first place.

    12. Re:Schools not teaching assembly anymore by trisweb · · Score: 2, Informative

      I find the opposite is true... in fact, a class on machine structures is required at Berkeley, and our professor is very enthusiastic about teaching assembly. In fact, he probably got most of the points in this article out over the semester. So, "No one really needs to know this stuff, and you'll never use it, but it is required by this program so we've got to struggle through the next several weeks studying this material." was not what I experienced at all. We were thouroughly taught how a processor runs our code, how the processor itself works, how to optimize machine code, etc etc. Great class.

      --
      "!"
    13. Re:Schools not teaching assembly anymore by Derkec · · Score: 2, Insightful

      I'm a recent grad (2 years out of CU-Boulder) and we still had a course in assembly programming for the 8086. This was part of a series of courses that we called Digital 1,2,3 or the love your fellow engineer courses.

      They put CS, ECE and EE students together and grouped us up for the first two courses - assembly programming was the first. Wiring chips together and programming FPGLAs was the second. The capstone was a general "how computers work from top to bottom" course that discussed processor design and had us writing some MIPs assembly. Anyway, it was a miserable series of classes to actually take, but verry useful and great in getting engineers from slightly different disciplines to practice working together. The CS guys tended to really help a group in assembly programming while the other guys tended to be more competent when wiring things together.

      I really feel that the time I took understanding computer achitecture is a bit more useful that the time I spent learning assembly - although to a certain extent learning assembly forces you to learn the archeticture. Keeping in mind that with a relatively small set of data, all the work will be done on the CPU at blazingly fast speeds, while a single fetch out to the disk changes the times you're messing in by orders of maginitude.

      Being able to read assembly is good for debugging but I'm not convinced it is required to write great code. Pure blazing speed is important for some applications, but for many it just isn't. The guy in the article mentions word processors and how they aren't 16,000 times faster than they used to be. Frankly, I'm not sure how you'd measure. I know the Macs I used in high school were slow enough that a fast typer could outpace their ability to render new characters, but my current word processor puts up characters quickly enough. It also checks my spelling and grammar on the fly and unlike old word processors it's more or less WUSISYG and not markup. The only slow part is launch time. That's more a process of big code requiring disk access to be loaded rather than slow code.

      For me, good code is the following: 1. It gets the jobs done. 2. It's very readable. 3. It's designed in such a way that I can change it without destroying the system :) 4. It's efficient. Now, if the code requires next year's processor to work in a reasonable way, it fails at #1. If it's job is to RIP MP3s, it's job is to be fast.

      For most applications though, the easiest algorith to read is the best one to use. That said, I agree with the author that it's best to know when you are writing code that is inefficient. It should make you wince.

      I winced a lot when writing a mock-up of simple app that ran against the contact database of my customer. However, despite each request looking through every record in 2 tables I worked worked with instead of using some sensible SQL, it ran effectively instaneously on an average machine. So would I look at that level of ineffiency as aweful code? Probably. Should I? I'm not so sure.

    14. Re:Schools not teaching assembly anymore by the_duke_of_hazzard · · Score: 2, Insightful
      I think it's more that it empowers you to think of a computer in the right way. It shows you that everything is built on top of very simple commands, and Java (the default language of choice for many mediocre Comp Sci courses), for example, is nothing special.

      I interview people for jobs all the time, and you can tell right off who are the ones who've been taught a language as a tool (VB'ers), and who visualises a computer from the ground up. They think around problems and beyond the API.

  5. don't bother........ by Anonymous Coward · · Score: 5, Insightful

    Hate to say, but the kind of optimization you learn about by knowing assembly language is just not necessary for most programmers these days.

    I learned programming in the 80's, and I did learn assembly language, starting with 6502 assembly. I would subconciously code my C so that it would produce faster code. Every block of code I wrote would be optimized as much as practical. My code was fast and confusing.

    When coding Perl or Java I would keep in mind the details of the underlying virtual machine so I could avoid wasteful string concatenation or whatever. I cache things whenever possible, use temp variables all the time, etc., etc.

    I've spent the last few years trying to UNLEARN this useless habit. There is just no need. And in highly dynamic languages like Ruby, it's pointless. You can't predict where the bottlenecks will show up.. almost every project I've worked on has either had no performance problems, or had a couple major performance problems that were solved by profiling and correcting a bad algorithm.

    Stuff like XP and agile development have it right: code as simply as possible, don't code for performance, then when you need performance you can drill down and figure out how to do it.

    To me a beautiful piece of code is one that is so simple it does exactly what it needs, and nothing more, and it reads like pseudo-code. Minimalism is the name of the game.

    So my advice is, don't learn assembly language. Learn Lisp or another abstract language. Think in terms of functions and algorithms, not registers and page faults. Learn to program minimally.

    On another note, the tab in my Konqueror for this article reads: "Slashdot | Why Learning Ass...". Heh. :-)

    1. Re:don't bother........ by reallocate · · Score: 4, Insightful

      Why does use of assembly preclude thinking in terms of functions and algorithms? Algorithms are the essence of programminmg; registers, syntax, etc, are just tools to implement algorithms.

      --
      -- Slashdot: When Public Access TV Says "No"
    2. Re:don't bother........ by MBCook · · Score: 5, Insightful
      I disagree.

      I have seen FAR FAR too many students in my various college programing classes who think nothing of calling functions with 15 parameters and copies of large datastructures (not references) and other such things. I really think that assembly should be one of the FIRST things taught to future programmers. So many people I've run up against don't have any idea how computers work. Sure things are "mentioned" in classes, but so much is lost on them. Somthing as simple as "passing 2 things is much MUCH faster/easier than passing 10" don't get taught.

      By passing 10 things, their job is easy. That's all they see. They don't know about registers (other than they exist and are sorta like variables on the CPU). So they don't know that to pass 10 things you might put some in registers but the rest will have to be passed in memory (which is slow) as opposed to puting everything in registers (if at all possible) which is faster (especially for simple functions).

      The only problem with assembly is the catch-22 mentioned in the article: you have to do all sorts of "magic" to print out to the screen or read from the keyboard, which can be confusing. And it takes a while to get them up to the point where they can start to understand that magic. My school teaches assembly (sorta) on little 68HC12 development boards that have built in callable routines that perform things equivelent to printf and such, so there is little voodoo involved which is nice.

      I'm not saying assembly is neccessary, but I DEFINATLY think it's important for programers to learn how things work under the compiler. I have seen FAR too many hideous bits of code that no one who understood the underpinnings of assembly would never dream of.

      --
      Comment forecast: Bits of genius surrounded by a sea of mediocrity.
    3. Re:don't bother........ by Smidge204 · · Score: 5, Insightful

      So basically you don't have time to do it right, but you might have time to do it twice?

      Learning assembly isn't all about optimization, either. Being familiar with how the machine works right down to the core will make you a better programmer, peroid. Personally speaking, it also helps develop that zen like ability to "think like the computer", and that helps you program not just more efficiently but more effectively since you can think things out better. You can't tell me you're not a better programmer for having been exposed to it... it simply changes the way you think about the machine.

      It can also be argued that "beautiful" code has no bearing on performance. It's also the kind of "Oh performance isn't an issue anymore" and "make te source code pretty" thinking that we now need gigahert+ machines with 128MB RAM just to write a goddamn letter... it's really quite sad that so many programmers just let their applications fill the hardware vacuum they think their users will have, or should have, just because they didn't take an extra day to think about what they're doing and write their code a little more efficiently.
      =Smidge=

    4. Re:don't bother........ by dsheeks · · Score: 2, Insightful

      Dead on. There are probably lots of people that learned something about assembly language and saw it as just a bunch of linear instructions. Good modular programming can be done at more than one level. Good, easy to understand design is critical, but performance can be critical in many situations. Besides, the point isn't to know something about assembly so you can make EVERY decision based on optimization, but so you can make the necessary optimization decisions in an informed way.

    5. Re:don't bother........ by Tony-A · · Score: 4, Insightful

      To me a beautiful piece of code is one that is so simple it does exactly what it needs, and nothing more, and it reads like pseudo-code. Minimalism is the name of the game.

      From an old fart who likes assembly language, total agreement.
      Assuming the primary goal is performance, the blunt reality is that about 90% of the code is irrelevant as to impacting that performance. Any screweys in that code, particularly trying to "improve" performance, will have indirect deletorious effects on that performance.

    6. Re:don't bother........ by Dark+Nexus · · Score: 2, Informative

      You forget one thing. You're only talking about programming for a PC. Pretty narrow view.

      Considering that imbedded processors, where every single bit of performance is important, outnumber PCs by a LARGE margin it's still applicable.

      Sure, most of the code for them would be done in C as well, those habits you gained out of assembly would come in handy.

      --
      Dark Nexus
      "Sanity is calming, but madness is more interesting."
    7. Re:don't bother........ by edhall · · Score: 4, Insightful

      Use of assembly doesn't preclude thinking in terms of functions and algorithms. Like nearly any form of programming, it pretty much requires such thought -- in abundance. But given that I have a limited amount of attention to spend on each line of code, focusing on registers, branches, instruction sets and memory layout takes away from time better spent on clarity, modularity, and algorithmic sophistication.

      It's much easier to take code written for clarity and correctness and make it fast, than take code written for speed and make it clear and correct. That's what profilers and coverage tools are for. Once you've measured, code your inner loops and bit-fiddling in assembler if you must, but only after your program is working and well-tested.

      -Ed
    8. Re:don't bother........ by Entrope · · Score: 3, Insightful
      I have seen FAR too many hideous bits of code that no one who understood the underpinnings of assembly would never dream of.

      I have seen FAR too many hideous bits of code due to people not knowing appropriate data structures. I have seen FAR too many hideous bits of code just because people didn't know what clean code looks like (or didn't know why it helps maintenance).

      Sure, you can save some time by passing fewer arguments on the stack. You generally will not save much time that way; if somebody passes 15 arguments to a function, it is usually because they do something with most of them, and that bounds the potential speedup. But you can often save mountains of execution time by using a better algorithm. You can also save mountains of developer time by trying to write clear, concise code in the first place.

      Knowing how the CPU works is just one facet of competent programming, and is important to remember; but too many people focus on just one facet and ignore the others.

    9. Re:don't bother........ by nerdsv650 · · Score: 2, Informative

      Don't bother, my a**. This is the idiotic notion that has yielded Windows and all it's associated bloatware. If you don't understand your machine, will you think to pad structures to cache line boundaries? Will you know to declare variables with stricter alignment restrictions before those with more relaxed restrictions? True, this may not always be portable from one architecture to the next, but the reality is that you'll at least know enough to locate the macros that yield the cache-line size and use them for structures that are likely to end up in arrays. Code written by someone with a strong assembly language background is less likely to fragment the heap since they'll likely combine small allocations or endeavor to allocate equal size data items. I could go on, and on, and on, but those who believe already do, those who don't are plain lazy. IMO, of course.

      -michael

    10. Re:don't bother........ by PaulBu · · Score: 2, Insightful

      Well, this is the second part of the equation... To my mind the premise of the original article was not exactly that everyone should code in assembly (and reading "assembly language" three times in one 4-line paragraph was driving me crasy, he should've used ASM or something ;-) ), but that one should LEARN different things...

      To my mind, any programmer (I would not refer to the ivory towers of CS here ;-) ) should more or less know both LISP and assembly, the latter one for the reasons discussed in the arcticle, the former one if only because it kind of relates to what can be computed AT ALL, _not_ how efficiently it can be done. (see, for example, chapter three )I guess) of today's story about \Omega ;-) ).

      Paul B.

    11. Re:don't bother........ by Brandybuck · · Score: 3, Insightful

      too many people focus on just one facet and ignore the others.

      That is exactly the point! Programming in assembly is another of these facets, and just as important as all the others. Instead of shouting at each other, maybe you should recognize that you're both right!

      --
      Don't blame me, I didn't vote for either of them!
    12. Re:don't bother........ by oconnorcjo · · Score: 4, Insightful
      By passing 10 things, their job is easy. That's all they see. They don't know about registers (other than they exist and are sorta like variables on the CPU). So they don't know that to pass 10 things you might put some in registers but the rest will have to be passed in memory (which is slow) as opposed to puting everything in registers (if at all possible) which is faster (especially for simple functions).

      SO WHAT! Programs should only be optimized if:

      1) the program is doing stuff so intensive that it runs slow
      or
      2) It is being run all the time in the background by the system and can slow down the system as a whole.

      98% of the time it just does not matter.

      Easilly readable code is FAR MORE IMPORTANT.

      I have written code in more than half a dozen different languages but my favorite language these days is Python. It runs ten times slower than C, but in most cases, it just doesn't matter. Most of the time, the code feels instantanious.

      --
      I miss the Karma Whores.
    13. Re:don't bother........ by johnnyb · · Score: 3, Informative

      You need to know the low-level stuff for a few reasons:

      1) You are a programmer, and knowing how the computer functions is your job

      2) Many of the high-level constructs are better understood when you know what it is they are trying to abstract. It will also keep you from doing stupid things like making everything in java a BigNum or whatever that is.

      3) The idea of references and pointers are a lot more fuzzy for programmers who never learned assembly language. The difference between a pointer and a value is harder to grasp.

      4) Debugging is a lot easier when you know assembly language, because you know how the parts fit together. You understand what a calling convention is, you understand how memory mapping works, you understand how the stack works - you just can see the whole picture of how the machine is processing your data.

      There's even some optimizations that you can do still in higher-level languages that you get from knowing assembly language. For example, in C, the first member of a struct is accessed faster because the compiler can just do straight indirect addressing rather than base pointer addressing. It might also convince you to rewrite your loops so they have a better chance of fitting entirely into the instruction cache. But even without these things, knowing assembly language is useful for the four reasons I outlined above. It's also useful for people who are having trouble learning to code, because it forces them to think on a much more exacting, step-by-step, concrete level.

    14. Re:don't bother........ by Jeremi · · Score: 2, Insightful
      Easily readable code is FAR MORE IMPORTANT.


      Agreed -- but I would argue that if you are making lots of function calls that take 10 arguments each, your code isn't very readable either. In most cases like that, the thing to do is create a class that contains all the parameters and just pass in a reference to an object of that class. Then your code is both efficient AND easy to understand.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    15. Re:don't bother........ by Methuseus · · Score: 2, Informative

      And your point has nothing to do with assembly in particular. You are basically saying to use object oriented programming practices. This is not something that assembly will teach you better than any other programming language.

      --
      Two things are infinite: the universe and human stupidity, though I'm not yet sure about the universe. - A Einstein
    16. Re:don't bother........ by Elladan · · Score: 5, Insightful
      While the general idea you're expressing - that people should understand how computers work to program them - is a good one, I think you're missing the point to a large degree.

      The things that are most important in performance are, generally speaking, algorithms. It's important to understand things like:
      • Cache - the computer operates faster on small working sets.
      • Algorithm efficiency - O(nlogn) is better than O(n^2) for most problems.
      • Latency - network or disk round trips are bad.

      Etc. The sort of thing you're proposing, with stuff like function call arguments, loop conditionals, etc. are micro-optimizations, and are very seldom worthwhile for programmers. Micro-optimizations are almost always best left to the compiler writers, who can, in effect, program them once and let everyone reap the benefits.

      Consider your example in particular: A function with 2 arguments instead of 10 isn't really faster. First off, it's only slower on an x86 - many architectures have these things called registers, which you can use for things like function arguments. Second, those function arguments are spilled to the stack just before the function call jump. This means they're extremely hot in the D$, and will hardly even be any more expensive than a register to reload at all. Third, if you break the big function into a lot of little ones, you're incurring more call overhead and more pressure on the I$. Fourth, breaking the function up causes multiple copies of the function prologues and epilogues, which will easily overwhelm the register spilling cost. Etc. etc. etc.

      In other words, those 10 arguments are only microscopically slower, and may even be faster!

      In this case, the student should avoid writing a function with 10 arguments if it makes the code clearer. The value of this sort of incredibly trivial micro-optimization is fundamentally dwarfed by the value of readable code - if the student can read her code, that means she'll have fewer bugs and can spend more time optimizing it. And that's what'll really make the program faster.

      You should only consider worrying about optimizations at this level if you've already optimized your program at an algorithm level fully, have profiled it, and determined some particular pieces are extremely dense hot-spots that need to be improved by hand. But if you're doing that, you may want to consider recoding the hot-spots in assembly anyway.

      These days, these sorts of hot spots tend to be media codecs, and the way to speed those up is to use SIMD instructions - which can only be used properly from asm. So even before worrying about these sorts of extremely tight micro-optimizations, you'd want to recode in assembly just to use the special vector instructions! And in asm, readability is even harder to obtain, so you'll probably avoid a lot of the sort of micro-optimizations a crazy compiler will do just so you can make sure the code works right.
    17. Re:don't bother........ by DrSchlock · · Score: 5, Funny
      I have a favorite fortune on my system...

      The First Rule of Program Optimization:
      Don't do it.

      The Second Rule of Program Optimization (for experts only!):
      Don't do it yet.
  6. Best, efficient or cheap by jimmy+page · · Score: 4, Insightful

    Come on - all that may be great, but what really matters is what gives the most bang(features) for the buck (cheapest)... and in the minds of the average CEO with 10 billion options this is done by outsourcing to the lowest cost provider (India, China, etc..) regardless of code training, language etc..

    1. Re:Best, efficient or cheap by Anml4ixoye · · Score: 2, Interesting
      in the minds of the average CEO

      Right. Because after reading that article, I thought, "Boy, if *I* was a CEO, this is how my guys would program everything." Actually, he says in there that writing everything in Assembly is not for every project.

      So what's great about it is that if someone is looking to make a step to become a better programmer, this would be a good direction to check out so that you truly understand your code. If you are happy being a VB code jockey (or any code jockey for that matter) then rejoice! and don't take the time to learn Assembly.

  7. Smaller code? We can hope... by dinodrac · · Score: 4, Insightful

    Unfortunatly, I doubt that we are going to see many people switching to assembly language, but we can hope. I'd love to see a return to applications that were under 100K

    Misuse of high level languages such as visual basic, as well as off the shelf components for everything, has led to a level of code bloat in todays applications that is inexcusable.

    (note: off the shelf components and high level languages aren't inherently bad, just not always suitable for commercial applications.)

    Also, given that modern optimizing C compilers can often optimize better than humans, it may make sense to embed critical sections of assembly into C code, and let the compiler optimize the rest...

    Also, whatever happened to profiling? Has this become a lost art among developers? Time your code. See where it bogs down. Find the fat. Cut it out. Please.

    --
    This post brought to you by Save the CPU Cycles!

    1. Re:Smaller code? We can hope... by Jeffrey+Baker · · Score: 5, Funny

      Fuck, I'd settle for viruses smaller than 400K! Of all things, you'd expect a virus to be lean and mean, but I guess the latest crops were made with Visual Virus .NET or something to that effect.

    2. Re:Smaller code? We can hope... by mikael · · Score: 2, Insightful

      Also, given that modern optimizing C compilers can often optimize better than humans, it may make sense to embed critical sections of assembly into C code, and let the compiler optimize the rest...

      In the past, I used to do a lot of assembly language programming, but would always end up being burnt by having to completely rewrite everything for a new CPU/graphics card. It's much more productive to write a generic algorithm in C/C++ and use the assembly output to identify where the optimisations can be made. In nearly all cases, I could restructure the C code to match the optimum assembler output.

      --
      Vintage computer adverts: http://www.vintageadbrowser.com/computers-and-software-ads
    3. Re:Smaller code? We can hope... by Just+Some+Guy · · Score: 5, Insightful
      Misuse of high level languages such as visual basic, as well as off the shelf components for everything, has led to a level of code bloat in todays applications that is inexcusable.

      You, sir, are insane. Much of my job involves pushing around regular expressions and hash tables (aka associative arrays aka dictionaries). I know several flavors of assembler on distinct hardware platforms (x86, 68k, 6502, MIPS) so I say this out of experience rather than fear of the unknown: I'd rather swallow my own tongue than write anything non-trivial in a low-level language.

      Seriously, a lot of people who know what they're doing have provided a huge library of functionality for me to pick and choose from. If I need to write a GUI app, I'll do it in Python with GTK or QT bindings. I am competent to build it in assembler, but why? It wouldn't be portable, it'd shave a very small amount of size from the end product (most of the project's resources are likely to be spent in the GUI libraries and not the core of the program), and would take 20 times longer than necessary.

      There are a very few areas where low-level languages make sense. I haven't touched any of them in years.

      --
      Dewey, what part of this looks like authorities should be involved?
    4. Re:Smaller code? We can hope... by mindstrm · · Score: 2, Insightful

      Nobody is suggesting switching back to assembly... .just that programms should have some experience with it.

      It's also not about optimizing instructions.. to truly optimize on many modern processors requires years of study of that particular architecture in the first place.. that kind of task is best left to he compiler nowadays.

      The point is that by coding some stuff in assembly, you learn a lot more about how the machine really works, how the OS really interacts with the machine, and your code.

      Again, it's not about optimizing instructions but more about having a critical understanding of what is really going on.. taking out the magic.

      Understanding things like:

      How are arguments passed? By register, or by stack? Which is faster? Why?
      How are shared libraries handled? How does an interrupt affect things?
      What is a context-switch?

    5. Re:Smaller code? We can hope... by sosegumu · · Score: 2, Interesting

      I'd love to see a return to applications that were under 100K

      No kidding. I'm not a programmer, but this guy writes little helpful applications in assembly that are like 20K. In this day and age, I'm impressed when anyone writes anything that can just fit on one CD-ROM.

      --
      It's easier to wear the spandex than to do the crunches. --David Lee Roth
    6. Re:Smaller code? We can hope... by johnnyb · · Score: 2, Insightful

      "Unfortunatly, I doubt that we are going to see many people switching to assembly language, but we can hope."

      I don't think there's many people hoping for a complete return to assembly language. However, a return to _understanding_ assembly language and how a computer works underneath is what is needed. I wrote a book on assembly language for just that purpose. The code I write professionally is usually Perl, Python, PHP, or C. However, knowing assembly language makes me a much better coder in all of those languages.

      Anyway, see my sig for the book I wrote on this.

  8. Yes and no... by Daniel_Staal · · Score: 5, Insightful

    While I learned assembly, and found it useful for learning to understand exactly how the machines think, I'm not sure I agree with his basic premise. Namely, that great code (code that is well designed for it's job, and easy to work with and under) is always the efficient code, in machine terms.

    The machine thinks one way. A human thinks in another. Code that is well designed for easy updating, and extending, is code that is easy for a human to understand. If that is not the most efficient way for the machine to do it, that may be the price for 'great' code in this project. (The ideal balance depends on the project, of course. A kernel should be machine-efficient, for example.)

    --
    'Sensible' is a curse word.
  9. I disagree by nacturation · · Score: 5, Insightful

    Efficiency in terms of coding is a wonderful art and I think it's still applicable today. Kernel-level routines, games, drivers, etc. all benefit from tight coding in assembly language.

    But let's be honest here. Computer Science 101: an efficient algorithm coded in an inefficient way will always beat out an inefficient algorithm coded by hand in 100% optimized assembly. I'll put my crudely coded Javascript quicksort algorithm against your finely honed 100% assembly bubblesort algorithm any day. Not only will my algorithm beat the pants off of your algorithm, but I'll also code it in far less time and with way fewer debugging sessions than you would. Also, the higher-level language you go, the better it is for security. How easy is it to introduce things like buffer overflows, array out of bounds, etc. errors in assembly? How easy is it to do that in Java, C#, etc.?

    So yes, writing in assembly language is still good and has its places. But let's keep it to those places, shall we?

    --
    Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    1. Re:I disagree by bendelo · · Score: 3, Interesting

      I'll put my crudely coded Javascript quicksort algorithm against your finely honed 100% assembly bubblesort algorithm any day. Not only will my algorithm beat the pants off of your algorithm, but I'll also code it in far less time and with way fewer debugging sessions than you would.

      You're on. After my exams are over, I'll code a bubblesort algorithm in assembly language. I wonder how large the dataset will have to be before you win? Mail me.

    2. Re:I disagree by no+longer+myself · · Score: 2, Informative
      I'll put my crudely coded Javascript quicksort algorithm against your finely honed 100% assembly bubblesort algorithm any day.

      Depends on what you are sorting. Anyone will tell you that the quicksort algorithm works fastest when dealing with total randomness, but a properly designed bubblesort can quickly shake out a couple of minor swaps much faster than a quicksort.

    3. Re:I disagree by nacturation · · Score: 4, Interesting

      I wonder how large the dataset will have to be before you win?

      Yes, this really is the crux of it all and I left that out. I participated in a very interesting challenge to generate 10 unique random numbers in a scripting language. The goal was for minimal time. As it turns out, a simple array check of whether or not the number has been included worked the fastest due to the fact that you're generating only 10 numbers. As soon as it got up to 100 or more, the array approach O(n^2) broke down.

      So for a small dataset, I'll award you your prize already. :) For a large, random dataset I think I'd win out on that one. Check out this sorting algorithm demo page (uses Java applets). Looks like the Shear sort kicks ass over all of them.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    4. Re:I disagree by Jason1729 · · Score: 4, Funny

      I'll take that bet...but since you choose the algorithms, I choose the architectures, and I choose a base-line PIC microcontroller. It has a 2-level deep hardware stack, Let's see your recursive javascript code run on that.

      Jason
      ProfQuotes

    5. Re:I disagree by bendelo · · Score: 2, Interesting
      Okay, here's a quickly knocked up bit of assembler to Bubblesort byte-wise an the area of memory.

      0100 MOV BX,[0128]
      0104 MOV AH,[BX]
      0106 MOV DL,00
      0108 MOV AL,AH
      010A MOV AH,[BX+01]
      010D CMP AL,AH
      010F JLE 011A
      0111 MOV DL,01
      0113 XCHG AL,AH
      0115 MOV [BX],AL
      0117 MOV [BX+01],AH
      011A INC BX
      011B CMP BX,[012A]
      011F JL 0108
      0121 CMP DL,01
      0124 JZ 0100
      0126 INT 20
      To sort 3000 bytes of random data it takes 5.4 seconds on a P4 1.8Ghz while running in debug.exe under Win2K. That's 1.6 million comparisons (of AL to AH) per second. I wonder how long that would take on a Javascript quicksort implementation!
    6. Re:I disagree by nacturation · · Score: 2, Interesting
      Here's some hacked together javascript, qsort implementation ripped from the web. On a P4-M 1.4GHz notebook, it takes 581ms while running in Opera under Windows XP. Slashcode screws up the formatting somewhat... the "&amp ;nb sp;" part gets incorrectly inserted.
      function _pm_array_qsort(vec,lo,up,cmp_fun){
      var i, j, t;
      while(up > lo){
      i = lo;
      j = up;
      t = vec[lo];
      while(i < j){
      while(cmp_fun(vec[j],t) > 0)
      j -= 1;
      vec[i] = vec[j];
      while((i < j) && (cmp_fun(vec[i],t) <= 0))
      i++;
      vec[j] = vec[i];
      }
      vec[i] = t;
      if(i - lo < up - i){
      _pm_array_qsort(vec,lo,i-1,cmp_fun); lo = i+1;
      } else {
      _pm_array_qsort(vec,i+1,up,cmp_fun); up = i-1;
      }
      }
      }
      function _pm_array_defcmp(a,b){
      return (a == b) ? 0 : (a > b) ? 1 : -1;
      }
      function pm_array_qsort(vec,lo,hi,cmp_fun){
      if(vec == null){
      return;
      } else if(cmp_fun == null){
      _pm_array_qsort(vec,lo,hi,_pm_array_defcmp);
      &amp ;nb sp; } else {
      _pm_array_qsort(vec,lo,hi,cmp_fun);
      }
      }

      var x = new Array(3000);

      for (var i = 0; i < 3000; i++)
      {
      x[i] = Math.round(Math.random() * 255);
      // output initial array contents
      document.write(x[i] + " ");
      }

      var start = new Date();

      document.write("<p>Start: " + start.getSeconds() + ":" + start.getMilliseconds() + "</p>");

      pm_array_qsort(x, 0, 2999, _pm_array_defcmp);

      var end = new Date();

      document.write("<p>End: " + end.getSeconds() + ":" + end.getMilliseconds() + "</p>");

      for (var i = 0; i < 3000; i++)
      {
      // output final array contents
      document.write(x[i] + " ");
      }
      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    7. Re:I disagree by CharlesEGrant · · Score: 2, Interesting

      Knowing more is almost always better then knowing less, but I'm still going to try to disagree with you. The problem is that the breadth of computer science has grown so in the last 30 years that there is almost always a 'Guns vs Butter' choice to be made in the course of an education. The time I spent on exercises in assembly language was time I wasn't able to spend on algorithms for computational biology and visa versa.

      A few years ago I worked with a gentleman who had graduated from a trade school. He was a generally sharp programmer, but he really put me to shame in database design and SQL. He had completely internalized the relational model, and could write a query in five minutes that was an order of magnitude faster a query I'd taken an hour to come up with. On the other hand he had no idea how floating point numbers were represented in the computer (he assumed everything was BCD). In database design there are so many levels of abstraction between you and the hardware that
      understanding the CPU architecture is of very limited utility.

  10. It's like learning any language by mark-t · · Score: 2, Insightful

    Learning it is good, even if one never ends up actually seriously developing in it. It advances your ability to solve problems in a language independant fashion and equips you to be able to more rapidly model solutions to brand new problems, even in the languages that you may already know.

  11. Exposure useful, mastery not needed by Ars-Fartsica · · Score: 4, Insightful
    Developers smarter than you have spent decades building useful higher-level layers to speed up the development of complex code. You would be wise to leverage this incredible infrastructure for the 99.999% of projects that do not benefit from obsessively tweaking the finest details.

    Knowing what assembly is and how it works is beneficial. Mastery of assembly is completely pointless for anyone outside of OS kernel, compiler construcution and embedded development...which probably means you. Your time will be better spent figuring out how to make Java programs 10% faster most of the time.

  12. desire to teach someone 6502 assembly language by pomakis · · Score: 4, Insightful
    For some reason I have a strange desire to teach someone 6502 assembly language. I'm not sure why that is, and the rational side of me knows that I'm never going to find anybody who's even half-interested in learning it. I think that perhaps the reason I want to teach it to someone is that it'd be nice to experience someone else coming to the realization of the power of abstraction, the awareness that so much is possible using such simple building blocks. And yes, I strongly believe that knowing how to program in assembly language (and how it relates to the underlying machine language) makes one an instinctively better programmer. And it's frikkin' neat. It's like driving a standard versus an automatic. You become one with the computer.

    1. Re:desire to teach someone 6502 assembly language by Kainaw · · Score: 2, Interesting

      For some reason I have a strange desire to teach someone 6502 assembly language.

      Maybe you are simply a teacher. I'd say just do it. I avoided college for 10 years because I simply hated being a student. Then, my wife practically forced me to go so I could get my degree and start teaching. I admit that I hated the undergrad junk, but now I am much happier to be in an academic environment than hacking away in some company.

      Also, there's the Internet. To this day, any search for my nick (kainaw) still turns up "Kainaw's Amiga Internet Guide" - a guide to getting an Amiga on the Internet when all we had was SLIP over dial-up. Maybe you could write a good guide to 6502 assembly and be surprised when someone calls you in the middle of the night with a strange assembly question.

      --
      The previous comment is purposely vague and generalized, but all of the facts are completely true.
    2. Re:desire to teach someone 6502 assembly language by Anonymous Coward · · Score: 2, Informative

      There are many so called rom-hackers out there who would love someone like you to tutor them in the ways of learning 6502 assembly for hacking console system games that use the 6502 processor. Such as NES, 2600, TG16, etc. I've dabbled in 6502 asm for a while now making demos, and reverse engineering nes roms and you really do get a intimate feel for the computer/console your working with because of assembly language. Anyways there are many hungry people out there in the console dev/rom-hacking scene wanting your help...

      -- HighT1mes

    3. Re:desire to teach someone 6502 assembly language by ScrewMaster · · Score: 2, Insightful

      Actually, I think a LOT of the appeal of a straightforward RISC-like processor like the MCS6502 is the simplicity: you can keep all 56 basic opcodes and all the addressing modes in your head with no need to continually refer to a reference manual or online help system. I spent years coding 6502 on the Apple ][, Commodore 64 and embedded systems and found that I could simply CODE, continously, and I was extremely productive. I was able to encompass all relevant portions of the language and the hardware in my mind, and was able to essentially "run entirely from RAM" while I was working. I really miss those days: the code would simply flow from my fingertips without constantly cracking reference manuals, or having that nagging feeling that the language probably has a feature or function that would do what I wanted but not having any idea where to find it.

      Flash-forward a quarter of a century, and we have bloated, massively complex "development systems" such as Microsoft's Visual Studio and others, which have such an incredible amount of complexity that no mere human memory could possibly learn all of it. Add to this the fact these development tools are changed regularly, arbitrarily and with malice aforethought, and it isn't hard to see why overall productivity hasn't increased as much as one might have expected. The truth is that the market-driven creeping-featuristic aspect of modern programming environments has, in many ways, proven detrimental to the development process.

      In fact, it's been shown in several studies I've read over the past decade or so that because of this ridiculous degree of complexity, programmers simply learn a subset of the available instructions, just enough to get the job done, and rarely bother to learn anything more. And that's entirely justifiable, because if they DID invest huge amounts of time trying to learn all of the available features, odds are the langauge vendor will have changed the language anyway. Consequently, most of the power of modern tool chains is simply never realized by most users of them.

      --
      The higher the technology, the sharper that two-edged sword.
  13. how many people actually program in assembly? by Doppler00 · · Score: 5, Interesting

    I've programmed a few embedded systems in assembly and it's not very fun at all.

    To make matters worse, each CPU has it's own instruction set, and special set of commands that you must learn before you can even sit down and start writing code.

    With C++ or at least a C compiler, you don't need to worry about so many implementation details. You should only resort to assembly if you absolutely, must have the performance required. Maybe the author of this article forgets how difficult it is to debug assembly code, or how difficult it is to implement abstract concepts such as OO at such a low level.

    I don't agree at all that writing "efficient code" necessarily creates better code. Writing "clearer" is better from a quality standard.

    We have compilers for a reason, to produce assembly code as efficiently as possible for a higher level language. Most 99% of the time, the compiler will optomize the code just as well, or better than you can.

    I would still recommend learning assembly language to C++ programmers simply so they understand how the computer is actually working. But to require anyone to program in assembly requires a great deal of justification.

    1. Re:how many people actually program in assembly? by jay2003 · · Score: 2, Informative

      With C++ or at least a C compiler And then your compiler generates bad assembly and if you don't understand assembly, you can't figure what the problem is. Compilers outputing incorrect assembly has happened to me several times.

  14. In what other languages by foidulus · · Score: 5, Funny

    can you get away with naming a source file org.asm?
    * rim shot
    I apologize.

  15. Not just efficiency but correctness by jkabbe · · Score: 3, Insightful

    I think there is more at stake here than just writing efficient applications. For one thing, writing proper multi-threaded code often requires thinking at the assembly level. Many of my coworkers who are all high-level-language-only programmer types couldn't understand (until I explained it) how the Double-Checked-Locking Java example was broken.

  16. So What? by tomblackwell · · Score: 5, Insightful

    Wow. You can crash a machine with assembly language.

    That may seem impressive to you (especially if you're fourteen), but the fact is that exploits can be done in almost any language.

    In other news, this doesn't have a hell of a lot to do with the posted article, either.

    1. Re:So What? by Nasarius · · Score: 4, Insightful

      It is a big deal when you can do it without root permissions. Running a webserver on Linux that allows clients ssh access? Oops, one of them can take down the whole box. You're right that it's not very on-topic, though...

      --
      LOAD "SIG",8,1
  17. As somebody who has done DSP algorithms by earthforce_1 · · Score: 5, Informative

    Assembly language will always be needed to optimize certain types of algorithms, that don't translate efficiently into C. Try writing a FFT algorithm on C using a DSP, and compare it to what can be done in native assembly. The difference can be an order of magnitude or more. Some processors have special purpose modulo registers and addressing modes (such as bit reverse) that don't translate well into C, at least not without extending the language. Fixed point arithmatic operations are not supported in ANSI C either, but are a common feature on special purpose processors.

    For low power/embedded applications, efficiency makes sense as well. Every CPU cycle wasted chips away at battery power. A more efficient algorithm means a smaller ROM size, and the CPU can either be clocked slower (can use cheaper memory and/or CPU) or put into a halted state when it isn't needed. (longer battery life) Coding small ISRs in assembly makes sense as well, as C compilers often must make worst case assumptions about saving processor context.

    That being said, only a fool would try and re-write printf or cout in assembly, if they have a C/C++ compiler handy. Hand optimization is best used as a silver bullet, for the most computationally intensive or critical functions.

    --
    My rights don't need management.
    1. Re:As somebody who has done DSP algorithms by duffhuff · · Score: 2, Informative

      I fully agree with the parent. Assembly coding is critical in embedded and DSP development.

      It's nice to have a compliant C/C++ compiler for your target device, some even have language extensions allowing you to take advantage of more specific features on the chip. However, when it comes down to speed and critical timing issues assembly can't (yet) be beat.

      On some recent DSP projects we used the supplied C compiler to do simple things like control logic and other tasks, and it works wonderfully for that type of task, but the critical algorithms were all hand-tuned assembly. Often we would use the compiler output as a start and work from there, but we would invariably blow the doors off it performance-wise, but the compiler did surprise us a few times.

      The biggest impact comes with tight timing restrictions. If you've only got 500 microseconds to get a sample done, or process a set of data, *and* you've got to do it a very tight memory space with minimal power consumption, you've got to rely on your assembly language skills to work it out. It's gruelling work, but we can't all just buy faster chips or more memory and use the compiler.

  18. Not sure about his premise by r.jimenezz · · Score: 2, Insightful
    I was lucky enough to be taught assembly on my undergraduate degree, but after five years of "industrial practice" I am not sure knowing assembly will help you write more efficient code, at least not in a modern business environment. IMHO, in these environments you depend too much on pre-existing tools (DBMSs, application servers, etc.) and *those* programmers may benefit from knowing assembly to enhance their work, not you.

    Second, and perhaps more important, I think most of the performance issues in such environments stem from architectural, not algorithmical issues. Think J2EE, where if you are not careful enough you end up doing a round trip to the server every time you set a property in an object.

    In a sense, he covers this in the article when he writes:

    "This doesn't mean, of course, that a practicing engineer should sacrifice project schedules, readable and maintainable code, or other important software attributes for the sake of efficiency.

    What it does mean is that the software engineer should keep efficiency in mind while designing and implementing the software."

    But of course, most of his emphasis is on knowing how does the machine work. I ascribe more to modern thoughts considering efficiency (and other non-functional requirements, such as the maintenability also mentioned in the above quote) as architectural concerns, things that shape the architecture and that no amount of algorithm substitution and the like can fix if gotten wrong in the first place.

    --
    The revolution will not be televised.
  19. far more important than optimization by exp(pi*sqrt(163)) · · Score: 4, Insightful

    You know, when you're trying to get a game out the door that runs at 30fps and your competitor has a similar game running at 60fps because they coded their inner loops in assembly you begin to realize why optimization is important after all.

    --
    Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    1. Re:far more important than optimization by imsabbel · · Score: 3, Insightful

      If you get your game out and need 14 patches to be playable and your reputation is ruined, and your competitors product runs fine out of the box, you realize there are other products more important.

      Btw: Most of those "inner loops" you could save tons of time with assembly have slowly dissapeared with vertex shaders and gpus in general.

      --
      HI O WISE PRINCE. WHT TOOK U SO DAM LONG?
  20. Which Platforms? by buckhead_buddy · · Score: 4, Interesting

    What platforms would you use to teach assembly?

    Intel could give many kickbacks to university programs, but they appear to get criticized for chips with too much baggage and backward compatability.

    The RISC PowerPC processor has potential, but the number of consumer desktops with it has been on the decline (Is anyone but Apple left?). Computers might be too expensive for some students.

    A Palm Pilot / Handheld sounds like a great choice to me. They're cheap and can be synced with whatever consumer desktop the user has (I can't imagine coding assembly in Graffiti). The limited hardware is probably a plus for academic purposes.

    I think this fellow makes some great points, but what platform and tools would you choose to learn assembly with?

    1. Re:Which Platforms? by Archeopteryx · · Score: 3, Informative

      I would start with an emulated 8-bit microprocessor or microcontroller, such as the Z-8 or the 68HC908. This way they can run the emulation on a platform they already have, and such devices, embedded within ASICs are the most likely target for a pure assembly effort anyway.

      Just a couple of years ago I did a fairly large 68HC908 application for a housekeeping processor entirely in assembler.

      --
      Dog is my co-pilot.
    2. Re:Which Platforms? by TheRaven64 · · Score: 2, Informative
      Why use a real machine at all? In my second year as an undergrad we were expected to build an optimising compiler for a simple language. The output for this compiler was assembly for a very simple virtual machine (the Tiny Machine from Kenneth C. Louden's compilers book. Here's the source code if anyone wants to play with it). I think this (combined with exposure to things like URMs and courses on microprocessor design) gave a better grounding in efficient program design than learning any real assembly language.

      If I had learned assembly then as a child it would have been 6502 or Z80, as an undergrad it would have been x86 (or a small subset of x86 assembly, since it really is horrible). Now, most of the coding I do is on PowerPC, so none of them would have been any use and would have taught me misleading things (for example, register allocation is horrible on x86 and context switches are very expensive. On PowerPC most of the registers are general purpose and context switches have about the same overhead as function calls).

      I doubt that learning a real assembly language is much use (unless you learn PIC assembly, or similar and then develop embedded systems), but using something like the Tiny Machine is very good experience (and since it runs on about any platform with a C compiler and a libc it eliminates hardware constraints).

      --
      I am TheRaven on Soylent News
  21. Try the games industry by Jack+Porter · · Score: 5, Interesting

    While the majority of the Unreal engine is C++, we often write assembly-code versions of critical functions for specific platforms. Of course this is done after the C++ versions are tried and tested, and the bottlenecks are idetified.

    To take full advantage of processor features like SSE or AltiVec you don't really have a choice.

    For example, UT2004 contains SSE and AltiVec assembly versions of some of the vector and matrix manipulation functions, some of the visibility culling code, etc. The amount of work Dan Vogel put into this kind of optimization is one of the reasons that UT2004 runs better than UT2003 on the same hardware.

    Learning assembly language is useful, as it's sometimes the right tool for the job.

    1. Re:Try the games industry by nonya · · Score: 2, Interesting

      > To take full advantage of processor features like SSE or AltiVec you don't really have a choice.

      This is true. However, the intel c++ compiler does a decent job of vectorizing code. I wrote some benchmarks comparing gcc, icc (intel) and hand coded
      assembler using mmx/sse/sse2. Icc did surprisingly well, often equivalant to my hand coded assembly (gcc did less well).

  22. x86 aint what it used to be by mike260 · · Score: 3, Insightful

    I have very fond memories of writing pentium-optimised asm...the rules were complicated enough to make things interesting, but still comprehensible.

    Nowadays, the x86 ISA is just an API...god knows how the core actually executes instructions and in what order, which makes it very hard to optimise code beyond a certain point. You get more mileage from optimising memory access patterns and doing other such dull, dull, dull work. I get my asm coding fix elsewhere nowadays.

  23. Obvious qdb reference by revmoo · · Score: 4, Funny
    How does an assembly programmer commit suicide?
    goto cliff
    :cliff
    jmp 0xFFFFFFFF
    --
    I would expect such blatant racism on Fark, but on Slashdot? Mods please ban this asshole.
  24. The problem with assembly... by jafo · · Score: 5, Insightful

    Quoting: "the best implementations are written by those who've mastered assembly language".

    I haven't read this book, but I'd hope that there would be some pretty good justification of the above statement. I suspect that it's not, though. First of all, who defines what the "best implementation" is?

    As Knuth says, the first rule of program optimization is: "Don't do it". Trying to optimize a program when you're writing it leads to all sorts of problems including difficult to maintain code, increated time and budget required for the project, and often it's not even a hot spot anyway.

    I used to be very concerned about using making my code fast, but have (over the decades) decided that making it obvious is much more important than speed, particularly in the initial implementation. Profiling allows you to concentrate on the 20% of the code that the program is actually spending 80% of it's time in, instead of guessing where the hot spots are going to be.

    I've found that another benefit of using simpler code is that I'm more likely to throw away whole sections of simpler code and try radically different algorithms or mechanisms. More complicated code I find I'll try to just tweek instead of dumping wholesale. Randically different approaches can lead to 10x speedups where tweeks of existing code may give you 2x speedups, if you're lucky.

    Don't get me wrong, I'm all for trying different approaches. I'm not sure I would have come to the same conclusion I have now if I hadn't spent quite a long time trying to write optimized code. It was a very different world back then, but I know I wasted a lot of time optimizing code that didn't at all need it. It was an experience though.

    Sean

  25. Learning Asembly from Hyde made me a better coder by John.P.Jones · · Score: 2, Insightful
    I learned Assembly language programming from Randall Hyde using his monster tome (available online for free and in print) the Art of Assembly Language Programming.

    What Randy Hyde taught me is that it is important for a beginner programmer to quickly learn what kind of instructions the high level code you write is being translated into, how basic machine organization works and how the compiler and OS figure into running your code. Writting Assembly is no longer important (thank goodness) however the process of LEARNING how to write Assembly is a crucial step in a well rounded CS curriculum.

    When Randy Hyde taught x86 Assembly to us at UC Riverside it was the toughest lower-division class and the weeder for the people who shouldn't be computer scientists. Without that core people are making it to upper-division and performing very poorly in OS, compilers and architecture.

  26. What I Learned From Assembly... by Prototerm · · Score: 2, Funny

    ...is not to fear Binary Arithmetic. It's just like regular arithmetic -- if you're missing 9 fingers.

    --
    "My country, right or wrong; if right, to be kept right; and if wrong, to be set right." --Senator Carl Schurz (1872)
  27. Where am I going wrong? by skywolf · · Score: 2, Interesting
    I code in C, assembly and Matlab. I also write code for PIC microcontrollers.


    I see very few links between the way I code in assembly, and how I write the higher-level languages. Yet according to this article I should have the makings of a guru. Where am I going wrong?


    Presumably everyone understands binary encoding, shift right and left instructions, and the like? Anything much beyond this is liable to be very architecture-specific - which is bad. I look forward to the day when I can choose between a number of architectures and run the same open-source programs on each. I loathe X86, and I dislike apple for other reasons.


    Perhaps we become more rigourous by writing assembly for small systems - with very few resources. But beyond this, I can see no real advantages to learning assembly.


    I regard myself as a good programmer, but I see my strengths as being clarity of expression and design.


    Skywolf

  28. Viruses by Sheepdot · · Score: 2, Funny

    Probably the best reason to learn ASM is so you can code your own viruses instead of stealing my own GPL'd malware.

  29. Learn compilers by bigbadbob0 · · Score: 3, Interesting

    I think learning compilers and how they will take your code and mangle it into machine code is more important than learning assembly, specifically. Building your own compiler will require you to learn some assembly (or at least the notion of it) which is sufficient for this purpose.

  30. This guy clearly doesn't work in the real world. by Chazmyrr · · Score: 2, Informative

    In the real world, you generally don't write an application targetted to a specific CPU. You trust that your compiler is generally going to produce efficient machine code for your algorithm. Sometimes it won't, but if there isn't a performance problem with that particular section of code it usually isn't worth the effort to do anything about it.

    The point of using a profiler to optimize your application is that usually you're going to identify a couple key areas where you need to do some tuning because your algorithm is not efficient regardless of the architecture on which its running.

    Further, within the x86 family, different CPUs have different performance characteristics. The most efficient machine code on one may be the slowest on another. So to write the most efficient programs for x86, according to this guy's definition, I would end up having to implement run time CPU checking with different code paths depending on the result.

    Guess what? It isn't worth the additional development time unless the result is substantial. How do we know which improvements would be substanial? We profile the code.

    This guy needs to take a leave of absence from teaching and work as a programmer for a while before he shoots off his mouth on topics where he clearly has no clue.

  31. This is the wrong reason to learn assembly by Skapare · · Score: 3, Insightful

    I'm fully in favor that most programmers should learn some assembly. But learning how to do efficient code is not the reason for learning assembly. Assembly should be learned thoroughly by systems programmers (who write operating systems, core libraries, compilers, etc) and certain embedded programmers because they might actually need to use that skill directly. Other programmers should learn some to the extent that it teaches them what's really going on inside the machine, but they should not dwell on it (unless they find it fun). Efficiency should focus on choosing (or developing) the proper algorithms for the application being developed.

    If one is going to do programming where pointers would be used (systems programming and lower level applications programming, such as in C), then I suggest learning assembly as the first language. Two or more decades ago, that advice worked because most people didn't learn to program until they took a class in it or such. Now days, people destined to be programmers are learning some programming by around age 10 (usually in whatever language is easiest to get started in, which is generally not always the best to develop larger applications in). By the time they've done a lot of programming, they either "get it" with regard to pointers, or don't, and are set that way for life. This is unfortunate (and results in much insecure programming).

    --
    now we need to go OSS in diesel cars
  32. The old days... by twoslice · · Score: 2, Interesting
    I was true blue assembly guy for many years and had such an extensive library of assembly routines that I could keep up with most c programmers at the time.

    However, My most sought after skill with my peers was not debugging programs, but using DOS debug to hack around the copy protect schemes in use at the time for various apps and games...

    --

    From excellent karma to terible karma with a single +5 funny post...
  33. Counterpoint by Temporal · · Score: 5, Insightful

    This guy says "Efficiency Is the Key". This guy is wrong.

    With the incredible power provided to us by modern CPU's, efficiency is just about completely irrelevant for 99% of non-game applications. Think... when was the last time you thought "This word processor just doesn't respond to my keypresses fast enough." or "AIM takes way too long to open a new IM window."? The reason why these programs aren't getting "faster" (as the article complains) is because there is no way to do so. They spend 99.9% of their time waiting for user input already.

    Optimizing code which doesn't need optimization is Bad with a capital 'B'. When optimizing code, there is almost always a tradeoff between efficiency and maintainability. Efficiency often requires cutting corners, killing opportunities for future expansion, or, at the very least, writing ugly code. When that added efficiency does not lead to any noticeable benefit to the user, why do it?

    Now, granted, you shouldn't use an O(n) algorithm when an O(lg n) one exists to solve the same problem. However, knowing the difference between O(n) and O(lg n) has nothing to do with knowing assembly. The only benefits you can get out of knowing assembly are constant-multiplier speed increases. And, frankly, shaving off 50% of 0.1% CPU time used is not going to help much.

    Really, the speed of modern CPU's is sickening. I can't count the number of times I've written a piece of code, thought "This is going to be so slow...", then watched it execute near instantaneously. Even when running programs in a prototype programming language I'm working on -- which currently runs about 40x slower than C, because it's a crappy prototype -- this happens to me regularly. The only time your code is going to be noticeably slow is if you are processing a very, very large data set or you are using slow algorithms. In the former case, sure, knowing assembly will help, but such cases are extremely rare in typical applications. In the latter case, find a better algorithm.

    1. Re:Counterpoint by Wienaren · · Score: 2, Funny

      > when was the last time you thought "This word processor just doesn't respond to my keypresses fast enough."

      Yesterday, when using quanta 3.2.2.

      --
      -- The Online Photo Editor - http://www.phixr.com
    2. Re:Counterpoint by Temporal · · Score: 2, Informative

      Actually, I left something out... the most common reason for slowness in any program is I/O. Reading from hard drives or from the network can be very, very slow. A good way to improve efficiency is to minimize these operations, even at the expense of added CPU usage. Of course, knowing assembly isn't going to help you with this one either.

    3. Re:Counterpoint by eloki · · Score: 2, Insightful

      Optimizing code which doesn't need optimization is Bad with a capital 'B'. When optimizing code, there is almost always a tradeoff between efficiency and maintainability.

      There is truth in what you say, but I don't think this is a counterpoint to what he said. What he is lamenting is the lost art of being aware and caring about performance at the micro-level, as opposed to the macro-level.

      In a way, he acknowledges that knowing assembly itself isn't required. Simply knowing the way the machine works (and having a basic understanding of assembly) provides most of the benefits. Good programmers do not pass 2K structs by value to functions in C, they pass pointers. Good programmers move independent code out of loops. And that is better code in every way - more efficient, because it saves executing it repeatedly, and because if it's independent, then looping it doesn't actually make semantic sense. Later readers of the code might wonder if they're just misreading it, and maybe it isn't independent code... now they have to check for obscure relationships.

      The best point to take away from the article is that efficiency choices are not just the "big" ones like which algorithm to use, they are everywhere. Every programming decision has efficiency concerns, from the choice of algorithm down to the program design (how much data must be passed around?) and the size of data structures (big ones use more memory, which could affect cache locality).

      That doesn't mean that for every choice, you must pick the one that is the most efficient. It simply means that you keep effiency in mind, and you take it into account when choosing. That way when you pick a simpler (but slower) algorithm, you're at least knowingly making the tradeoff... same if you pick the faster algorithm.

    4. Re:Counterpoint by Reziac · · Score: 2, Informative
      ...when was the last time you thought "This word processor just doesn't respond to my keypresses fast enough."

      Erm... today? Seriously. Today.

      See, I had this mere 4 megs of actual data stored in 48,000 records, that happened to come to me as 1500 pages of fairly clean HTML tables (originally in about 50 separate files), and I needed to convert it all to a single file in comma-delimited format.

      It choked every modern program I tried to get to handle it -- and that was while it was still in much smaller chunks of half a meg or less. The only Win32 app it didn't crash outright was EditPad, and even that worthy got a bit laggy on the needful search and replace.

      I wound up doing most of the conversion by hand, in ... are you ready for this?? WordPerfect 5.1 for DOS. In about 2 minutes to S&R the table structures to CSV, and 5 seconds to sort the records. And no editing lag at all.

      As it happens, WP5.1 was written in ASM.

      Well, you asked :)

      --
      ~REZ~ #43301. Who'd fake being me anyway?
    5. Re:Counterpoint by gnu-generation-one · · Score: 2, Informative

      "With the incredible power provided to us by modern CPU's, efficiency is just about completely irrelevant for 99% of non-game applications."

      And this is why your computer still takes a minute to boot-up, despite being 8 million times faster than a 1980s computer that boots in 6 seconds.

      "Think... when was the last time you thought "This word processor just doesn't respond to my keypresses fast enough."

      Last time I loaded Microsoft Word. It takes about 10 seconds to start on my 2GHz machine at work.

      "The reason why these programs aren't getting "faster" (as the article complains) is because there is no way to do so. They spend 99.9% of their time waiting for user input already."

      So tell me why KPPP (a dial-up network program with just 3 buttons) takes 15 seconds to load in my WindowMaker desktop, or why KDE itself takes almost 25 seconds to load? Waiting for my user-input, is it?

      "When that added efficiency does not lead to any noticeable benefit to the user, why do it?"

      Everyone here has used fast applications and slow applications. The fast applications feel nice to use and let you get stuff done. The slow applications are annoying and frustrating and difficult to use. I'd certainly count speed (and memory footprint) as a benefit to the user.

  34. Long article makes one point. by twitter · · Score: 3, Insightful
    He makes this one point:

    All too often, high-level language programmers pick certain high-level language sequences without any knowledge of the execution costs of those statements. Learning assembly language forces the programmer to learn the costs associated with various high-level constructs. So even if the programmer never actually writes applications in assembly language, the knowledge makes the programmer aware of the problems with certain inefficient sequences so they can avoid them in their high-level code.

    Fair enough. Like he says, it works with any speed processor to make things faster.

    Most of the rest sounds like praise of free software. Free software does not suffer, "unrealistic software development schedules." Free software authors can go read the source code to gcc and gcc and the gnu debugger both have had more attention lavished to them than any proprietary equivalent.

    --

    Friends don't help friends install M$ junk.

  35. Never too much assembly by thebdj · · Score: 2, Interesting
    I really do not believe anyone can be over exposed to assembly language and all and all it is a good thing that schools teach it. I believe any school which has or plans on phasing out assembly language is doing a great injustice to their students and to the corporations unfortunate to hire those students.
    I myself have learned two and a half different languages at Ohio State and am trying to find time this summer around work to learn a third. To be honest it is almost a "cool geek" thing for me now. I mean everyone and their mother knows C++ or can create a website. Those just aren't as geek as they used to be.
    The two u-controllers (microcontrollers for the slow people) that I learned assembly on are the Motorola 68HC11 and on a fairly standard PIC, which one exactly I worked with eludes me at the moment. The half of a language I know is from the MIPS64 family of processors. I only know "half" because I sort of picked it up as a result of another class and have never actually used it myself.
    The language I am hoping to learn is the x86 assembly language. It seems to me that of all the u-controllers and processors the one that is by far the most common is the x86 architecture. I can think of several good reasons for individuals to learn assembly language:
    • Quicker and Neater then most compiled codes
    • Above makes them better for fast embedded systems
    • They teach good programming skill
    • Can be more powerful, especially when you know how to use it
    It isn't exactly as much needed since most u-controllers have C++ compilers written for them. However, sometimes this compiled code is not as fast if it would have been written in assembly by the user. I hope for the sake of programmers and Electrical/Computer Engineers (like myself) that assembly stays around for a long time. It is still the basis for design of any microprocessor and so long as they are using assembly at a basic level, then people need to know how to use it.
    --
    "Some days you just can't get rid of a bomb."
  36. right on by js3 · · Score: 2, Insightful

    the key to that article was the word "mastering". Anyone can learn assembly but it takes years of practice to master. Just because I can code in asm doesn't make me good at it. An investment that could be better spent elsewhere on other programming languages

    --
    did you forget to take your meds?
  37. Don't forget Reverse Engineering by eidechse · · Score: 4, Insightful

    A solid knowledge of assembly, file formats, calling conventions, and other voodoo is the price of admission if you need to find out how something works and all you've got is a binary.

  38. Assembly vs. scripting by xyote · · Score: 4, Interesting
    I used to have two binary search utilities. One written in assembler and one written in a shell script. Same logic. The script was faster. Performance isn't just a matter of number of lines of code.


    In this case I think the reason was the system having to load the binary vs. the script interpreter already being resident in memory. The start up overhead dominated the actual runtime overhead - binary searchs are very quick.

  39. assembly as a game by j1m+5n0w · · Score: 2, Informative

    This is a bit of a digression, but I'd like to point out that not only is assembly useful to implement games, it can be a game in itself: 7th anual International Functional Programming Contest, CoreWars (though I don't expect them to displace the market share of UT2004)

    -jim

  40. It is this kind of bullsh*t attitude by Mycroft_514 · · Score: 2, Insightful

    That set up many 3-4am debugging sessions.

    Look, exposure to low level languages and limited memory make you think about what you really need in the program and what you can do without.

    In one shop I would take code from the consulting firm, trim out 40-60% of the code, and end up with a job running 25-35% faster (and cheaper). And then there was the other bug in the code. 50 lines of useless code in each of three programs was costing the company $60K in usage to a department per year!

    Or how about added transfer time into an EDI program twice for each item calculated. It was causing Disney to hold $10 Million in the warehouses in inventory until I found it.

    And it isn't just assembler. It is low level DBMS functionality too. I had one job where the first test ran 12 hours. By re-coding it in a completely different manner it took 5 minutes. The 12 hour method was the method recommended by the vendor of the DBMS. The 5 minute version was mine.

    Finally, code can be in a high level language and still be efficient. And there are still plenty of devices out there with limited memory - how about PDAs? or Dive Computers?

  41. Problems with article by Percy_Blakeney · · Score: 5, Insightful
    I agree with the underlying premise that more programmers should learn an assembly language and the intimate details of how a computer works. However, I disagree with several part of the article.

    - He faults inefficient coding for the failure of software speed to keep up with CPU speed (or at least, its a "large part".) This is much less true than he lets on; Amdahl's Law means that the CPU is less and less responsible for the speed of an application, while things such as disk seek/transfer times, memory access times, and network latency all play huge roles in the speed of your computer's software.

    - He seems to think that it's not terribly hard to become an "efficient" assembly language programmer. Bzzt, wrong! In the modern era of superscalar architectures, pipelining, processor specific instructions, branch delays, and memory heirarchies, it takes a hell of a lot of knowledge and experience to beat the performance of a good compiler.

    - He apparently hasn't tried any large assembly language porting efforts lately. I'd love to see the effort involved in porting a large x86 assembly language program to a MIPS architecture, all the while maintaining that coveted "ultra-efficiency". The reality is that a good compiler can be reasonably efficient at porting a program to a new architecture, while a programmer usually isn't.

    - He also apparently hasn't tried debugging a large chunk of assembly code lately. It is a fact of life that it is very difficult to debug assembly. By using a high-level language, you are increasing the readability of your software, which tends to decreases the number of bugs.

    I could go on, but needless to say, I'm not impressed with the numerous assumptions and generalizations about assembly that he makes. Learning assembly will make your high-level programming better, and limited use of it can be appropriate, but using it all over the place is a huge mistake.

    1. Re:Problems with article by bro1 · · Score: 2, Informative

      As far as I understood from the article the author does not advocate writing software in ASM. He is merely advocating learning ASM in order to understand how to write efficient programs in high level languages.

      Which does not actually make much sense for virtual machine based languages such as Java and C#.

  42. Crappy programmers make crappy programs by Anonymous Coward · · Score: 3, Insightful

    It doesn't matter what language you know, crappy programmers will always write crappy programs.

    A bad assembly programmer will write unreadable and unmaintainable code.

    A bad C programmer will write unreadable and unmaintainable code.

    A bad Java programmer will write unreadable and unmaintainable code.

    A good assembly programmer will write beautifully elegant and efficient code.

    A good C programmer will write beautifully elegant and efficient code.

    A good Java programmer will write beautifully elegant and efficient code.

    Learning assembly language will help you understand how the guts work, and yes, it can be used to optimize the last 20% that compilers can't do (ie for embedded and graphics). It will help you crack registration keys, solve stack bugs, and write viruses because you will have a better understanding of why certain behavior is prevalent in computer code. But you don't absolutely require it to write efficient and clean code.

  43. Re:HLA?...nah. by biobogonics · · Score: 2, Insightful

    And this is at least the third time this has been promoted on /.

    So? HLA is a good teaching tool. Randy is now a unversity professor.

    Even if you don't use assembly, it does make you a better programmer. Learn assembly and pointers make sense. As a teaching tool, assembly has some advantages. You are programming an abstract machine at a simplified level. (If you read Knuth, you are programming a fictional abstract machine!) Some data structures and algorithms are easy to explain in assembly.

    Plus, understanding assembly gives you a sanity check on C code. For example, look at the hoops some C programmers go through to get the double length result of a multiply or the quotient and remainder from a divide operation at the same time.

    In particular, I remember a library routine that came with a well known MS-DOS C compiler by a very talented programmer. I could see that the source code was written in C and it was a convoluted mess. Worse it was wrong! About 20 lines of 8088 code would have been equivalent (or 4 lines of '386 code). The author was trying to do some low level bit whacking in C that should have been done in asm in the first place.

  44. "Premature optimization is the root of all evil" by richieb · · Score: 5, Interesting
    To quote Donald Knuth.

    Having said that, knowing assembler is useful because it teaches you how the machine works.

    However, most modern compilers can generate code that is much faster than handwritten assembler - especially because they know how to take advantage of the specialized processor architectures (hyper-threading, pipeling etc).

    --
    ...richie - It is a good day to code.
  45. The Art Of Computer Programming by drew+crampsie · · Score: 4, Interesting

    I've been reading this site since it was chips n dip, but this is the first time i've ever felt the need to comment.

    I can't believe that any developer could write and code without some knowlege of ASM. Disclaimer: I'm self-educated, so have no bias except my own.

    More importantly, if you don't know ASM and can't understand machine language, you'd never get through Knuth's tome "The Art Of Computer Programming".

    In my opinion, this is the most important work ever written in our field. Any developer worth his/her salt should have at least read and understood these books, and completed at least the simple exercises.

    the examples in tAoCP are written in machine language for a fictional machine, but the depth one learns by reviewing what that machine does with its data is important in any project.

    I've never programmed professionally in ASM. infact, i usually work in Perl/PHP/Python. But i would not be able to write quality code in those languages if my mind was not constantly thinking of the machine. After all, i'm a computer programmer, not a linguist or scientist.

    Not knowing assembly, or at least having some idea as to how a computer processor works, would make a programmer useless in my eyes. leave them to Access or VBA, and leave the coding to us pro's :)

    I beleive that ASM should be taught first. If you can't understand ASM, you'll neer be a good programmer, so why bother learning Java/C++ or whatever? would you trust a doctor who didn't know how the body works?

    drewc
    Open Source Business: The Tech Co-op
    --
    Drew Crampsie - Software Developer
    Open Source Business : The Tec
  46. Because you can't always trust compilers by soullessbastard · · Score: 5, Insightful

    One thing that many programmers take for granted these days is that compilers produce correct code nearly all the time. They've gotten really good over the years and are really a testament to the quality of compiler engineers. Even so...

    I've been a programmer for over a decade and I've always found the worst problems to debug are when the problems aren't in your code but in the compiler. Compilers are programs too and have their own bugs. They aren't always 100% accurate at generating correct machine code for your source. And until the compiler gets fixed in the next patch or rev, you may be stuck with broken code unless you switch compilers.

    Sometimes disassembly of the problem code and inlining correct assembly can be the difference between shipping a product or missing a deadline because you've spent months sitting around for the next compiler version to fix your problem for you.

    ed

    1. Re:Because you can't always trust compilers by Percy_Blakeney · · Score: 2, Insightful
      Of course, you can't always trust assemblers either. There isn't necessarily a one-to-one correlation between a given assembly instruction and what the computer actually does, especially on architectures like the x86.

      To take it even further, you can't even trust machine language all the time -- look at Intel's floating point bug a decade ago. There's a reason why x86 processors now have ways of patching the microcode.

  47. Absolutely by KidSock · · Score: 5, Insightful

    I didn't start programming until I was in my mid 20s (degree in Chemistry). I liked fiddling with Java but always felt uncomfortable about what was going on underneath the hood. So I took a few classes. The first was Computer Systems Architecture. We wrote a game in x86 assembler. That class completely opened up my understanding how programs actually worked. To understand the stack, the state machine nature of things, and memory was an awakening experience.

    Now (~5yrs later) I'm a fully capable programmer and an even better designer. My preference is C, binary file formats, networking protocols, crafting elegant solutions for multiplexing IO. I'm lead on a project used in production by many companies large and small.

    I genuinely feel assembler is a vital part of the learning process for a programmer.

  48. Schools not teaching assembly...Really? by Venner · · Score: 2, Informative

    Well, I'm a recent (May '03) computer engineering graduate. We programmed in assembly on MIPs, x86, Motorola, and several other architectures that aren't coming to mind at the moment.

    The CompE curriculum at my university was very electronics / hardware oriented, so there was quite a bit of asm to learn. Not to mention VHDL, etc, which is also quite valuable stuff to know. Nothing like building individual logic from scratch and putting it together to simulate a microprocessor. Then trying to implement it on a chip.

    --
    A preposition is a terrible thing to end a sentence with.
    1. Re:Schools not teaching assembly...Really? by johnnyb · · Score: 2, Informative

      Oklahoma State University seems to be at least phasing it out of some of their programs. OSU-Okmulgee doesn't even teach it at all. How they plan on truly educating their students in their new security training when they don't know how code works at the assembly level I have no idea.

  49. Function calls and data buffering by Latent+Heat · · Score: 2, Interesting
    I work with audio digital signal processing along with visual displays of signals, and instead of worrying about the overhead of function calls and how many parameters they have and whether they are virtual or dynamically dispatched, I try to block or buffer things so that I get things done wholesale for every function call.

    Given the way processors are pipelined, you take such a hit for any kind of function call compared to a set of arithmetic operations that the only way to go is to call functions on arrays or slices of arrays to process batch of samples at a time. If you implemented a digital filter by calling a function for each sample you want to process, that is going to be slow, while if you call a function for batches of 1024 samples, you are really pretty insensitive to the function call overhead. If the function call overhead is high, just make the batch size bigger.

    This arises in other situations: for operations over a network it is recommended to make your transactions blockier or chunkier; for raster graphics, the naive Windows SetPixel() command is slow compared to CreateDIBSection().

  50. Realtime video enhancement filters needs assembly! by mdrejhon · · Score: 4, Insightful

    I learned 6502 assembly in the 1980's on a Commodore 64. I even have it all imported into my system, into a few D64's full of software I wrote myself - to run in an emulator for old time's sake. (Gee, hard to believe that some of the programs are almost 20 years old now.)

    I had a lot of the habits that you describe, and I now program simply in C++ for either Linux or XP.

    However, I had run into some performance issues with certain critical loops that were executed millions of times, such as a loop that iterates through pixels in image processing, and I wanted to view the disassembly of it. I understood enough assembly to be able to optimize a tight loop in a plain C code routine, and verified that the assembly was just as good as handcoded non-MMX assembly. (Some compilers do an amazing job now) The only way to improve the performance further in my case, would have to have written MMX/SSE/SSE2 for this 0.05% of a computer program, but even so, I deemed it not to be still worth the effort.

    Now, if you are talking about realtime video filters, such as deinterlacing and sharpening (think Adobe Photoshop style plugins executed 50 or 60 times per second for every interlaced video field at 60 Hz for NTSC, 50 Hz for PAL), you still need matrix math operations such as MMX/SSE/SSE2 assembly language if you want to do lots of video enhancement realtime on a live video source.

    One example program is the open-source dScaler project - dScaler Realtime Video Processor . You can do REALTIME sharpening filters, denoising filters, motion-compensated deinterlace filters, 3D-like chroma filters, diagonal-jaggie removal filters, etc, all the above simultaneously, on a LIVE real-time video source from a cheap $30 PCI TV tuner card, on today's high end Pentium 4 and Athlon systems. All this would not be possible without assembly language. Now, they are talking about adding realtime HDTV enhancement (1080 interlaced -> 1080 progressive). Run your cable/satellite/DVD box connected to your home theater PC running dScaler, and hook the home theater PC to your HDTV, and the live homemade "upconversions-on-the-fly" you are seeing are shockingly better looking than the bad quality upconvered video you watch on TV; (Important: Don't use S-Video output, connect the VGA output directly to the TV using a component-output adaptor. It's 6 times sharper than S-Video. For more information, see AVSFORUM's Home Theater Computers Forum section for more information about getting HDTV-quality video out of your computer to your HDTV television, especially if the HDTV television does not have a native VGA input.)

    (For watching live realtime videoprocessed video, I don't recommend a $30 TV tuner card, the power users like to get more expensive cards such as approx-$250 PDI Deluxe card, which is a Conextant 23882-compatible card that actually has a Y-Pr-Pb component input for computers! Supposedly better analog signal-to-noise ratio, better A/D converter electronics, better power filtering.)

    The point is that you don't need assembly language most of the time, but there definitely sure are times that it's exeedingly, absolutely critical.

  51. Another reason: so your mental model is correct by alien_blueprint · · Score: 4, Insightful

    If you don't understand what's going on at the machine level, you are going to run into trouble eventually because your perception of the runtime environment is slightly or even wildly incorrect.

    Example: When programming in languages like C or C++, you have to know what a stack frame is and basically how it's implemented, so that when something goes wrong you can correctly diagnose the problem. If you just know the corresponding language syntax (i.e. the scoping rules), you won't have the first clue where to start.

    This applies to Java as well - just replace "machine code" with "bytecode" and "CPU" with "virtual machine".

    In all these cases, a compiler takes your program specification (the source code) and produces the *real* program (in machine code or bytecode) - and that is what is executed and that is what you will be debugging and analysing. If you don't understand basically what machine code is and how it works, you will keep running into brick walls. I've seen this over and over again - the new graduates who just can't see why their program is behaving the way it does, because they never did assembly programming, or studied the run-time environment of programming languages, and so have these bizarre ad-hoc mental models of what's happening that bears little or no relation to reality.

    I'm not saying that assembler should be used any more than it is currently, but if we are going to be using compiled languages (C, C++, Java), then it simply *must* be taught. There is simply no way to avoid this if you want to be a half-way productive programmer in those environments.

  52. NIU does. by gillbates · · Score: 2, Funny

    Assembler is used as a weed-out course. This course humbles a lot of hackers....

    --
    The society for a thought-free internet welcomes you.
  53. Re:This guy clearly doesn't work in the real world by Brandybuck · · Score: 2, Informative

    No, you're the one without a clue. Read his article. He is saying that it is useful to *learn* assembly, not that it is useful to use assembly for everything you write.

    --
    Don't blame me, I didn't vote for either of them!
  54. *A* big ass computer??? by PaulBu · · Score: 2, Insightful

    Due to the advancee in hardware capabilities Bloat is now excusable - and encouraged. It is cheaper to buy a big ass computer that can crank and hog bits than it is to pay somebody good money to nitpick over every bit of resource that their programs consume.

    What if you want to run your app on (God forbid! ;-) ) SEVERAL computers? I may be mistaken, but I do not think that you still have the mentality of "The world's market in computers is probably 5 or 6 of them" (food is burning on the stove, no time to get the exact Watson's quote ;-) ).

    Last time I checked the price difference between a $100 ARM-based unit and $5,000 G5 was still $4,900, so if you intend to run your program on a 1000 units you can as well pay $900,000 to a guy who can port from the latter to the former and keep the cool $4M.

    Or if you think about selling your solution (HW+SW) to some millions of customers... (Wow!) ;-)

    Paul B.

  55. Debug? What's that? by www.sorehands.com · · Score: 2, Funny

    I write my code right the first time. :)

  56. embedded code by EmbeddedJanitor · · Score: 2, Informative
    It is close to impossible to write embedded code without using at least some assembler. All C programs - err well just about -- need some assembly code to set things up before calling main().

    Another reason why assmbler will always be useful is that many CPUs have valuable instructions that have no C equivalent. Therefore to use these instructions one typically needs to write assembler.

    Frequently it is simpler to write a function that accesses hardware directly in assembler than it is to write it in C. With C the compiler will often jerk you around and optimise away specific behaviour that you want.

    --
    Engineering is the art of compromise.
  57. Re:assembly still doesn't seem like the best choic by johnnyb · · Score: 4, Insightful

    Much more useful in most systems is knowledge of the system components at a level higher than the CPU--details about how the OS works (scheduler, memory management, etc.), how the language you're programming in is designed (is tail-recursion done without a stack?

    Of course, some of these, even if you don't HAVE to know assembly language to understand them, knowing assembly language makes it easier to understand. Most people who know assembly language have a much more concrete view of the differences between pointers and values. When you have personally had to think about whether to push the value or the memory location, when you have to think about which addressing mode you need to use in that situation, it makes the idea of pointers and stacks and calling conventions a TON more concrete. It also makes many of the ideas of sequencing and linearity a lot more concrete. This is something that I've found a lot of new programmers have difficulty with - they have trouble thinking in straight linear fashion, and assembly language absolutely forces you to think that way.

    Anyway, that's the reason I wrote my book on assembly language. See my sig for more info. Randall Hyde actually wrote me a pretty good review on barnesandnoble.com. I got a good one from Joel Spolsky, too.

  58. With all due respect... by blueforce · · Score: 2, Insightful

    I agree with the premise of the article and I understand the logic behind his arguments. I too, believe every programmer should have a strong math foundation and learn assembly language - regardless of the architecture. Generally speaking, knowing the "nuts and bolts" is what separates the 4-year CS degree programmers from the 2-year, fast-track-to-developer "programmers". All too often schools do future developers and the companies they end up working for a disservice by churning out less-than-ready programmers with a weak foundation in the why's and theory in exchange for a bunch of how-to's on a particular language syntax.

    However, regarding the article, there's a piece of the puzzle missing. In the case of a byte-code language like Java or C#, the code isn't compiled to assembly or machine code where it's easy (other than a debugger disassembly) for a developer to get at. In the case of C# or any other .NET CLR language, it's nearly impossible to know how the compiler generates assembly instructions. In the case of Java, one may be able to study the JIT compiler of an open-source implemenation like Blackdown but that's not necessarily the best option or even the most efficient implementation either. There are so many different JIT compilers for Java, which one would you study? With the .Net CLR, the only possibility would be to study the source to ROTOR to gain any insight into the JIT compiler.

    The implication of the article is that the programmer has some access or insight to the compiler output other than looking at the object files. I submit that, especially in the case of a byte-code language, that insight isn't nearly as available. After all, we're talking about programmers that don't know assembly, in all probability don't know what an object file is, and perhaps don't have the expertise to know how or where to garner such information.

    I would like to see these programmers learn the difference between the stack and the heap. It's not exactly easy, especially when you don't know where to begin, to figure out how the compiler for a high-level language creates assembly instructions from source. Learning that information (think YACC and Bison) is on the same level as assembly, combinatronics, and two's complements. Again I say, it's not enough to learn assembly - Without the solid background in math, data structures, and other concepts, the 2-year degree programmer is, in all probability, lost. You can't learn or use assembly without two's complement, binary, and hex arithmetic. How could you figure out how to add 64-bit numbers when you only have 32-bit registers?

    Like I said, I don't disagree with the premise of the article. However, simply learning (or trying to learn) assembly is not the cure-all for all programmer deficiencies. You just can't take a person that can't add 2 hex numbers, run them through assembly 101 and expect the Mona Lisa of software. I suppose there are broader implications to learning assembly like having to learn all of the aforementioned skills first but that was never indicated in the article.

    --
    If you do what you always did, you get what you always got.
  59. Toccata & Fugue for Eight Bits by Dr.+Mu · · Score: 2, Interesting

    Great symphonic programming masterworks will always be scored in high-level languages. But there are those of us minimalists who thrive on doing as much as we can with as little as possible. Writing a tightly-orchestrated fugue for an eight-bit microcontroller in assembly language is an art form I shall never grow weary of practicing. With a 2K program space and maybe 128 bytes of RAM, every single note must contribute to that ephemeral interplay between space- and time-efficiencies. Those of you who do this for a living will know what I'm talking about. To those just entering the field, I hope you seize whatever opportunities you can to learn assempbly language -- especially if it's for a low-level controller. You may become hooked for life!

  60. Assembly's still important. by sodergren · · Score: 2, Insightful

    I still think that it's extremely important for a programmer to understand what's happening at the lowest level in the target system. It's also very important for low-level work such as bios code and for small system programming. On some small embedded systems, a programmer can actually be concerned about efficient stack use, etc, and if you have limited RAM, the bloated spew that a C compiler puts out just might not be acceptable.

    Understanding of assembly / machine code can also be quite important for hardware people. Example: when debugging a new board design with a logic analyzer hooked up to the system's buses, C/C++ knowledge isn't going to help decipher that long list of numbers being transferred from RAM to processor.

  61. Re:This guy clearly doesn't work in the real world by Hemlock+Stones · · Score: 2, Informative

    Which "real world" are you talking about? The real world sitting on a desktop or the real world in a modern fighter jet that can't be flown unless computer software is used to keep it stable? Where time concerns are critical and every last machine cycle counts. Welcome to the "real world" of hard real-time computing. Where a slip in time costs lives. Profilers can't be used here because they increase execution time.

    Or how about in the embedded "real world" with 64K (that's 65,536) bytes (or less) of program code space and 512 bytes (or less) of RAM? Believe it or not, there are literally thousands of these computers for every desktop computer on earth. Where not ony time efficency but cost and power consumption (lower speed processors), code and data efficency are critical. Profilers aren't much use here.

    It may also suprise you to know that some compiled programs do run time CPU type checking and use different code paths depending on the results for exactly the reasonds you give. A profiler can't always help produce code that is efficent enough on all the variations of the x86 CPU architecture. Few programs need this level of efficency, but when they do, there are few alternatives.

    And, last. No compiler can produce realy good optimized code without a programmer with an intimate knowledge of the instruction set and hardware architecture of the processor the compiler is producing machine instructions for.

    Maybe you need to learn more about "other" types of "real world" computer software uses before you shoot your foot off talking about subjects you clearly do not know enough about.

  62. To some extent you are missing the point by 3770 · · Score: 4, Insightful

    What you are advocating is that the students should understand the cost of the code that they write and you are saying that understanding assembly is the way to do that.

    But here is where you are missing the point.

    It is not the only way and sometimes it is the wrong way.

    With virtual machines and interpreting languages, knowing the machine code of the CPU becomes pointless. You need to know what is costly for _your_ language.

    What I think that you _really_ meant was that your students should understand compiler technology. That is how you understand the cost of different language constructs in a way that is portable across compiled, interpreted and byte code languages. This is unfortunately not something that you can have beginners learn, it is more of a third year thing.

    Also, I've programmed professionally for 10+ years in most programming languages known to man, and I agree with your parent poster. Write simple and sensible code. Optimize when needed. More often than not, you will find that the code is fast enough. If it isn't, then you saved so much time writing the code originally, that you can spend a lot of time optimizing the problem areas.

    If you disagree with this approach (write simple code and optimize when needed) then I'm willing to bet that you've never programmed outside a university environment.

    --
    The Internet is full. Go Away!!!
    1. Re:To some extent you are missing the point by 3770 · · Score: 2, Interesting

      Word!

      The discussion that "knowing assembly makes you a better coder" pops up here at slashdot every once in a while.

      I'd go out on a limb saying that a large part of the reason, for the popular belief that knowing assembly makes you a better coder, is that many people that have learned machine code are really dedicated coders and did it because it was fun. These people have a really good understanding of programming for many reasons, not only the fact that they know assembly.

      Those are the people that have their voices heard on this subject here at Slashdot.

      And those people are not necessarily the people I would trust to make a curriculum.

      --
      The Internet is full. Go Away!!!
  63. RE: No, really, don't bother. by RGreene · · Score: 4, Insightful

    I must disagree. Without having any resources, I would suggest the bulk of software developers are building business applications. You know - the non-computer science stuff. Not compilers, not operating systems, not the latest whiz-bang game, etc.

    A number of us are true computer science students, and we cut our teeth in assembly, so-to-speak. That being said, I disagree that it is necessary (or even good) to understand the machine at the low-level. I have never done x86 development (instruction set and memory models never made sense to me) and I have never seen the JVM byte-code that I use daily. Nor do I care to.

    If you're writing code that is supposed to be optimized for the machine, you've missed close to a decade of compiler development. Dealing with multiple pipelines, delayed branching, etc is best left to a machine. I have more pressing issues to solve - like delivering good software.

    The compiler optimizations are pretty astounding today. The JVM run-time optimizations are amazing. My knowledge of hardware architecture is 20+ years old. I'll trust the compiler writers as well as the JVM designers.

    The focus for the bulk of us is on maintainable applications that can be delivered "on time, within budget, blah blah blah." Illogical algorithms and/or writing code for the computer and not for the human don't help anybody. In fact, I'd probably just throw it out and start again - it's the fastest and least stressful way to deal with it.

    The most important tool to hone and keep tuned is your mind. Those with good logical reasoning and critical thinking are going to do well. They are the ones *I* look up to.

    I would suggest teaching unit testing (ie, JUnit) - including what to test and how to test correctly (both difficult topics) - and debugging skills (which I wished I had more of when I started) instead.

    If you want to cover hardware, use a book like CODE (by Charles Petzold) to give people an idea of computer structure. Nothing more than that - and even that isn't required.

  64. Good luck... by pb · · Score: 3, Interesting

    Actually, there's a Perl module that does this. But if you wanted to write said C program from scratch, it could take you a while--writing the Perl program would be much faster. And then there's the choice of algorithms involved. Have fun writing your own sorting functions in C, your own regular expression library in C, your own arbitrary precision number library in C, your own reference-counting garbage collector in C, your own closures in C...

    Of course, there are other pre-existing C libraries you could use that do all of these things, but there's no telling whether or not they're faster than what Perl uses internally, and since you're re-implementing everything in C anyhow, you might as well just write your own!

    So the point I'm trying to make here is this--Perl is convenient because it has all these things written for you and integrated together. Sure you could write a C program that does the same thing, but you'd end up re-inventing the wheel many times over, and you'd have to work hard to make it a better wheel.

    Or you could target Parrot instead, for a lot of things it's already faster than Perl. It also has a JIT compiler, so who knows--it might generate some code here and there that's faster than what your C compiler generates. :)

    --
    pb Reply or e-mail; don't vaguely moderate.
    1. Re:Good luck... by Alioth · · Score: 3, Insightful

      That seems to be a bit of a straw-man argument, arguing against the use of libraries in C, but for them in Perl.

      All things being equal, any CPU-bound program written in C is highly likely to be faster than the same in Perl.

      The reason I write lots of Perl and hardly any C these days is because virtually everything I write is I/O bound and just doesn't need the performance. I may as well use Perl and save myself a heap of time.

    2. Re:Good luck... by Tony-A · · Score: 2, Interesting

      All things being equal, any CPU-bound program written in C is highly likely to be faster than the same in Perl.

      Depends.
      If the bulk of the CPU is in the program code as opposed to the library code, then C should be substantially faster than Perl.
      If the bulk of the CPU is in program code for C and in library code for Perl, then chances are high that the Perl is better coded and optimized.
      If the bulk of the CPU is in library code, then it depends on the libraries.

      Formatted IO tends to be heavily interpreted and the odds favor Perl as being much faster.

  65. Why stop there? by TheWoundedSeagull · · Score: 2, Insightful

    Not only should the programmer learn assembler, they should also learn Operating system mechanisms. So they understand how their program is operating relative to those mechanisms. but that is not enough, they should also learn CPU design. How else are they really going to understand? Actually they really need to learn about materials science. Not enough really is it? Physics, laws of thermodynamics, electronics, quantum theory. Then when they program they will *really* know what is going on.

    Alternativly they could learn more about the problem domain, so that the design better reflects the problem domain and will be more flexible in the changing environment. Nah, that really would be a waste of time.

  66. JIT? by magnum3065 · · Score: 3, Informative

    I suggest you watch this presentation on the Psyco just-in-time compiler for Python and do some research on the Transmeta Crusoe processor to learn about run-time optimization.

    1. Re:JIT? by johnnyb · · Score: 3, Insightful

      Actually, HP's Dynamo project showed how JIT'ing a machine code into itself (like JIT'ing x86 code INTO x86 code) can give you speed advantages. The reason is that the JIT can look at the runtime characteristics of the code and do optimizations based off of that. It can move code so it's on the same page as other code that is called in sequence, optimize branches so that there is a higher chance of branch prediction and to save the pipeline.

  67. Duh. by humankind · · Score: 3, Insightful

    On behalf of all decent programmers on the planet, may I say..

    DUH!

    Imagine a mechanic who has built his own engine from scratch, or a painter who has made his own paint, or a musician who crafted his own instrument. Those seeking to exercise their art on the lowest possible level will always have superior insight into those that don't.

    1. Re:Duh. by kirkjobsluder · · Score: 2, Interesting

      Possibly true of mechanics. Probably not true of painters. Quite a few great paintings are in serious trouble because the paints are falling off the canvas after only a 100 years.

      Definitely not true of musicians who think in radically different terms from insturment builders. There seems to be a big hole in your analogy. Building an insturment is not analogous to writing in assembly language. A better analogy would be to say that building an insturment is analogous to building a CPU. Musicians think in abstractions such as beats and tones rather than in the terms of resonance, refraction, interference, and reflection that are central to insturment designers. Likewise, most programmers (even assembly programmers) think in terms of abstract bits moved or transformed from location to location rather than thinking in terms of resistance, capacitance, induction, and heat.

      A better analogy would be to say that musicians learn a lot from practicing and composing etudes, compositions that focus on the relationship between musical theory and technique.

  68. Re:.Net micro-benchmarking tool by Leeji · · Score: 2, Informative

    I wrote a C# performance comparison tool to help me in this respect. When you're trying to optimize a hot-spot in your program, you can click on the "ILDasm Result" tab to see how .Net compiles it down to its Microsoft Intermediate Language (MSIL) representation.

    I've also got the book, "Inside Microsoft .Net IL Assembler" that's very helpful. For whatever reason, you can get it for like $2 + shipping used from Amazon.

    --
    It all goes downhill from first post ...
  69. I agree... and disagree... by Otto · · Score: 3, Insightful

    SO WHAT! Programs should only be optimized if:
    1) the program is doing stuff so intensive that it runs slow
    or
    2) It is being run all the time in the background by the system and can slow down the system as a whole.
    98% of the time it just does not matter.


    I agree with points 1 and 2, however, if you're doing any non-trivial programming, I wholeheartedly disagree with the 98% figure. Not every bit of code is a throw-away piece. If your code only runs occassionally, and it's not performance critical, then yes, make readability your main priority.

    But a lot of times your code is performance critical, or at least will be in the future. Code has this tendancy to stick around once it's actually working. Too often have I seen code that, when it was written, was not getting used a lot. It worked, so nobody thought anything of it. As they scaled the system up, that code became a major bottleneck and eventually somebody had to go back and optimize the hell out of it, or simply throw it out and rewrite it to be fast.

    It's good to write readable code. But it's also good to write code that is reasonably optimized at the same time. No need to go to extremes, just don't do stupid things like passing around huge 4 kilobyte variables to functions and such (example I've seen). Pass a pointer instead. Or a reference. Just write smart code. You can still make readable code while making it optimal enough to scale pretty well. Only very, very rarely do you have something that needs to be super well optimized, and then you usually are better off writing the critical sections in machine code anyway.

    Easilly readable code is FAR MORE IMPORTANT.

    Easy readability is far more important when that code scales to the level you need it to scale to. Readable code that doesn't actually work in the system you're trying to put it in is worse than useless.

    --
    - Give a man a fire and he's warm for a day, but set him on fire and he's warm for the rest of his life.
    1. Re:I agree... and disagree... by Kenbo · · Score: 2, Insightful
      But a lot of times your code is performance critical, or at least will be in the future. Code has this tendancy to stick around once it's actually working. Too often have I seen code that, when it was written, was not getting used a lot. It worked, so nobody thought anything of it. As they scaled the system up, that code became a major bottleneck and eventually somebody had to go back and optimize the hell out of it, or simply throw it out and rewrite it to be fast.

      And if that bottleneck was clearly written it will likely be much easier to refactor/optimize. It's really hard without profiling to know which pieces of code will be the bottleneck with current usage and especially future usage. For any decently large program, optimizing the whole program is IMO a supreme waste of time and likely to make it late, brittle, and buggy.

      If your code is performance critical now, write it simply, profile it's execution, fix the slow parts.

      Don't spend alot of time optimizing code now that *might* be performance critical in the future. Chances are that it won't be or that the requirements will have changed enough so that the parts you spent all that time optimizing aren't the critical parts or need rewriting for functional changes anyway.

      The strategy I've developed is as follows:

      • Make it work
      • Make it work right (fix the edge cases/unit tests)
      • If necessary, make it fast

      It took me a long time to get over the notion that every program should be as efficient and fast as I could make it. But my code productivity, maintainability and correctness have improved noticably since I have.

      Obligatory Quotes:

      We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.
      - Donald Knuth

      The price of reliability is the pursuit of the utmost simplicity.

      Premature optimization is the root of all evil in programming.
      -- C.A.R. Hoare

      More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity.
      - W.A. Wulf, A Case Against the GOTO

      Rules of Optimization:
      Rule 1: Don't do it.
      Rule 2 (for experts only): Don't do it yet.
      - Michael A. Jackson
  70. Small point or two by ewe2 · · Score: 2, Insightful

    Many posters seem to be promoting compilers over learning the nuts and bolts of a particular architecture yourself: somebody had to learn it to write that compiler! Probably a whole bunch of somebodies, because writing a good compiler is a hard task.

    Even then, if you don't understand how your language is compiled, you cannot properly debug your code. With C/C++, it isn't just a case of stack frames, there's memory allocation, pointer dereferencing, etc. Sometimes you need to look at the assembler level to get a grip on some bugs.

    I know from experience that compilers are buggy, don't perform the same way with the same switches on different platforms and while they may optimize generally better than a human, sometimes it's a bug to optimize at all!

    Some appreciation of the assembley level is better than nothing at all.

    --
    insecurity asks the wrong question irritation gives the wrong answer
  71. Counterpoint by AlternateSyndicate · · Score: 2, Interesting
    Ken Silverman is pretty decent with assembly. He's a smart guy and could write very well optimized assembly for his time.

    Every shred of C he's ever written is absolutely unmaintainable. It's just horrible.

    The answer to the question "Is assembly language faster than C?" is the same as the answer to "Is C faster than assembly language?": "No." My point is that there's no magic bullet. The article was not nearly balanced enough to be considered correct.

  72. Re:Not exactly on that not exactly. by Bastian · · Score: 2, Insightful

    You're mixing examples. In the first, we're talking about an interpreted language being written in a compiled language, and whether or not the interpreted language can still be faster.

    You're talking about a program in an interpreted language that spits out machine code. It's kind of like pretending a horse riding a human is the same as a human riding a horse - although the same two animals are involved in both cases, the overall situation is completely different.

    That said, I still say Perl is going to have a darned hard time being faster than C since it has to precompile the program every time it executes whereas a C executable is already in machine code. Not saying it can't happen, just saying a situations where it happens probably aren't all that common.

  73. Re:ARGH by Bastian · · Score: 2, Informative

    I want everyone who thinks this to go out and play the Mac version of Halo. Notice how amazingly slow it is. This isn't because PPC is a slow architecture - this is because the people who ported the program didn't pay attention to the underlying architecture they were porting to.

    I'm not saying everyone has to be a hardcore assembly programmer, but I am saying understanding assembly and the underlying architecture on which you are developing software can make a huge difference. The fact of the matter is, an optimising compiler is not a magic bullet any more than anything else is a magic bullet. The optimiser is great for doing the real low-level instruction shifting type optimizations that a lot of people think are the real optimizations.

    But the optimiser can't help you with poor data structure design, poor memory access patterns, or any other of a host of high-level decisions that still have a lot to do with architecture.

    It's not about hand-optimised assembly anymore, anyway - at least, not if you're working on a beefy architecture with out-of-order execution and all that. But you still need to have a general idea of what kinds of things your particular computer does well and what kinds of things it drags ass on, otherwise you can still end up writing your own little version of Halo PPC.

  74. There's a more fundamental flaw there by Estanislao+Mart�nez · · Score: 2, Interesting
    By passing 10 things, their job is easy. That's all they see. They don't know about registers (other than they exist and are sorta like variables on the CPU). So they don't know that to pass 10 things you might put some in registers but the rest will have to be passed in memory (which is slow) as opposed to puting everything in registers (if at all possible) which is faster (especially for simple functions).

    Passing 10 argument is bad regardless of the performance issues. These students are making a much more fundamental mistake: they're not dividing up the problem properly into easy-to-understand pieces.

    A useful analogy (but don't take it too literally cause I'm oversimplifying it): verbs in natural languages never have more than 3 arguments (subject, direct object, indirect object). If you find yourself crassly exceeding this, you need a justification.

  75. Whats a good place to start? by aToaster · · Score: 2, Interesting

    I tried learning assembly language, but the I can't find ne place that will really explain to me the details of how it works, I'm afraid I don't know enough of the computer engineering side of it to understand the language. Whats a good place to start, wheres a good tutorial or book? Thanks.

  76. I go for clarity first, linecount second. by Gldm · · Score: 2, Insightful
    You can find an example of some of my in-progress code here.


    Of course this is after thinking about the design for awhile. Rarely have I just gone and said "Ok I'm going to code this function now." without thinking "Ok what will this break? What will I want to add in the future and will it mean redoing this a different way?" I spend alot more time thinking about how to get the best flexibility out of a design than actually coding. I tend to think up the data structures first, by figuring out what data I need and what I'm going to do with it. Once I have that, I construct objects around the structures and figure out what methods I need to manipulate them. Everything revolves around the data, not the process. I try to keep the objects segregated on a "need to know" basis so that it's easier to swap out one implementation for another later. I don't want to be sitting forever rewriting the entire project because I've found that quicksort sucks for this data and I'm better off with a heap than a linked list.


    When I actually get around to coding, my first concern is clarity. If I can't read my code, I'm going to be screwed when I have to debug it tomorrow, and totally lost when I need to add a feature or rework something next month. I tend to name my variables and functions for what they are, sometimes with fairly long names. Sure it's a pain in the ass to type cosine_offset and I can typo it alot, but it's a hell of alot easier than figuring out that w stands for cosine offset a month from now. Compilers catch name typos, they won't tell you what the hell you were thinking when you wrote the code. I find the stupid "hungarian warts" where you get names like pfstrqlrdwFOO are absolutely worthless. The only prefixer I use is p, for pointer, because pointer screwups are bad and it's possible to forget something is a pointer and requires different operands. I can usually figure out if something's an int or float or string pretty easy by following the names and what functions it comes from/goes to. GetInputString(myinput) makes it pretty obvious what myinput is, I don't need pcstrz in front of it.


    Having other people able to read your code is a huge bonus. Readability = less time debugging = more time to improve or optimize later. I don't know ASM, but if my code is readable by someone who does, it's alot easier to get them to help me if they don't have to spend a week going "WTF is this variable for? What is the point of this function?"


    Another thing I do that was taught to me by a very realisticly-oriented CS professor is go for low linecount. Outside of clarity, linecount is king. Why? Because fewer lines are easier to comprehend, tend to have fewer bugs, can be easier to optimize (into ASM for example). Functions over 50 lines are rare for me. My functions do exactly one thing that they're named for, I don't group an entire 9 step procedure into a single long function. If I have to do that then it'll be a function calling a bunch of other functions in order. That way when I have a bottleneck, I can just rewrite 25 lines of code instead of poring over 250 looking for where the slow code is and misunderstanding parts of it.


    Granted I'm not the best programmer. I'm probably not even an average programmer around here given my lack of experience. I had a basic course in ASM at college that mostly covered MIPS, and an EE course that covered up through basic CPUs and registers. I know some of the concepts but have never written in ASM. Maybe when I finish the main parts of my current project I'll learn x86 ASM so I can optimize it.

    --

    Introducing the new Occam Fusion! Now with sqrt(-1) fewer blades!

  77. Principles learned while programming assembler& by drolli · · Score: 2, Informative
    Actually programming in jython, java & matlab, some of the principles which i learned while programming on a C128 and an 8051 with 128 bytes and C on linux are the following:
    • Never Copy - if not necessary (be careful with the "=" operator in C++ and other high-level Lang.)
    • Aggregate Information as soon as possible
    • Preserve Locality
    • Save Memory always - your Computer has lots of RAM, but little Cache.
    • Be careful with 2D-Arrays and similar structures and consider the cache organiziation
    • Try to use Regular automata wherever appropriate instead of more complex structures.
    Some more important non-algorithmic ideas?
  78. even better: learn to write a compiler by wdebruij · · Score: 2, Insightful

    as there are already some 400 posts, perhaps noone's going to read this. Still, here's my two cents.

    Randall states that CS students don't learn assembly language anymore, or that if they do, they aren't being taught well. I have to disagree.

    In our CS curriculum (Universiteit Leiden, NL) we had courses that learned us

    (1) how to design a CPU, including ALU, load/store architecture and microinstructions for a fake CPU that interprets (a subset of) the MIPS instruction set. (digital systems design)

    (2) write a compiler from a subset of pascal to MIPS code. The end result had to be tested on SGI Indy's. Present students still have to do this, but need SPIM, since the Indy's have gone, how sad.
    (compiler construction *)

    My point is that our curriculum is arguably representative of the standard CS bachelor, at least in Europe, and that learning everything from high-level languages up to micro-instructions greatly surpasses dabbling with programming in assembly.

    I do agree with his main point though: you should know these things. My feeling is that more people are already acquinted with Randall's dark art than he thinks.

    (*) offtopic: this course was the major stumbling point of half of all CS students. Some handed in the assignments 4 years late, after their final MSc paper.

    It appears that either you are good at the math side and suck at coding or it is the other way around. I did fairly well here, but I won't go into my math ;)

  79. Assembly is bogus by ajv · · Score: 4, Insightful

    I'll give you real hard numbers.

    I look after pnm2ppa, which is a print processor to convert pnm image bitmaps from Ghostscript to PPA, which are HP's worst ever printers. Ever. They are so dumb, they make Bush look like a Mensa candidate.

    When I first came to the code, it was written by someone who thought they knew better than the compiler, and structured the code accordingly.

    We had hand-unrolled loops, unusual and rampant use of the "register" keyword, the occasional volatile, and strange padding in structures to try to align the data to what he thought the processor would use. There were arithmetic "if"'s, nasty pointer usage, throwing away type information (ie casting to void *), and strange methods of going through the data.

    When I hand simplified all the code, it went about 15% faster. In inner loop case, over 100% faster by re-rolling a single inner loop because the person who unrolled it didn't understand how branch prediction worked and even less about large data structure walking and L1/L2 cache interaction. gcc 3.3 improved the performance of the code by about another 15%.

    But you know what made the biggest change? A simple replacement of floating point gamma correction with a lookup table ordered in the simplest possible way. That shaved literally 30+ seconds off every page render on my PIII/800.

    And you know what? The new GLUT is shorter and more readble, and is easier to tune for color correct output. It costs about 4 MB of RAM.

    Assembly has no place in the modern day programmer's skillset. Humans do not know how to schedule instructions properly. They do not know how branch prediction will work unless the data they use is static. They should not waste their time on understanding the difference in L1 cache strategies (which are wildy different in the x86 families and AMD Opterons). They cannot work out how to best keep the data pipeline full on a wide range of processors. But you can help compilers work this out for you by:

    * Design the system in the correct way first time - what do you actually need to do? Don't do anything else
    * Learn and keep up with the best generic algorithms for a wide range of activities (such as sorting, arrays, dictionaries, etc) and keep a library of well tested and bug free examples

    * Write simple, clear, maintable code
    * Never, ever, ever throw away type information
    * Never, ever, ever throw away data aliasing
    * Never, ever, use the "register" keyword
    * Never use "volatile" unless you know why you need it
    * Document tests, data and code properly. This pays off big time every time you come to add new features or fix old ones

    Lastly, program like a software engineer not a cowboy. Code must be correct then fast. Not fast and wrong.

    --
    Andrew van der Stock
  80. What Assembly Is... by cr0sh · · Score: 2, Interesting
    You want to know what assembly is, and how it works, and why? You want to really know how a cpu works? I am going to boil it down here for ya (note, this is the basics - real CPU tech is even further advanced, but this description is good enough to get your feet wet):

    A computer is nothing more than a very fast player piano, and nothing less.

    Simple, huh? But it is understanding this that is key. First off, how a player piano works: there is a reel of paper, the "roll", upon which is impressed, via a series of holes, one for each key, and a few for pedals - the notes which will be played. It is pulled past a row of vacuum air valves by a clockwork or electric motor. This same motor drives the pumps for the air system, when a hole passes, the note is played - how long the hole is determines how long the note is held down for. Other holes determine how long the pedals are held for. The roll of paper unrolls at a constant rate. I believe there were "operator" knobs to set this rate for various rolls, as instructed on the rolls.

    And that is how one of the Victorian-era programmable machines worked. This is all a computer really is. This is how a CPU works.

    Imagine the roll of paper with its holes, each "row" on the roll being one "address" in this very long (but finite) amount of "memory". At each address, or "row" of holes, is encoded an "instruction", consisting of a bit pattern, that is read by the "CPU" (the valve system), which "executes" the command to the rest of the "system" (keys and pedals). Then on to the next "row"...

    This is how a CPU works, and it is how assembly works. The CPU has a bunch of address space, and it is mapped to the addresses to which the memory can be instructed to read or write. The clock on the system causes the CPU to advance states in the system, which increments an address counter, typically called the "instruction pointer" or IP. This pointer is set to a value indicating the starting address of the code. When the CPU is told to "run" the code, the instruction pointer is advanced one address at a time by the clock. At each point, the CPU reads the data at that address. Let's say each opcode in assembly for our fictional CPU is one byte in length. Some of these opcodes say that the next byte might be data, or the next two bytes are data, or no bytes are data (the next byte is another opcode). Each of these codes causes the CPU to read the instruction, switch logic gates via electricity in the electronics so that a logic path changes to read the next bytes as needed and assign them to whereever (other memory, a register, a pointer). Some of these opcodes may be jump (JMP) instructions, in which the next byte or so represents an address to which to set the instruction pointer (thus, unconditional branching). Other opcodes may indicate conditional branching, in which the processing the CPU does for such an opcode reads certain flags, memory areas, or registers, and then jumps (or not jump) to the specified address based on the boolean outcome of the comparison.

    You should now be able to see how stringing a series of opcodes (bytes) and data (more bytes) together, with the CPU stepping through it, electronically and electrically reconfiguring itself to shuffle data (which is represented by electrical logic states, like +5V=1, 0V=0, in electronic circuits - it goes deep, very deep). Name the opcodes according to what they do, and how many bytes afterward are "arguments", and there is how a CPU works, at the basic level. Just like a player piano.

    All the CPU is doing is slogging through a whole mess of bytes and interpreting them to electronically re-arrange itself to perform calculations. There are further refinements of this - my explanation of how a CPU and assembler works is only a very basic one (I can't write a book for ya, can I?). One such refinement (and incrediblely, none other than Charles Babbage implemented a form of it in his plans for the Analytical Engine) is the concept of "microcode". Microcode is essentially assembler for which the CPU is pr

    --
    Reason is the Path to God - Anon
  81. More important to read than write by Diomidis+Spinellis · · Score: 5, Interesting
    It is vastly more important to be able to read assembly code than write it. In most cases this involves reading the code the compiler generates.

    An earlier poster mentioned how such a skill can help you find compiler bugs. This can be the case, but it is rare; I have located two such bugs in 20 years of programming. A more common use is to locate bugs in your code. When your brain refuses to see the missing braces around the wrongly indented code, or an spurious semicolon at the end of an if or while statement, reading the generated assembly code can save some extra hours of frustration. You will be able to see that the code the compiler generates differs from the code you think you wrote, and this will point you to the bug's location.

    As I argue in Code Reading, other cases where reading assembly code can be of use are:

    • to understand how an implementation-defined operation (e.g. a type cast) is actually performed,
    • to see how compiler optimizations affect the resulting code,
    • to verify that hardware-specific code written in C/C++ actually performs the operations you expect, and
    • to learn how a particular construct can be written in symbolic code.

    To read compiler-generated assembly code you need:

    • An understanding of the processor's architecture: registers, instruction format, addressing modes. See for example Intel's Pentium Architecture Manual.
    • A handbook of the processor's instruction set. Again, see for example Intel's Pentium Instruction Set Reference Manual A-M and Intel's Pentium Instruction Set Reference Manual N-Z.
    • An appreciation of how compilers generate code for modern structured languages. The key ideas here are the stack as a way to handle nested function and method calls, the frame pointer as a way to access function arguments and local variables, and the virtual function table often used for implementing dynamic dispatch in OO languages. The Red Dragon Book is the venerable classic here.
    • A way to obtain an assembly code listing of your high-level language code. The Unix compiler's -S switch, and the Java SDK "javap -c" command are two methods I often use. In gdb you can use the disassemble, nexti, and stepi commands to examine your program at the level of discrete processor instructions.

    Obligatory "hello, world" program written in i386 assembly:

    hello: .string "hello, world\n"
    .globl main
    main:
    pushl $13
    pushl $hello
    pushl $1
    call write
    addl $12, %esp
    xorl %eax, %eax
    ret

    Diomidis Spinellis - #include "/dev/tty"

  82. Virus and antivirus... by upside · · Score: 3, Interesting

    In an article I read the CEO of FSecure was quoted as saying the biggest recruitment problem is the lack of assembly language teaching in universities these days.

    I guess it helps if you are in the business of making bugs, too.

    --
    I'm sorry if I haven't offended anyone
  83. 15? Pah! by Dr.Knackerator · · Score: 2, Funny

    Only 15 params? Way back about 94 when I was working at MS supporting Visual C++ I took a call from some plank who was moaning that he was getting an internal compiler error.

    Looked it up. The compiler was failing as there was a limit of *100* parameters. So I told him and started getting all wound up. I asked how many he was trying to pass. it was something like 120 odd. (i turned the mic off and laughed hehehe)

    He asked when it would be fixed. I suggested that as this was the first call ever on this topic it would not be a high priority.

    Customer goes mad and starts saying things like 'how am I supposed to get my work done now?'. I gently suggest that he could put the parameters in a struct and pass that across.

    Customer went dead quiet, thanked me and quickly hung up :)

    BTW if you want to know what torture is, trying having to explain how to use - extern "C" - about 3 times a day for 2 years.

  84. Assembly language is on the way out. by Anonymous Coward · · Score: 2, Informative

    Understanding how a computer works is more important than learning to write in assembly language. In fact, assembly code has simpler constructs than most high level languages. The perceived complexity of assembly language is due to the tedium of programming solutions to even simple problems.

    A good start then is to learn how a computer works by reading "Code" by Charles Petzold or "Computer Organisation & Design : The Hardware and Software interface" by Hennesey and Patterson. With such an understanding you will know "when" to write in assembly instead of high level language. When you ought to write code in assembly, grab an instruction set reference manual for your architecture and/or a tutorial on how to interface C/C++ functions with assembly and you are off.

    Assembly language is surely on the way out. It becomes irrelevant in distributed, cluster or grid computing. How will you optimise if your cluster is made of heterogenous processors ? A variant of the problem has already cropped up with modern processors supporiting different kinds of SIMD instructions leading to messy template switched code. Optimisation then shifts strongly towards choosing efficient algorithms rather than fidding with assembly. In any case, code generation should be the headache of the compiler where its better solved than each application trying to do it on its own.

  85. Pardon me? by pb · · Score: 2, Insightful

    Naturally it's helpful to use libraries in C. However, the 'libraries' I speak of in Perl are actually built-in language features that don't natively exist in C. If you read the post I was replying to, you'll see that the poster was talking about *re-implementing* all of this in C. Naturally it wouldn't have to be re-implemented in Perl, because it's already a part of Perl. And if you used external libraries that you didn't write yourself in C, then you'd have to make sure they were (a) equivalent to Perl's built-in language features, and (b) faster.

    All things being equal, any equivalent program written in C is highly likely to be far longer, more complex, and more difficult to write than the same in Perl--that's because Perl does a ton of things for you, many of which I have already outlined. Of course, if you don't need these features in the first place, it might make sense to write it in C. But given an arbitrary Perl program and then being tasked to write an 'equivalent' program in C... well, it's just going to end up being way more complex. If that Perl program uses eval, you might just have to write an entire Perl interpreter. :)

    Of course this entire line of argument has been ridiculous from the start--Perl and C work together just fine, so you can always use Perl for the rapid development, and C for speed, as needed. In fact, there are tons of Perl modules that just consist of a Perl API to a bunch of C functions, usually for speed, or just to use an existing C API in Perl.

    I know what you mean about being I/O bound--I do a lot of PHP programming. Now, PHP can be an embarassingly slow language sometimes, but that doesn't matter when you're busy waiting on a network connection to a database!

    --
    pb Reply or e-mail; don't vaguely moderate.
  86. IRTA but found it poor by angel'o'sphere · · Score: 2, Interesting

    Hm,

    seems that article is a try to hype the book: "Write Great Code". While some few small trues are in the articel msot of its conclusions are false conclusions ... that bothers me.

    Some random quotes:
    It's all well and good to say, "I'll just find a better algorithm!" However, finding and deploying that algorithm, if one actually exists, is another matter.
    A programmer able to find a better algorithm is also able to deploy it. Why does the author think different there?

    say, going from an algorithm with O(n^2) performance to one with O(n lg n) performance, but the truth is that most of the time a constant factor of two or three times improvement, applied throughout a piece of software, can make the difference between a practical application and one that is simply too slow to comfortably use.
    Hm, isn't that a little contradicting to the authors rant? He argues that the programmers are so poor, they can not even find more efficient algorithms ... and here he says, well its anyway better to just make a factor two or three improvement? See now here:

    Advances in computer architecture have exacerbated this problem--for example, you might hear a programmer say, "If this program needs to be a little faster, just wait a year or so and CPUs will be twice as fast; there's no need to worry about it." And this attitude, probably more than any other, is why software performance doesn't keep pace with CPU performance.


    Ooops: he clearly does not know what programming is about ... He thinks making a program 2 or 3 times as fast makes the difference of successfull or not. But the same approach by using hardware he finds inappropriated.

    Well: but this is the most clear statement that teh author has really no clue how two write efficient software on old hardware:
    Programmers were doing great things with software back in the days when their applications were running on eight-bit 5MHz 8088 PCs; the same techniques they used to squeeze every last bit of performance out of those low-end CPUs provides the key to high-performance applications today. So, how did they achieve reasonable performance on such low-end processors? The answer is not a secret--they understood how the underlying hardware operated and they wrote their code accordingly. That same knowledge, of the underlying hardware, is the key to writing efficient software today.

    Assembly language or C ... thats not a big difference. Great software on those low performing machines where most of the time games. And the games clearly where written in different perspective. No one said: I want it looking like this: make it so. Programmers and game designers where more or less the same persons, so they could write good code yielding good games by experimenting. How if we make thagraphics like this? How does it look and feel? How if do it like this? Remember Doom? Doom was great because the coders found a simplified way of 3D scene generation (raycasting). Thats an algorithm. Thats data. Thats an idea on how to transmorgrify specifications into a program where the product manager does not see that his spec was transformed. Because it looked like he expected.

    Most good programs used two principles:
    a) lookup tables, e.g for sinus values
    b) looking at the requirements from a different perspective, which seemed to behave from the outside like expected, but was achieved in a unconventionel way

    Long after that the geeks started to look at the underlying hardware. Before a) and b) did not happen it makes no sense to check wether LD A, #$00 is faster or EXOR A, A.

    Underlying hardware is the point where you have to fiddel far mroe than just knowing assembler. How do you access a Joystick? Today with DirectX or some other device driver. In my days you wrote to a memory locations. That caused a condensator to be loaded. Then you started to read a second memory location in a loop. The

    --
    Cost free eBook I read (by iBook/Kobo/Amazon/ObookO/Gutenberg etc.): "The Green Odyssey" by Philip Jose Farmer.
  87. For and Against by kreyg · · Score: 3, Insightful

    So, once again everyone is coming out of the woodwork to explain why this article is either right or wrong based entirely on the tiny subset of programming tasks that they actually do.

    For some applications - embedded systems, drivers, games (my specialty), or any other real-time application - assembly is either very important to understand or actually essential. There is (or was) no other way to program the PS2's vector units, for instance.

    For database work, batch or text processing, network admin, or anything else where speed is nice but not a show-stopper, "make it work" is much more important than "make it work fast."

    I've always felt knowledge of assembly makes one a better programmer regardless of the application. Even on a high level, understanding why (unnecessarily) using data types larger than the system's register size is going to hurt performance can only be a good thing. Understanding assembly is fairly fundamental to understanding computers, as opposed to just using them.

    --
    sig fault
  88. After careful consideration... by RetiredMidn · · Score: 4, Insightful
    ..I changed my mind several times and decided I agree with the author of the original article.

    I do disagree on several points that have been raised, but they don't defeat the final conclusion:

    - I do agree that premature optimization has been lethal to many software projects. But I have met as many people who commit PO in HLL's as assembler, so this is not an argument for or against the language.

    - The comparisons of startup times and code sizes with the '80s (the 80's! Why, in the 70's we had only... never mind) are amusing, but uninformative; there are a lot more services embedded in the average OS or word processor today. There is a degree of bloat, but the statistics are misleading.

    - Hand-crafted assembly code is unlikely to be optimal in light of processor pipelining, multiple execution units, and scheduling. I used to know how many clock cycles each instruction in the PDP-11 instruction set would take to execute for each addressing mode; this information is not nearly so useful for today's processors.

    - There are architectural considerations beyond assembly. As early as 1983 a colleague of mine brought a VAX-11/780 (a screamer for its day) to its knees, and came to me complaining bitterly about the processor and/or compiler performance. It turned out that the code in question, which used massive multi-dimensional arrays (in FORTRAN), had compiled into a two-instruction loop (three-operand multiply and an increment/branch), but the code was generating six page faults per iteration! He would not have avoided the problem just by using assembler, but my deeper understanding of the machine led to the identification of the problem.

    All that being said, the title of the article is "Why Learning Assembly Language is Still Good." At the end of the day, while I opt to write in Java (or Objective-C, which I'm just picking up), I am better equipped to write good code knowing assembler, and a few other things behind the language and runtime I'm using.

  89. Re:Assembly or Assembler ?? by TheRaven64 · · Score: 2

    Assembly Language is what you write, and an Assembler is the program which assembles it. It is quite common for people to use the tool to describe the thing (look at all the object pascal programmers who claim they write Delphi, since they write it using an IDE called Delphi).

    --
    I am TheRaven on Soylent News
  90. Assm and Perl by Pan+T.+Hose · · Score: 2, Insightful

    Performance is much more a matter of structure (exponential complexity) than language (poor linear complexity). As to level, "high level" languages limit you to their implementation of a few concepts. Depending on where the heavy lifting is, Perl could easily outperform optimized C.

    Speaking about Perl and Assembly, it is important to mention that there are modern object-oriented assembly languages with asynchronous I/O, events, threads, multiple inheritance, garbage collection, built-in Unicode support, etc. See: Parrot Assembly, and IMCC:

    "IMC stands for Intermediate Code; IMCC stands for Intermediate Code Compiler. You will also see the term PIR which is for Parrot Intermediate Representation and means the same as IMC, but for some each Parrot developer has his favorite term. PIR was the original term, where IMC seems to be the vernacular. It is an intermediate language that compiles either directly to Parrot Byte code, or translates to Parrot Assembly language. It is the preferred target language for compilers for the Parrot Virtual Machine. PIR is halfway between a High Level Language (HLL) and Parrot Assembly (PASM)."

    How Is IMCC different than Parrot Assembly language?

    "PASM is an assembly language, raw and low-level. PASM does exactly what you say, and each PASM instruction represents a single VM opcode. Assembly language can be tough to debug, simply due to the amount of instructions that a high-level compiler generates for a given construct. Assembly language typically has no concept of basic blocks, namespaces, variable tracking, etc. You must track your register usage and take care of saving/restoring values in cases where you run out of registers. This is called spilling.

    "IMC is medium level and a bit more friendly to write or debug. IMCC also has a builtin register allocator and spiller. IMC has the concept of a "subroutine" unit, complete with local variables and high-level sub call syntax. IMCC also allows unlimited symbolic registers. It will take care of assigning the appropriate register to your variables and will usually find the most efficient mapping so as to use as few registers as possible for a given piece of code. If you use more registers than are currently available, IMCC will generate instructions to save/restore (spill) the registers for you. This is a significant piece of every compiler.

    "While it is possible to write more efficient code by hand directly in PASM, it is rare. IMC is still very close to PASM as far as granularity. It is also common for IMCC to generate instructions that use less registers than handwritten PASM. This is good for cache performance."

    For a good introduction to Parrot, read Parrot: Some Assembly Required by Simon Cozens. There is a great article (also on ONLamp.com) Building a Parrot Compiler by Dan Sugalski (I have no idea why it wasn't posted on the Slashdot front page).

    (By the way, for those who read off-line, here is a printable version of the linked Why Learning Assembly Language Is Still a Good Idea article in one piece.)

    --
    Sincerely,
    Pan Tarhei Hosé, PhD.
    "Homo sum et cogito ergo odi profanum vulgus et libido."
  91. Abso-fscking-lutely by whitroth · · Score: 3, Interesting

    A number of years ago, while I was working for a Baby Bell, we were building a system, and integrating it with BEA's Tuxedo. One day a couple of the consultants came to me, to tell me that it was crashing, and they couldn't figure out why.

    I pulled it up in the debugger (a Sun box), and stepped through the code...and, when I found it was crashing in Tuxedo, I did something the consultants (young guys) had no clue you could do...I stepi'd *into* the binary.

    Now, I didn't know Sun assembly language, but that was irrelevant. I nexti'd and stepi'd my way through, and found the name of the function it was crashing in, which will *always* be there, even in a stripped binary, and where it was doing it in the function.

    I could then call BEA (I was senior technical, and Rank Hath Its Privileges), and get info from their developers.

    Turned out to be the environment, not a bug, but the point is, once in a while, *knowing* what how things work Down There will save your butt, and maybe even lead you to better code.

    mark "and I pushed my kids to know what
    happens under the hood of the car, too"

  92. Why C isn't always fastest by Anonymous+Brave+Guy · · Score: 4, Insightful
    But if Perl is written in C, wouldn't that mean that Perl can never be "faster" than C?

    Superficially, that seems an obvious truth, but it doesn't necessarily hold in practice for several reasons:

    • By definition, high-level languages have more expressive features than a glorified assembly language. Those features allow the programmer to express certain concepts directly, in a form whose semantics that the compiler can understand. That in turn may allow the HLL compiler to optimise the output code it produces in a way that the LLL compiler couldn't. Consider the number of optimisations that no current C compiler can perform because of the risk of variable aliasing, which simply can't happen in some high-level functional languages because effectively there are no variables, only immutable values.
    • Moreover, in practice, pretty much nobody goes to the effort to implement an optimised high-level language feature in a C program unless they're writing a compiler for that HLL anyway.
    • Finally, there is the issue of run-time optimisation, which is to an extent just a variation on the themes above. So-called just-in-time compilers can potentially look at the run-time behaviour of a program, and dynamically adjust the executable code to better handle what is really happening, with the real data being provided. How else do you think an overweight beast like Java now gets performance at least comparable to the C and C++ world? Since no compiler can ever know what real data will be provided, the only way to achieve this effect in a LLL like C is to write your own virtual machine, and effectively create your own new language with a JIT compiler. Not a lot of projects do that, because it's insanely complicated.

    In other words, with today's compiler technology, and more importantly today's run-time environments, C is no longer automatically the king of performance, and it is both theoretically and practically possible for much higher level languages to outperform even hand-optimised compiled C code.

    Of course, the price you pay is the initial overhead for the JIT compilation process, usually when a program first loads. However, this is one area where rapidly increasing hardware speeds really tells, because that directly reduces the overhead of that bootstrapping process, so the field of more level the faster hardware gets.

    I expect traditional, compile-only technologies to fade into the background over time; in the programming language "performance vs. safety+power" spectrum, they aim at a target nobody will need to hit any more. There will always be a need for LLLs, if only to write the underlying platforms to support HLLs, but for regular application development, their days are numbered.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  93. I agree, kinda by nicnak · · Score: 2, Informative

    I have seen to many people wasting their time reordering code and coming up with obscure ways of doing an if statement that might use a few less cpu cycles.

    But I still think inorder to program efficant code you still must know assembly. The best courses I took were about compliers. This lets you know exactly how the compiler will optimize that assembly you know, so you know what is worth optimizing in a high level language.

    For example, a lot of the things people do like rearanging local variable instanciation has absolutly nothing to do with how the machine code is actually written. The first think a compiler does is translate your code into a meta-code that has the exact same syntax style everywhere. All the variable declarations are moved to the front, every for, while, and do-while is turned into a while. All the code is normalized into a functional equivalent.

    Then the code is optimized, if statements may be turned into the logical opposite, extra variables will be eliminated, code will be rearranged to increase parallel processing.

    If you write code with this in mind you focus more on the important problems, like is this loop n-squared or just n.

    But in-order to know what to optimize in code you still need to know assembly.

    -nicnak

  94. The Doctor Analogy by invid · · Score: 2, Insightful

    Being a programmer and not knowing at least the basics of assembly language is like being a doctor and not knowing what a cell is. Depending on your specialty, you can get by all right about 99% of the time, but if you hit a problem that stumps you, you won't be able to delve deeper into it because you won't know how. A deeper knowledge gives you insights, because where the rubber hits the road, it's all bits turning on and off in registers. If you don't understand what those bits are doing then it might as well be magic and it's time to break out the prayer beads.

    --
    The Moore-Murphy Law: The number of things that will go wrong will double every 2 years.
  95. I disagree that assembler is faster than compiled by HankB · · Score: 4, Insightful
    We evaluated assembler vs. C for an 8086 hosted system about 15 years ago. We looked at several compilers and wrote some simple functions in C and assembler to compare the code generated. The best compiler (Watcom) produced code that was tighter then the hand coded assembler. The compiler did things with the code like sharing parts of a return block and optimizing register usage in ways that would make maintaining the code extremely difficult. With more complex chips, I doubt that a human developer could track all of the details required to produce tight efficient code.

    In theory, a really good assembler programmer could produce more highly optimized code, but not on a consistent basis and within schedule constraints.

    I don't argue that assembler isn't useful. I learmed more about how computers work wwhen I took an 8080 assembler class in college. And for certain problem domains like embedded systems, assembler is often necessary. But I don't write any more code in assembler than absolutely necessary.

  96. I think that's pretty much completely wrong by arevos · · Score: 2, Insightful

    The majority of 3D optimisations is deciding what not to draw. Quadmaps, octrees, BSPs and so forth, are all techniques for quickly discounting large areas of polygons. The bottleneck of most 3D games is the drawing of the display. You may, perhaps get 1% or 2% improvement using assembly, but I doubt it. Today, compilers can optimise code pretty well. There's little difference in raw speed between C and assembly.

    In addition, games don't just compete on framerate. Games have to be very, very, very stable. If a word processor crashes, people seem to be able to live with it. If a game crashes just as you were about to rack up a new hiscore, then the player is going to be very cross indeed. The more assembly is used, the more unstable the game is likely to become.

    Thirdly, there's the difficulty of time. Assembly would obviously take more time, for benefits that are pretty much negilible. Coding inner loops in assembly really wouldn't improve framerate by any great degree, and would just contribute to the overall expense and instability of the system.

    There's no problem knowing assembly. In many cases, understanding how computers work is very useful. But coding in assembly on modern PCs/consoles, even for video games, isn't likely to have very good results.

    3D optimisation is all about having good algorithms. Case in point; I designed a 3D, OpenGL demo in C++. I then designed a similar demo in python. The one in python ran much faster, partly because I knew what I got wrong on the C++ demonstration, but mainly because in python, I could code better optimisations (various frustrum culling and octrees were the main ones), in a much shorter space of time.

    In C++/SDL I had to write algorithms for taking a bitmap and converting it into an array, and then creating a heightmap. In python/pygame, image loading was done for me, and creating a heightmap was quite simple. The rest of the time I used designing an octree interface for my terrain.

  97. Re:"Premature optimization is the root of all evil by Vexar · · Score: 2, Interesting

    Randall Hyde regularly said that in his Assembly Language courses. Be aware that there are still occasions when Assembly is all you get, like embedded systems.

  98. invaluable by Anonymous Coward · · Score: 4, Interesting

    I was reading hex dumps and hand coding small assembler routines in high school (read: 24 years ago), and its been an invaluable skill over the years. I've written 'C' programs that call assembly routines to access OS functions that no routines existed for, understood how parameters got passed on the stack so when something got corrupted I could look at a hex dump and figure it out within minutes.
    I took the TCP/IP software for an old minicomputer at my old job, licensed to the particular CPU, and figured out how to defeat the licensing so it'll run on any machine... all with no source, just by decoding/hacking the assembler and changing a few BNZ (branch Not Zero) to straight branches. I've played with building my own boards, and writing drivers for them.

    From the standpoint of knowing how things work.. having the base knowledge of how the underlying hardware works, I can pretty much pick up any language on the fly.

    I had a guy recently who I had to explain why:

    status="green";
    if (result1 >= 0) status="red";
    if (result2 >= 0) status="red";

    was better than:

    if ((result1 >=0) && (result2 == 0)) status="red";
    else if ((result1 == 0) && (result2 >= 0)) status="red";
    else if ((result1 >= 0) && (result2 >= 0)) status="red";
    else status="green";

    no concept of the difference in 6 compares & 3 logical and's, vs two compares. Not that his way wouldn't work.. but *efficiency*. In a lot of ways, in my mind, mastery of assembly language can bring great insight into the *best* way to accomplish something.

  99. Cart Before Horse by jefu · · Score: 3, Insightful
    I agree that knowing how to code at the assembler level is often the hallmark of the best programmers.

    But I'd turn the premise around - I think that the best programmers learn how to code at the lowest because they want to and are interested in it. Then they learn about both the benefits and complications (pipeline stalls, cache effects...).

    But on another level, teaching assembler in college is increasingly difficult. Students in many CS programs are hard pressed to learn much more than Java and C# - very few know any language other than those in the C/C++/Java/C# family plus Perl and Python. Instead they learn all about GUI's, IDE's, .NET and so on.

    I'd love to see students really learn assembly language (though ideally it would be for something other than the plug-ugly x86 series architectures), but then I'd also love to see them learn Lisp, Haskell and a few more languages, as well as Unix, Windows, VMS and a few more OS's, as well as HTML, XML, TeX and a few more ways to mark up information, as well as OpenGL, Postscript, X windows library calls and a few more graphics systems, as well as Calculus, Linear Algebra and a bit more math, as well as.... (well, you get the idea).

  100. What assembly should be used for by Haydn+Fenton · · Score: 3, Insightful
    I spent some time learning assembly, simply because I wanted to. I found out how EXTREMELY fast it can be (If you've ever used REGEX - the engine is written in assembly - you'll know how much faster it is compared to string functions, in any language).
    However, I think the only times assembly is really needed is (in a few cases, C++ will do the job almost as well):
    • Cracking - Obvious reasons, you'll need to know how to program in ASM to know whats going on in programs, and therefore how to 'crack' them.
    • Kernel/Other core file development - Again, pretty obvious. Apart from the fact you can't really write kernels in VB and whatnot, you will want these files to be as fast as possible.
    • Graphic-Intensive games - Again, you want the game to run as fast as possible, you'll maybe get 60 fps if written in ASM, compared to about 10fps if written in VB.
    • Virus writing - polymorphic viruses, for example, if you want the program to actually change its contents when a virus scanner checks it, writing it in VB or something will quite a bit more than challenging.
    There are probably other cases too.
    I think it IS important to know how computers work - as in the CPU, registers, etc. But in most cases, it's simply not needed.

    If you want to optimize, you can learn how to optimize code in your own language. For example, 2 * 2 * 2 will be about extremely faster than 2^3. StrComp() type functions are faster than If (UCase(string1) = UCase(string2)), etc.
  101. Efficiency is not the biggest problem by Khelder · · Score: 2, Insightful

    I completely disagree with Hyde about the importance of efficiency. Sure, I'd like apps to be smaller and faster. But 99% of the time, what I want to be improved in apps I use are:

    * Usability
    * Security
    * Learnability

    As a developer, I also rarely care about efficiency. I'd much rather developers spent more time making their code:

    * Readable
    * Maintainable
    * Debuggable

    I also agree with other comments that even if you think efficiency is important, assembly by itself does not help very much in understand what's efficient. That's because so many other factors besides the lines of code impact how your program runs, such as:

    * Compiler and runtime environment (e.g., JVM)
    * OS implementation (e.g., scheduler, virtual memory management)
    * CPU architecture (e.g., pipeline, cache, superscalar execution)

    Would knowing assembly be better than not knowing it? Sure. But considering all the things that it would benefit a programmer to know, how important is assembly? For the vast majority of applications out there, I think assembly is not nearly as important as many other things.

  102. Modern processors and FFT algorithms by Latent+Heat · · Score: 2, Interesting
    Much has been said about a good algorithm being better than a hand-coded loop.

    When the FFT came out, a lot of effort went into cutting down the number of arithmetic operations -- eliminating "trivial" operations like multiply by 1, multiply by 0 and add, as well as they higher radix butterflies (radix 4, 8, 16). The simple radix 2 FFT given in many DSP texts was offered as a "teaching example", but "production" FFT programs were complex masses of FORTRAN code that attempted to identify all the optimizations.

    In my own experience, the simple radix 2 FFT is best for the modern x86 where as you say x86 is just an API to a RISC core. The minute you start putting in the optimizations, you need additional loops, branches, and tests, which trip up the pipeline. Arithmetic ops are fast compared to extra loops, branches, and tests, so the old mainframe FFT subroutines were optimizing the wrong thin.

  103. Gibson Research by bluyonder · · Score: 2, Informative

    For more on the joys of Assembly programming, you should go see Gibson Research.

  104. one size fits all? by cybpunks3 · · Score: 3, Insightful

    Sometimes programmers can be a little smug in assuming that every other programmer is working in the same environment that they are and therefore they take their hard-earned wisdom from their particular niche and evangelize it to everyone else. Sometimes that evangelism borders on a geek-version of adolescent bullying as we try to put-down or shame everyone else for not doing things just as we do.

    The profession of programming has broadened to the point where it is IMPOSSIBLE to advocate a one-size-fits-all mantra to all programmers.

    Computers have become so ubiquitous and the things they do so broad that the profession itself has splintered into many different subcategories each with their own INDIVIDUAL best practices.

    So I think anyone trying to advocate a way of doing things should always qualify it by specifying the environment that they think suits it best.

    The way someone writing code for a PIC is going to approach it differently from a device driver who is going to approach it very differently from a web programmer writing C# code to deliver web pages or a game programmer doing real-time graphics or someone writing an embedded app who is concerned about battery life or a missile guidance system or medical instrument who is concerned about stability.

    That's not to say that there aren't any universal best practices, but everything is a cost-benefit assessment. There are cases where the time investment in the optimization will not payoff with a measurable increase in efficiency that actually helps the bottom line to any degree. Ultimately the best programmers are those who are able to satisfy BUSINESS needs, not just thier own perfectionism.

    This is true of just about any form of creation. Someone building a cookie-cutter apartment building approaches it differently from the replacement World Trade Center or a tent or a treehouse. Take artwork. A comic strip artist is not going to lavish the same amount of detail on his daily strip that went into the Sistine Chapel. The work that goes into creating a Hyundai is different from what goes into a Bentley or a Hummer or a tractor or a motorcycle.

    Always customize your approach to the niche you're in.

  105. C++ Options by sorbits · · Score: 2, Interesting
    If you happen to use C++ you'll probably have to shell out big bucks for a linter or be out of luck because there are only commercial linters available.

    What I generally do is overwrite new to place a 64 bytes marker before and after the memory block, which is then checked during delete, and will exit with a stack dump (and a hex dump of the block) if corrupted.

    At exit I dump all blocks not deleted (to catch leaks), and I litter my code with asserts (which also do stack dumps) plus have a printf-kind of system, where the level of output can be toggled (often at run-time, if the application i am working on has a user interface (I have a debug-menu component which I just link on my application)).

    Due to all the run-time checks, I generally catch mistakes the minute I make them -- I have debugged/resourced lots of other programs and have also programmed in assembler, so it's not a skill I lack, but I honestly never have a need to debug my own programs (except when the compiler produce the wrong instructions, but this is mainly just looking at the assembler output, rather than using the debugger).

    My memory system doesn't watch for stack-corruption. This however never really happens, because I only place objects on the stack or const arrays -- if I need a mutable array I use std::vector

    I also define _GLIBCXX_DEBUG, which turns on all sorts of sanity checks in the standard library.