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)."

667 comments

  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 Junta · · Score: 1

      That's 'l337ism' for you.....

      --
      XML is like violence. If it doesn't solve the problem, use more.
    4. 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...

    5. 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.

    6. Re:Because you can kill any 2.6.x kernel by pklinken · · Score: 1

      Hmmyea i started with assembly trying to kill my 8088 dos box for a while.. that wasnt too challenging ;)
      5 years later i had to optimize mips assembly at university..
      To be honest assembly seems to be pretty straightforward in general and i imagine it to be that to any academic..

    7. Re:Because you can kill any 2.6.x kernel by kmcmartin · · Score: 1

      I think you mean any x86 Linux machine. No other architectures are effected, obviously.

    8. Re:Because you can kill any 2.6.x kernel by netdaemon · · Score: 1

      This doesn't affect NetBSD Stable. It just throws a floating point exception when you run it.

    9. Re:Because you can kill any 2.6.x kernel by TelJanin · · Score: 1

      Perhaps because that's NetBSD, and it crashes Linux?

    10. 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.

    11. Re:Because you can kill any 2.6.x kernel by Alioth · · Score: 1

      It also apparently doesn't crash user mode Linux kernels; I'm using 2.6.5-1um on an x86 host, and it didn't crash that.

    12. 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.
    13. 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.
    14. Re:Because you can kill any 2.6.x kernel by josevnz · · Score: 1

      Greetings,

      Not so sure about how useful is to known assembler these days; A good design and a good compiler should be able to get the job done. And if performance is super critical chances are that you can buy a faster equipment to replace the old one instead of dealing with hard to maintain code.

      I haven't read the book (and I'm not an expert with assembler, only the basics) so it could be interesting to know on which cases assembler is definitely the best option (like systems with small memory footprint for example).

      Regards,

      JV.

      --
      Jose Vicente Nunez Zuleta RHCE, SJCD, SJCP
    15. 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.

    16. Re:Because you can kill any 2.6.x kernel by ceswiedler · · Score: 1

      I didn't misquote. If you look at the OP's reply to my post, you might notice that he changed the text of the site after my post.

    17. Re:Because you can kill any 2.6.x kernel by jayminer · · Score: 1
      So try this infamous code on a Windows NT kernel. (WinNT,2k,XP etc.) I don't know if it has been yet fixed
      #include <stdio.h>

      int main (void) {
      while (1)
      printf ("\t\t\b\b\b\b\b\b");

      return 0;
      }
  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 vontrotsky · · Score: 1

      Sooner or later, you'll need to debug something without a source-level debugger.

      printf?

    3. 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.

    4. 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.

    5. 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.

    6. Re:Debugging by Profane+MuthaFucka · · Score: 1

      How about plain old bragging rights? New programmers should read the story of Mel and get INSPIRED to learn assembly.

      --
      Fascism trolls keeping me up every night. When I starts a preachin', he HITS ME WITH HIS REICH!
    7. Re:Debugging by Anonymous Coward · · Score: 0

      Got a link to that story?

      I could do with some inspiration.

    8. 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!
    9. Re:Debugging by Anonymous Coward · · Score: 0

      Real Programmers use Google!

    10. 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.
    11. Re:Debugging by homeobocks · · Score: 1, Funny

      "Learning how to debug is just as precious to a programmer as learning how to code." That's nonsence. helloworld.cc worked the first time!

      --
      MOUNT TAPE U1439 ON B3, NO RING
    12. 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.

    13. Re:Debugging by PacoTaco · · Score: 1

      So I guess that means it's not ready for release yet.

    14. Re:Debugging by Anonymous Coward · · Score: 1, Interesting

      >

      ++(char *) 0xb0000; // in
      --(char *) 0xb0000; // out

      Not printf(), but hey, it uses the (monochrome) text screen...

      >

      (Holds AM radio next to motherboard, listens to the bits going by)

      >

      Oooh, those are the worst.

      >

      Use SmartHeap.

      >

      Those are pretty much axiomatic at this point.

    15. Re:Debugging by eidechse · · Score: 1

      Hehe...one would hope...although there are a lot of "if it compiles it must be ready" shops around.

    16. Re:Debugging by Methuseus · · Score: 1

      The problem comes when the advertisement is sort of blurry and doesn't tell you *exactly* what will happen.

      --
      Two things are infinite: the universe and human stupidity, though I'm not yet sure about the universe. - A Einstein
    17. Re:Debugging by Cuthalion · · Score: 1

      Pretend that he said "C that was optimized by someone who has finite time".

      --
      Trees can't go dancing
      So do them a big favor
      Pretend dancing stinks!
    18. Re:Debugging by Radius9 · · Score: 1, 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? And if I did, wouldn't that mean that Perl can't ever (theoretically) be faster than C?"

      Not exactly. If I was able to write an assembler in BASIC, it doesn't mean that BASIC runs as fast as assembly language.

    19. 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.
    20. 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.

    21. 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.
    22. 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.
    23. Re:Debugging by UncleFluffy · · Score: 1, Insightful

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

      An extensive logfile, and intelligent use of grep/awk/etc to analyse the behaviour of the system over time ?

      Leastways, that's what I do...

      --

      What would Lemmy do?

    24. 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.

    25. Re:Debugging by Have+Blue · · Score: 1

      Not exactly the same thing. What the parent suggested was writing a program in C that precisely duplicates the operations of the Perl interpreter processing a particular program, which should perform identically to the real Perl interpreter loading the program, parsing it, and then interpreting it. The BASIC assembler would produce identical output to the C assembler, which would execute by itself at the same speed, but that wouldn't prove anything as there would be no BASIC code involved when you executed the generated binary.

    26. Re:Debugging by Percy_Blakeney · · Score: 1

      You're completely right. The underlying point was that arguing for Perl because it can be "faster" than C is bogus; high-level, interpreted languages weren't built with speed as the competitive factor. They were built for maintainability and speed of development, with execution speed being secondary.

    27. Re:Debugging by Ninwa · · Score: 1

      Incase anybody cared it turned out that I was reading a non 0-terminated char array and that's what was causing all of the garabage.

      D'oh!

    28. 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...

      --

    29. 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.

    30. Re:Debugging by Feztaa · · Score: 1

      Mel, The Programmer

      Definitely a worthwhile read.

    31. 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.

    32. Re:Debugging by abreauj · · Score: 1
      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.

      I believe he meant that it took one second to write the perl one-liner, and one year to write the C code for a perl interpreter (or subset of same) that would execute that one-liner. In which case he was making precisely the same point you describe as "moot".

      He was, after all, responding to the assertion that you could in principle write your own perl interpreter subset in C to implement the same program.

    33. Re:Debugging by Anonymous Coward · · Score: 0
      The underlying point was that arguing for Perl because it can be "faster" than C is bogus;

      This is currently correct as Perl is currently implemented in C, however, there are optimizations that you can perform on Perl code which you cannot perform on the equivalent C code (simply because translating Perl to C is a lossy transformation). Therefore, it might be possible to achieve higher performance in some cases using Perl over C (if some parts of Perl were implemented in a more 'optimization-friendly' language).
    34. 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.

    35. 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.

    36. 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).

    37. Re:Debugging by LWATCDR · · Score: 1

      "Depending on where the heavy lifting is, Perl could easily outperform optimized C."

      This statment makes no sence at all. Perl is writen in C! If the code of a tasks is optimized to the same level as the Perl is optimized then it should run at least. I should run faster since perl is a general purpose tool and the c program would be specific to the task.

      Now in the real world it is very possible that perl is so well written it would take a very good programer a lot of effort to beat it. Just as in the real world a c compiler might be so good that it is hard to beat in Asm.

      --
      See my blog http://ilovecookes.blogspot.com/ for light hearted technical information.
    38. Re:Debugging by invid · · Score: 1

      Seems like an awful lot of work. It's much easier to set a break points and step through the code. Log files are good for some types of bugs, but I don't resort to them until after I've tried stepping through.

      --
      The Moore-Murphy Law: The number of things that will go wrong will double every 2 years.
    39. Re:Debugging by gauchopuro · · Score: 0, Flamebait

      Of course, this whole thread is irrelevant, because it assumes that it's possible to actually read that Perl program.

    40. Re:Debugging by p3d0 · · Score: 1
      The argument changes if you consider programmer effort. C easily outperforms ASM on large programs because to match a decent optimizing C compiler with hand-coded ASM would make the project too expensive to be feasible, especially if developing for multiple target platforms.

      To me, that's a much more relevant discussion than whether one language is more "powerful" than another in some abstract theoretical sense. When discussing a language's expressive power, I like to make an analogy with physics, where power is work divided by time. Thus, if a language can allow a developer to do the same work in less time, that makes it more powerful.

      --
      Patrick Doyle
      I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
    41. Re:Debugging by Anonymous Coward · · Score: 0

      And reading heavily optimized C code to do complex regular expressions instead of the m// nomenclature would be any easier to read?

      And no using yacc/bison, either, that's cheating.

      I'll take my 20-line perl mess (that an experienced perl coder can read) over a 2000-line hand-coded highly optimized regular expression engine any day (unless it was life-or-death real time parsing or something). My time is too valuable to re-implement the wheel to save a few microseconds.

    42. Re:Debugging by damiam · · Score: 1

      I thought about that, but since you can't write a Perl prog in one second, I figured if that's what he'd meant then he would've chosen times that made more sense. Maybe not. :-)

      --
      It's hard to be religious when certain people are never incinerated by bolts of lightning.
    43. Re:Debugging by ufob_ceo · · Score: 1
      "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."

      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.

    44. Re:Debugging by Anonymous Coward · · Score: 0

      The parent and grandparent posts are both right. printf statements can be very powerful debugging tools and can fix 98% of problems. I typically encapsulate small sections of code, e.g.
      printf("1");
      ... //code here
      printf("2");
      If the program dies and the last character printed was a "2", that section is fine. Otherwise, if the last character printed was a "1", I narrow the encapsulation, to find the core problem. However, the grandparent is also correct about stacks. What if you write past an array, and the section of code you encapsulate the crash in, has no reason to fail, because that code was correct? It becomes incredibly complex to try and find exactly what line of code is writing outside of your array using print statements, especially when you don't even know which function the problem is in?
      Still, low level debuggers could do such a better job by generating better debug level code, exporting symbols that the debugger could import, etc. Even visual c++'s debugger is terrible for trying to find problems.
      Example:
      00401256 mov eax,[00127639+ebx*4]
      With nothing but code above and below. You don't know what variable is at 127639, you don't know what ebx was representing, you don't even know what function you were in. So how do you expect to find out how or where that bad memory read got in your application?
      And when it drops you right into a kernel32 function that failed, there's no way in hell you're going to be able to use any of that info to your advantage.

    45. Re:Debugging by Anonymous Coward · · Score: 0

      Breakpoints to detect race conditions and deadlocks are completely useless in multithreaded programs. Either get a tools that explicitly detects such conditions or use extensive logging as the parent poster suggests. And yes, it's an awful lot of work to do something right. Doing something half-assed is easy.

    46. 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.

    47. Re:Debugging by AndreyF · · Score: 1

      Selling software wont make you money, selling a service will.

      Yeah, that's why Bill Gates is actually a bum disguised as the richest man on earth.

    48. Re:Debugging by AndreyF · · Score: 1

      PS. I know he's not the richest man anymore, but he's still damned rich :)

    49. 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
    50. Re:Debugging by Anonymous Coward · · Score: 0

      7) Big mac fries to go

    51. Re:Debugging by Tony-A · · Score: 1

      This is currently correct as Perl is currently implemented in C, however, there are optimizations that you can perform on Perl code which you cannot perform on the equivalent C code (simply because translating Perl to C is a lossy transformation). Therefore, it might be possible to achieve higher performance in some cases using Perl over C (if some parts of Perl were implemented in a more 'optimization-friendly' language).

      Like Perl?

      And now if the Perl program performs these optimizations on itself, ...

      Functional Programming has one very big thing going for it. Composition of functions is associative, but the different associations can have orders of magnitude differences in efficiency. A little bit of functional programming in "normal" languages can give some remarkable advantages.

    52. Re:Debugging by UncleFluffy · · Score: 1

      Seems like an awful lot of work. It's much easier to set a break points and step through the code. Log files are good for some types of bugs, but I don't resort to them until after I've tried stepping through.

      I agree, stepping through is easier, and it's great for bugs that involve the behaviour of a single thread of execution (though it is still a lot easier to rewind a logfile). When the bug is in the interaction of multiple subsystems (which covers most of the code I write), then single-stepping isn't going to get you very far.

      The right tool for the right job, and all that...

      --

      What would Lemmy do?

    53. Re:Debugging by nate+nice · · Score: 1
      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.


      I agree mainly, in that I often use printf or cout or whatever std output functions the particular programming language makes available but one thing you have to be careful about is, in as you were mentioning, multi threaded programs. Using printf type functions will not always work correctly because as the current thread waits for the IO device, it is put into waiting mode generally and another thread will take it's place as the executing thrad. So, if you are using printf, your program may be taking a break before an important piece of code that is causing the probems only when thread 'a' executed it before thread 'b' but since 'a' is preempted or waiting because of an early I/O command, 'b' runs when it should not and all hell breaks loose. Then again, multithreaded programming has many pitfalls, but just be careful when using an I/O command that will preempt a thread to check for many types of errors. They don't always allow multithreaded programs to execute in a realistic fashion. But then again, a multithreaded program should be able to change threads at anytime and run correctly, prohibiting specific instructions to wait, etc.

      --
      "If you are a dreamer, a wisher, a liar, A hope-er, a pray-er, a magic bean buyer ..."
    54. 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. ;-)

    55. Re:Debugging by Anonymous Coward · · Score: 0

      You all may want to give boundchecker a try. Its fairly good at finding that 'memory' overrun. Even pretty good at finding leaks. With templates I have found it to be fairly wacked out. But normal C/C++ stuff it works very well. I can count on 1 hand the number of times I have got it to mess up. I am sure the newer versions are much better?

      As for me things by the time 00401256 mov eax,[00127639+ebx*4] is showing up its WAY too late. The code was wacked out usually way way way before that. printf'ing will NOT find your problem. You need to do as a programer I work with says 'quit your bitching and LOOK for the problem'.

      Its even fairly easy to find. Look for any arrays that are being used. Look for any pointers that are being used. Look for any variables being passed in or out. Its tedious I know, but if you just LOOK at the code you will see it. 99% of the time I can walk through the code with the debugger and have something like that cleared up in a few hours. It is all a matter of WHO is using your data. Do they really have access to it? Should they really have access to it? Are they starting somewhere where they should and going off somewhere where they shouldnt. Treat your code like a 2 year old that is getting into everything and you will live a lot better.

      Also you all need to learn how to turn on debugging symbols in visual studio. By default for RELEASE builds its off. Either turn it on for your release builds or make another project that is release like and has debug turned on. You will clear up that 'can not figure out what function I am in'. Also pry open your wallet spend 500 bucks and buy the debug checked build of NT/XP/2k/2003. Even if you do not want to do that INSTALL the debug symbols for your OS. MS provides them at NO charge. You will never find yourself lost again.

      Also KNOW your tools. The MSDN docs are rather good. Experiment with your tools. Be they GNU stuff or MS stuff or whatever. Know what they are and are not capable of. Google around for things. You will find there are a few thousand other people just like you out there doing the same sorts of things. A few have even already solved your problem.

      With Visual Stuido the only thing I find that is really 'broken' is the way they manage the project. It has a tendancy to crash the whole IDE. Which is a pain. But the rest of it works VERY VERY well. I have used a lot of debuggers and IDE's over the years. I am actually fairly impressed with MS's stuff in this regard.

      Let me give you an example. Where I work we have 2 pieces of code that do the same thing. One in DOS one in win32. Now the dude who does DOS always uses the 'printf' method. I use the debugger method. I almost always beat him in finding what is wrong with the code? Why? Because I can peak in to the code and watch what code is getting exacuted. He has to 'guess' and 'intuit' his way to what is going.

      Now I am not say printf is bad. I am saying if its all you do you will be forever 'guessing' what its doing. You will never be able to say 'YES' it is doing something wrong. You will not be able to say 'Yes I have it fixed'. Now does tracing through it always get you the 'yes i have it fixed'? No but it gets you there a lot more often. Also the best thing I think MS ever did was that tooltip so you can see what a variable is. It is awsome for seeing uninitalized vars or stuff like that. The sort of thing a 'stray' pointer is made of. You can even configure visual studio to 'peak' into your own structs and give nice tooltips. How cool is that?

      I usually find the people who bitch about their tool are not very good at finding the problems. They are MUCH better at bitching about it.

    56. Re:Debugging by Pseudonym · · Score: 1
      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.

      Or you could have added 20 extra features and squashed 10 bugs in the Perl program, any one of which would have required rewriting large slabs of the C program in order to maintain the same performance.

      Higher-level languages tend to be able to maintain performance (whether that performance is good or bad) in the face of maintenance, where a C or assembly program cannot.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    57. Re:Debugging by ufob_ceo · · Score: 1

      I agree that detailed logging in the proper places can be a helpful debugging aid, but I've seen far too many people for whom it's the only tool at their disposal, which is unfortunate

      As an aside, I've long since given up on using devenv for anything other than verifying problems that I'm already 99% sure I've nailed down, and then only in development. It doesn't hold a candle to windbg when in comes to post mortem debugging. I really wish devenv and windbg would expose the same feature set. I can't count how many times I've put .cxr in a devenv immediate window and then scratched my head when the context record didn't pop into existence :-)

    58. Re:Debugging by Bob+Uhl · · Score: 1
      In the case of Perl, which is an interpreter, the answer is theoretically yes. But one needs to consider: will one's C code be as fast as that of the fellows who work on the Perl engine?

      But in the case of compiled code, the answer is no. The compiler can be written or bootstrapped in whatever language: all that matters is the quality of the generated code. And it happens to be the case that high level code can be very easily optimisable, and thus can run faster than low-level code. Slower, granted than pure, omniscient-programmer assembler, but faster than realistic C code.

    59. Re:Debugging by Bob+Uhl · · Score: 1
      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?

      Fewer damned parentheses, I suppose:-)

    60. 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
    61. Re:Debugging by llefler · · Score: 1

      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.

      And yes, I've worked in C, C++, and Assembly (sys 360), as well as CoBOL, RPG II, and BASIC. Although I choose not to use any of them right now.

      --
      It is amazing what you can accomplish if you do not care who gets the credit. -- Harry Truman
    62. 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".

      --

    63. Re:Debugging by Anonymous Coward · · Score: 0

      This is more of that application-level perspective, but I find the most useful feature in gdb is the print command. The most useful thing about a debugger isn't necessarily that you can step through code, or set breakpoints, or any of that, but that you can poke around memory, maybe step forward a few lines to get the change in memory contents, not necessarily to follow the program flow (which is clearer to read in an editor in most cases anyway, unless you have some odd block structure/looping typo).

      Basically, a debugger lets you write print statements on the fly. If being able to quickly cobble together one-offs is such a virtue in high level language, then why not in debugging? I usually treat gdb more like a C interpreter to evaluate small expressions than a sequential debugging tool for debugging control flow.

      Sure, you can do much of what a good debugger will do using a zillion print statements, but that's a lot of work to track down, for example, a typo. There's some benefit of keeping those zillions of statements for future debugging, but not in keeping all of them. And then you have the heisenbug issue, where introducing print statements changes the bug behavior.

      Basically, a basic debugger will let me fix in a few minutes of inspection what might usually take me a magnitude longer of staring at code and scratching my head, trying to find missing semicolons or what not. Instead of recompiling my code and introducing potentially more bugs in the print statements, I can just skip around quickly and find the problems in very little time at all. And that's ignoring what fancy debuggers like valgrind can do. Not all debugging tools are as simple-minded as gdb, after all.

      BTW, I've used debuggers to debug stack smashing quite effectively. As long as you can narrow down where the effects are happening, being able to use the x command to examine the raw memory and decode the stack frame overwrites manually can be quite useful, especially when the overwriting is happening a few frames out due to some sort of weird semi-random corruption.

    64. Re:Debugging by turgid · · Score: 1
      While I was at Microsoft, most of my debugging was done using the console-based debuggers

      How very interesting. I would have thought that everything would be GUI-based at Microsoft.

  3. hello by Anonymous Coward · · Score: 0, Troll

    any one there ?

  4. 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.
    2. Re:Why it's still good... by Pinkfud · · Score: 1

      It's also the only practical way to learn what the hardware is actually doing. In Assembler, you put data into registers and manipulate it as needed. Higher level languages never let you see that. My first assembler was for 6502 processors - remember those? And I still use it for coding routines that need to run as fast as possible.

      --
      The world is my oyster. That's why it's always in a stew.
    3. Re:Why it's still good... by natoochtoniket · · Score: 1
      Many mathematicians, myself included, think the curriculum for computer science should be begin with Finite-State machines, and then Turing Machines.

      After writing a few little programs for TM's, the student develops a real appreciation for assembly. After writing a few little programs in asembly (for just about any model of machine), the student develops a real understanding of higher-level languages. And, if we're lucky, some understanding of theory and a sense of history.

      I don't know about a curriculum for coding, though. That must be in a different school.

  5. 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 Anonymous Coward · · Score: 0

      It's a shame that schools are phasing assembly classes out of their computer science curriculums.

      It's not a shame to me; I'm an ECE.

    3. 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.

    4. Re:Schools not teaching assembly anymore by Trigulus · · Score: 0, Informative

      Most of what I see come out of "computer science" curriculums including BS and MS are woefully unskilled and sloppy. You dont want these people touching assembly. I learned assembly without even realizing it as a child with a Radio Shack Microcontroller Trainer. One of those old kits with all the spring terminals except this one had a hex keypad to enter programs with. I can't find a link to the product its too damn old.

      --
      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 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
    6. 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?
    7. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      Ahem. While I hated it at the time, I'm glad my computer science program has a class on writing an assembler and a virtual machine for a very simple assembly language as a prerequisite for declaring your major.

    8. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      This was forseen 10-15 years ago when schools started to phase out microprocessor electronics classes. Before the electronics classes were phased out assembly language was taught for two purposes: (1) as a basis to higher level programming, and (2) so that a programmer actually knew what happened to his or her data after the language got done with it (i.e. how a computer communicates with peripherals, RAM, etc). A very easy question I like to ask CS graduates is "What is the purpose of the control bus?" It tells you right away if they are factory-CS-program output or people who have an in depth understanding of how a computer works depending upon their answer.

    9. 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."
    10. 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...

    11. 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.

    12. Re:Schools not teaching assembly anymore by ZeroTrace · · Score: 1

      Really... I work at a community college where the only languages they offer are Java, VB6, C, and COBOL. I still haven't figured out why COBOL is in the list and not ASM.

    13. 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...

    14. Re:Schools not teaching assembly anymore by Shaklee39 · · Score: 1

      I find that odd too. I went to a small junior college and learned intel x86 asm there, but after transferring to a university the only asm they teach is picoblaze which is an extremely limited asm language (barely handles interrupts) that is just a wrapper around VHDL. I am glad I learned intel prior to this, it just shows how much I would be missing.

    15. 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.

    16. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 1, Informative

      I fail to see how Java byte code is not a "true assembly language." It has been implemented in hardware to various degrees, after all.

    17. 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
    18. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 1, Interesting

      If you look at a few universities, they are simply phasing it out of their "Computer Information Systems" curriculums, which is a really dumbed down version of Computer Science. While I haven't seen what CompSci students are doing these days, I can say that Computer Engineering students at my university don't touch C/C++ until we have had a couple of terms with Assembly on the X86 platform, and we get embedded platforms after that.

    19. Re:Schools not teaching assembly anymore by Methuseus · · Score: 1

      I would concede that point if the schools taught assembly on a non-deprecated architecture. When I went to college I had to take an assembly class with IBM's s370 architecture. It was just about the most horrendous programming class I ever took .This is including FORTRAN and x86 assembly. They even used the book for the language written in 1973. They didn't use the newer standards written in the 90's, let alone the late 70's or 80's.

      If they had used x86 assembly, or even SPARC, it would have at least made more sense (as it did when i looked into it later).

      --
      Two things are infinite: the universe and human stupidity, though I'm not yet sure about the universe. - A Einstein
    20. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0
      No, in Linux, we assemble our own units, thank you very much.

      Resistance is measured in m*m*kg/(s*s*s*A), thank you very much

    21. Re:Schools not teaching assembly anymore by mingot · · Score: 1

      I can say that Computer Engineering students at my university don't touch C/C++ until we have had a couple of terms with Assembly on the X86 platform, and we get embedded platforms after that.

      All in all, I'd rather hire someone who spent the four years learning the language they are going to use after hire as opposed to those that learned 2 years of VAX assembly, 1 year of embedded systems, and then spent the last two semisters learning about C++, OOP principles, etc.

      I don't want to hire a computer scientist or historian. What I need is a tech who is competent with the tools and languages that are in use here and now. Computer programmers are no different than air conditioning repairmen and carpenters. They need to know the skills to do the job today, not 20 years ago.

    22. Re:Schools not teaching assembly anymore by Frogbert · · Score: 1

      Speak for yourself, I'm currently studing for my Computer Architecture and Assembler exam on tuesday... damn you stack!!

    23. 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.

    24. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      Actually it depends on what major you are.
      Electrical engineers and Computer Engineers typically get C and Assembler, While Computer scientists get C++, Java, among other more abstract languages.

    25. Re:Schools not teaching assembly anymore by Nevo · · Score: 1

      The beautiful thing about learning to program in assembly is that once you learn it on one architecture, you can almost instantly pick it up on another architecture.

      I started on the 6502 and learned PIC assembly, and debugging Windows in ntsd was simple to learn from that foundation.

    26. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      sounds to me like your a short-term thinker. You want someone to do the skills today, but when environment changes you will want to hire someone that will have the new language of the day. Computer Science is about understanding how ALL languages work. So they understand WHICH language is best suited for your application. Now to me hiring someone like that will save the company money because they understand things like modularity, abstraction,types, binding, efficiency, ect. Just a programmer with X skill isnt really worth anything in the long term.

    27. Re:Schools not teaching assembly anymore by gfody · · Score: 0

      nice troll.. just recently I had a C++ programmer with 10 years experience ask me how to combine two values into one. its not something that comes up very often and without a low level fundamental understanding of your datatypes, the solution isn't exactly intuitive.

      why would a c++ programmer with 10 years experience not have a low level fundamental understanding of the datatypes? because he learned how to program with c++

      btw, I fired him immediately

      --

      bite my glorious golden ass.
    28. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      I thought _Concrete Mathematics_ was the prequel to TAOCP.

    29. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      That is sort of surprising. I don't think it has been removed from the ACM/IEEE curriculum guidelines, has it?

    30. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 1, Insightful
      All in all, I'd rather hire someone who spent the four years learning the language they are going to use after hire...
      Which is part of the reason why the quality of CS graduates is dropping. Demand from morons like you is turning our universities into tech prep schools. Thanks, asshole.
    31. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      You completely missed the point. If CS programs aren't teaching the CS students assembly language, but every ECE program worth its salt is teaching a variety of assembly lanaguages, then the ECE student is not just better prepared than the CS student, he has skills that the CS student doesn't.

      ECE students learn assembly language, period. When CS students don't learn it, that disqualifies them from jobs.

    32. Re:Schools not teaching assembly anymore by warrax_666 · · Score: 1
      Admittedly all of them are microcontrollers (PIC, AVR, HC11), but it really does force you to understand how the machine is working.

      It may do so on microcontrollers, but on e.g. x86 (anything later than Pentium 2, IIRC?), the processor actually interprets the machine code into a different RISC-based language which it executes. This translation is hidden from the programmer and so you effectively only learn about the "machine language environment" of the processor, not how the processor actually works.

      You would/could not have known that this translation occurs just from learning x86 assembly because it is hidden from you.

      No, if you wan't to learn about processor architecture you study processor architecture, you don't study assembly language.
      --
      HAND.
    33. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      combine two values into one

      Could you be more clear? Are you referring to unions?

    34. 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.

      --
      "!"
    35. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      Of course, another thing that makes knowing assembler useful is to check whether the compiler is doing what it's supposed to. I guess bugs in PC compilers are pretty rare nowadays, but this is still a realistic possibility on other architectures, as I found out this week while debugging code for a Atmel micro.

    36. Re:Schools not teaching assembly anymore by say · · Score: 1
      why would a c++ programmer with 10 years experience not have a low level fundamental understanding of the datatypes? because he learned how to program with c++

      btw, I fired him immediately

      Let me get this straight. You hired him for coding C++, and then fired him for not knowing anything but C++, and even for asking a question to which the solution 'isn't exactly intuitive'?

      Gee. I'm happy I do not work for you.

      --
      Roses are #FF0000, violets are #0000FF, all my base are belong to you
    37. Re:Schools not teaching assembly anymore by Mycroft_VIII · · Score: 1

      I started on the 6510 myself. Nearly identical to the 6502, in fact the difference were NOT intentional, but could be fun.
      Of course many who did asm for the 6510 may have though they were doing 6502. The 6510 was The cpu in a commodore 64, and was intended to be clone of it.

      Mycroft

      --
      https://signup.leagueoflegends.com/?ref=4c3ed6600b6ea
    38. Re:Schools not teaching assembly anymore by johnnyb · · Score: 1

      Haven't read Concrete Mathematics. TAOCP says that it assumes that the reader is familiar with how to program at least one machine/assembly language. That's what my book is for - to teach how to program, and do so using assembly language.

      I've got a few more goals than just that, as I want to teach the programmer how the program interfaces with the operating system. My book includes an example malloc() implementation, talks about raw system calls using int 0x80, discusses calling conventions, and shows a little bit about how dynamic linking works.

    39. 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.

    40. 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.

    41. Re:Schools not teaching assembly anymore by Crazy+Eight · · Score: 1
      I had a C++ programmer with 10 years experience ask me how to combine two values into one.

      He didn't know how to add?!

    42. Re:Schools not teaching assembly anymore by Ender+Ryan · · Score: 1
      Thanks, just ordered it from B&N.

      I had read good reviews of your book before, but couldn't remember what it was called :-/

      --
      Sticking feathers up your butt does not make you a chicken - Tyler Durden
    43. Re:Schools not teaching assembly anymore by slashdot_commentator · · Score: 1

      They are probably not packaging it properly. Perhaps what they should be doing is teaching "Introduction to Computer Architecture (201)" and using assembler as the language for class instruction. True, you could go about teaching those concepts using a higher level language. But that would be a form of cheating, faking the experience, at least until CPUs are designed to execute java in its instruction sets (that's a joke, son...). Besides, some professors tend to be sadistic, and prefer not to instruct a class in a commonly used language (where coding can be cribbed). It also may give a student a better appreciation for the computer oriented math classes, dealing with boolean logic, linear algebra, etc.

      The other problem is that the most prevalent computer for assembler assignments would be the one of the worst CPUs to learn assember (the x86 family). Then again, perhaps something like A86 still works for Athlon/P4, and the "arcane" CPU features can be totally avoided. Or perhaps there is an adequate 8bit CPU emulator for class instruction.

      --
      There is no America. There is no democracy. There is only IBM and AT&T and DuPont, Dow, General Electric, and Exxon
    44. Re:Schools not teaching assembly anymore by DaveAtFraud · · Score: 1

      Your example struck a nerve because I just went through having to show a developer how his design failed because he launched a separate thread for each action the user requested. His solution worked great when the number of requested actions was less than the number of CPUs (4 in this case: 2 physical and 2 HT). It wasn't even too horrible when the number of actions was greater but what was being acted on was small. Unfortunately, it sucked major, big-time when the objects were large (aggragate size greater than available RAM) and got worse when each thread finally tried to start updating the database. At that point, the system became completely unusable until it sort of caught up but, even then, any queries to the database still gave a bogus result because updates to the database were still I/O bound and going on in the background.

      We ended up serializing multiple user action requests of the type that caused the problem. Turns out that the serial solution actually was *faster* in all but a few trivial situations (e.g., multiple threads were only faster when there were only a few, small requested actions) since we also didn't start swapping, there were fewer context switches, etc. and the actual bottleneck was I/O. Yet another case of throwing multiple threads at a problem without anayzing what the system actually has to do. Since this just went on over the past couple of weeks at work, it was the type of example I was thinking of in my original post.

      (Note: I try not to over qualify my postings to the point where all my qualifications only serve to confuse the point I'm trying to make. That usually means there are some excpetions to what I have to say. See somebody else's comeback later in the responses with what they construe as another exception.)

      --
      They that can give up essential liberty to obtain a little temporary safety deserve neither safety nor liberty.
      Ben
    45. Re:Schools not teaching assembly anymore by mingot · · Score: 1

      Demand from morons like you is turning our universities into tech prep schools.

      Prep as in preparatory? In somewhere that prepares someone with the skills needed to perform an actual task? In the case of programmers you're goddamned right, thats EXACTLY what it should be. When it comes right down to it building a peice of software is like building a skyscraper. You need that one trained architect. You need that engineer to make sure it's not going to collapse under its own weight. AND you need 1000 blue collar slobs to actually build the thing. Universities are great at churning out the first two, but what about the other 1000?

    46. Re:Schools not teaching assembly anymore by modge · · Score: 1

      You can do a course called Computer systems engineering where i am (and im doing it). you do assembly for a couple of different PIC's C, java and little bits of other langages now and then. Best of all worlds

      --
      I am a sig
    47. Re:Schools not teaching assembly anymore by arkanes · · Score: 1

      This is an important difference between percieved performance and "real" performance. Your MT cpu-bound task (calculating a private key, say) will run slower (sometimes _much_ slower), but the user will percieve it as being performing better, because the application stays responsive (and they an see a progress bar, hit the cancel button, etc). A user will wait for a progress dialog that takes 30 seconds alot more willingly than they'll accept an application just freezing for 5.

    48. Re:Schools not teaching assembly anymore by computational+super · · Score: 1

      Spoken like somebody who's never written a program. The 1000 blue collar slobs who "actually build the thing" are the compiler, the linker, potentially code generators, forward engineering UML tools, etc. If some programming-related task doesn't require any engineering, it's been automated.

      Don't worry, though - you're in good company. Everybody who knows how it's done it actually out there doing it. All the incompetents get promoted out of harms way. (Mostly out of harms way... as long as they're not allowed to participate in hiring decisions as you seem to imply you are).

      --
      Proud neuron in the Slashdot hivemind since 2002.
    49. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      As a stack-based VM, Java bytecode is fun, but not really evil enough to count as an assembly language.

      My current job involves programming a really nasty VM, apparently designed by a cross between Hitler and a monkey, which provides 2000 32-bit registers and no stack. I spent several days trying to implement a small stack in software before deciding that recursion probably wasn't useful enough to be worth the effort...

    50. Re:Schools not teaching assembly anymore by johnnyb · · Score: 1

      Great! Let me know when you get through how you liked it and what I could do to improve it. Always looking for feedback.

      Of course, telling all your friends about it is a good idea, too :)

    51. Re:Schools not teaching assembly anymore by PaulBu · · Score: 1


      Of course you know your application better than anyone here, and I bet that you did do the right thing, but somethings strikes me as a little bit odd: ... since we also didn't start swapping, there were fewer context switches, etc. and the actual bottleneck was I/O

      Are you sure we are talking about the same 'threads', as in pthreads/clone()-based, NOT fork()ed-out _processes_? By definition the first kind all share memory space and running 10 of them instead of one should not cause excessive memory consumption/swapping.

      Well, of course it is not always true, if you mmap() a 100 GB database file and unleash a whole bunch of threads to work on different (non-overlapping) parts of that you start thrashing your OS's buffer cache really soon and can bring your system to a halt rather effectively...

      As a side note, I always assumed that the only reason to use more threads (in your program) than there are CPUs/contexts available is when your problem is I/O bound (you achieve the benefits of asynchronous I/O without explicitly coding it in): number of threads = number of CPUs + number which on average sleeps waiting for I/O to complete.

      Paul B.

    52. Re:Schools not teaching assembly anymore by TimTheFoolMan · · Score: 1

      This reminds me of what I call the "Malcom in Jurrassic Park" syndrome. His complaint (better stated in the book, but stated in the movie) to the scientists was (rough paraphrase) "You're standing on the shoulders of giants, and were so excited about what you *could* do that you didn't stop to think if you *should*."

      Though many aspects of Malcom's character were annoying enough to want him to become T-Rex filling, he was able to rather eloquently state what you're saying here. This thought also seems to be creeping up into other threads.

      For me, this begs the question: Is there a limit to what I (Joe Programmer) can learn as high-level languages progress if I choose to have a solid understanding of the things that went before the HLL? After all, I may be a pretty smart guy, but it seems pretty arrogant to assume that I'll be able to understand the mistakes of many others (without making those mistakes myself), take their knowledge, build upon it, and be able to reap all the benefits of the knowledge database that I've built upon.

      It seems at some point, for me to advance in a given field (not necessarily programming), I have to accept that I won't be able to know and understand ALL of the work of my predecessors, but only the most relevant aspects. This would appear to be where, in any given field, true genius would emerge.

      Tim

    53. Re:Schools not teaching assembly anymore by DaveAtFraud · · Score: 1

      The example is literally working with up to ~100GB "archives" of "event data" to be restored from a remote file server. The system doing the work is either an 4 CPU Dell 6650 with 8GB of RAM or a 2 CPU Dell 1750 with 2GB of RAM. Files in the archives consist of metadata identifying the file contents and the application data. Restoring an archive means the metadata gets stuffed into a postgres database with the application data remaining accessible through the file system. An "archive" such as this can consist of up to 1.7 million event files. The implementation language is Java as Java Server Pages (JSP) on a Red Hat Enterprise Linux 3 platform. The 6650 has a RAID 5 array to help provide better I/O throughput.

      The developers tend to test with (and think in terms of) small archives of several hundred event files and an archive size on the order of tens of megabytes. Multi-threading a few of these *appears* to work well and even doing a bunch doesn't seem to do much harm due to their size. Even at a point in between these extremes (e.g., 10 GB archive of a few hundred thousand event files), all it takes is firing off a couple of actions concurrently and the system is as good as dead. Running top on the system will reveal almost no user CPU cycles but everything solidly in I/O wait. At least the developers didn't try to mmap the archive.

      The real problem is the massive, monolithic archive which really isn't required since the end users access the event data through the metadata in the database. It would be fairly easy to also do a little more "book-keeping" and spread the events through several smaller archives. Unfortunately, the same developers seem to have trouble grasping this and want to cling to the single archive file design. The trick *isn't* to find a way of doing what we're currently trying to do but, instead, find an easier way to provide the user with the data they're interested in (e.g., try the door handle before you attempt to break down the door).

      S I G H

      --
      They that can give up essential liberty to obtain a little temporary safety deserve neither safety nor liberty.
      Ben
    54. Re:Schools not teaching assembly anymore by PaulBu · · Score: 1

      Oh, well, I can appreciate the full meaning of your ~/.signature now! ;-)

      The lesson: Test on production data. ;-( I know how it feels, a good friend of mine does similar kind of stuff for (German! European bureocracy!) medical insurance databases, the stories she told me are unbelievable to anyone with more mainstream CS background.

      Well, maybe another lesson is that Java is not exactly the right language when you are mostly dealing with syscalls (lseek(), read(), printf some SQL and send it towards the DB), which kind of brings us back to the original topic...

      At least the developers didn't try to mmap the archive. Maybe they should've? Then some part of what they were trying to do would shift from Java to highly-optimized (maybe even in asm ;-) ) code in the kernel. Not that it is a guaranteed win, but at least deserves some consideration and thought, but the thought process requires of the guy doing it to know what the tradeoffs are, and you get this knowledge only from learning something besides Java.

      The real problem is the massive, monolithic archive... A kernel module to mount the archive as a filesystem, anyone? I know, I know, but is not it sad that manufacturing gave us 3GHz processors and 300 GB disks (yeah, they just "print" those, not thinking of each individual Hz or byte) and too many programmers do not stop and think what does it take to handle a 100 GB dataset...

      Paul B.

    55. Re:Schools not teaching assembly anymore by Anonymous Coward · · Score: 0

      For my B.S. in CS (98-02) I took threee assembly courses. One was x86 assembly offered by my department (sophomore level course). They also required us to take an introductory ECE course focused on developing for the HC11. We also had to take one senior level ECE course for the B.S. program (B.A. in CS guys didn't need it). I took an additional course developing for the HC11 to satisfy this requirement.

      I'm still at the university as a graduate student, and the x86 assembly is required for all CS studens, and the intro ECE HC11 course is required for all B.S. in CS students.

  6. 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 rmull · · Score: 1

      Hear hear! There was something bugging me about this article and you've articulated it exactly. Coding for maintainability, clarity, and correctness is far more important than optimization. Increase in computer speed and size allows not only the luxury of additional features but more importantly the ability to work at a higher level and get more done.

      --
      See you, space cowboy...
    2. 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"
    3. Re:don't bother........ by Qzukk · · Score: 1

      then when you need performance you can drill down and figure out how to do it.

      Or you hire someone who understands why certain behaviors yield performance, instead of sitting there and trying different things until you work something out that seems a little faster.

      --
      If I have been able to see further than others, it is because I bought a pair of binoculars.
    4. Re:don't bother........ by mabinogi · · Score: 1

      I agree with most of what you said....but I'd still use a StringBuffer rather than a String for multiple concatenations...

      There are some things which are just a good idea regardless....

      --
      Advanced users are users too!
    5. Re:don't bother........ by Anonymous Coward · · Score: 1, Insightful

      2 points:

      1) Minimalism and assembly are not mutually exclusive. As you said, optimize at the end, and that optimization could be implemented with assembly.

      2) You can't tell me you are not a better programmer because you know assembly. Yes, we don't need to think about machine architecture or vm design as much as we used to, but you can't tell me it's not extremely useful in the circumstances that we do.

      The more languages you know, it changes the way you program. Yes, learn assembly, learn lisp, but also learn eiffel, haskell, objective-c and prolog too.

    6. 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.
    7. 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=

    8. 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.

    9. Re:don't bother........ by Anonymous Coward · · Score: 0

      This is the same attitude that has given us applications that crash incessantly in windows...bloated software, well it has 3+ million lines of dead code but we are too busry to clean it up...The old well good enough argument. All I see from this attitude is bloated, unstable, slow applications.

    10. 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.

    11. Re:don't bother........ by Anonymous Coward · · Score: 1, Interesting

      If you never learn assembly you will never have a chance of understanding what is happening to your data and how your memory is structured. While this may be fine for a VB programmer, and in general application programmers, if you want to graduate and become a system programmer, you need to know this information. A drawing with a box in it that says 'class A' and another that says 'heap' isn't going to help you if you want to write a memory manager or a real file system driver. While you may say this is a job for senior programmers, I would counter that I think education should be progressive. College courses should give you the basics so that you can learn what you need in a certain instance. Noone is going to expect a programmer to know the entire application being developed the first day on the job (or sometimes even the language being used!). But if the programmer doesn't have the basics to learn further, when he is told to do something that even remotely borders system programming he will respond "My college said assembly programming wasn't important, so I just skipped trying to understand how a computer works. But I know C#, Java, and PHP!". And the response "Thats helpful. How about you go and make a web page for the project instead, ok"

    12. Re:don't bother........ by kingstalemuffins · · Score: 1

      I'm sorry, but lisp is not a good language to use. Although i have never programming, my first college leve CSCI class used SCHEME (a direct descendant of Lisp if i remember correctly) as the language. This language is structed very difficult for a new computer science student to easily understand. The endless parenthesis does not help either. And, on top of this, the language is completely dead! I much rather would have learned an assembly language. This would have given students a better feel for the hardware and would have had useful applications.

    13. 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."
    14. Re:don't bother........ by Anonymous Coward · · Score: 0

      To quote Knuth "Premature optimization is the root of all evil." Using data structures appropriately in Smalltalk or Java consistently outperforms brute-force implementations in low level languages. (When was the last time you used a hash table or red-black tree in assembly?)

    15. 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
    16. 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.

    17. 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

    18. 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.

    19. Re:don't bother........ by Tony-A · · Score: 1

      Why does use of assembly preclude thinking in terms of functions and algorithms?

      Well, it shouldn't.

      Just try implementing recursive co-routines in a HAL.

    20. Re:don't bother........ by abdulla · · Score: 1

      Simply put, find a balance - teach good structure and organisation so when you need to micro-optimise, it's localised and easy to maintain.

    21. 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!
    22. 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.
    23. Re:don't bother........ by v1 · · Score: 1

      I too cut my teeth on 6502 assembly, and I'm thankful for it. It's allowed me to be able to spot areas in need of optimization and of course debugging compiled code where the source is not available or the debugger is not being helpful. Crypto is one area that demands assembly for high speed processing - the last two crypto blocks I optimized yielded a 10x and 30x speed increase. It's even helped me find bugs in compilers when they were generating broken code from my working source.

      That, and lastly, assembly makes you gain a whole new respect for higher level languages. Surely you remember having to make your own math libraries for the 6502, since it was an 8 bit processor that couldn't even multiply. Once you know how the basics work, it greatly benefits your use of the tools built on the basics.

      --
      I work for the Department of Redundancy Department.
    24. Re:don't bother........ by johnnyb · · Score: 1

      The way I got around the "magic" in my book is by starting out using the exit code to "print" out the values. You run the program and then do echo $? to get the value. This way you don't have to say "trust me" too many times. The programmer gets a feel for doing real code, and then eventually I get to an input/output chapter where I tell them how to print stuff out for real. And then later I teach how dynamic libs work.

    25. Re:don't bother........ by Anonymous Coward · · Score: 0

      Well, Mr. Light Bulb, if you measure 'faster' by the return time of function calls, rather than by how long it takes to actually solve the problem, then yes, one-argument-at-a-time-please functions are better. As for value vs. reference etc. what does that have to do w/ assembly language?

      Another shining example of why you shouldn't try to learn programming from slashdot.

    26. Re:don't bother........ by dkemist · · Score: 1

      interesting point, but actually, I think the same theory holds true for interpreted languages. It's just that the level of abstraction moves up a layer.

      Knowing the specific machine op codes for your java statements might not be as valuable, but having some sense on how that bytecode is going to be generated and interpreted by the VM will improve your design choices. Similarly, you can write some really horribly inefficient Perl algorithms if you don't understand how the underlying code is going to get executed at runtime (think regexs for example.)

      I think the message is less "learn assembly language," than "learn the underlying execution environment."

    27. 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.

    28. 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.
    29. Re:don't bother........ by Jeremi · · Score: 1
      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.


      Actually, it's great that people can write software and get it to run usably fast without having to be super-geniuses and/or spend hours or days poring over the code to get it to run fast enough. With more programmers having the ability to code, and each programmer being able to code more in less time, the result is much more software available that would otherwise be the case. And since CPU power and RAM is so cheap these days, the downside is minimal. So the glass is half full :^)


      At the end of the day, what matters is how much useful work people can get out of their computer. So I'd rather have a fast, cheap machine running lots of inefficient software, than any kind of machine with only a few highly optimized packages available for it.

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    30. Re:don't bother........ by Anonymous Coward · · Score: 0

      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.

      You are biased because you started with a background of assembly language programming. Programmers without that knowledge cannot "drill down" and optimize their code, simply because they've never done it before, and don't know what the hell the computer is actually doing. It is very difficult for programmers who don't know the hardware distinction between pass-by-reference and pass-by-value to understand why the former is faster for large objets (which are just allocated [from where?] with "new" anyway, so you should be able to pass them around, right?).

      Assembly language is lower than most programmers will ever need to go (often), but the same argument applies to any low level aspect of the system. Optimizing SQL queries requires an understanding of the fundamental set operations and indexes required, and how to optimize them. Programmers should never trust the machine to do all the work because machines just aren't that smart yet.

    31. Re:don't bother........ by tcgroat · · Score: 1

      A few extra parameters here, a function call instead of inline code there, not using index registers efficiently anywhere...the next thing you know, it's running slower than Windows. Oh, wait, that was yesterday's topic...

    32. 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
    33. Re:don't bother........ by Anonymous Coward · · Score: 0

      I suppose if you have no interest whatsoever in writing anything but desktop GUI stuff, that advice makes sense. But why limit yourself? Learn assembly AND Lisp! A true craftsman masters a wide range of tools.

      My opinion is skewed by the fact that I'm an embedded systems engineer, so I couldn't even begin to do my job without understanding software all the way down to the metal. I also think hardware engineers should learn to program.

      Besides, forget about pragmatism: Aren't you curious? Don't you want to understand what the compiler does with all that cool C++ code you write all day?

    34. Re:don't bother........ by chgros · · Score: 1

      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.
      How is that supposed to be more efficient? (I agree about the readability part though)

    35. 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.
    36. Re:don't bother........ by globalar · · Score: 1

      One issue of this discussion is not merely practicality, but principle.

      Programming is inherently about using finite resources to solve a problem (execute a process, etc.). Finite is, ultimately, a relative term. But that's not the point. To understand 1)why implementations exist as they do, 2)how the machine really works, and 3)how they can use their resources most effectively (because programmers need to be able to improve code as well as write it), programming within less-than-desired constraints is important. A parallel to this is the ability to apply algorithms and more complete components, to different circumstances.

    37. Re:don't bother........ by Jeremi · · Score: 1
      How is that supposed to be more efficient?


      Because you are only passing one reference to the function call instead of ten, and thus you only need one register instead of many. (This assumes you are passing in the same set(s) of values around repeatedly, of course... if you are passing in completely different combinations every time, then copying them into an object first will of course not help)

      --


      I don't care if it's 90,000 hectares. That lake was not my doing.
    38. Re:don't bother........ by Anonymous Coward · · Score: 1, 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).

      Are they supposed to pass all those 10 things or not? If they are, then passing some in registers and the rest on the stack is going to be loads faster than marshalling them all into a structure and passing a pointer to it. Shit, what's any piece of the program doing manipulating 10 independent pieces of state anyway? This has less to do with performance than with crappy high level design.

    39. 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.
    40. Re:don't bother........ by gfody · · Score: 1

      you are actually a good example of why people should learn asm. if you knew what was really going on you'd realize that passing 10 parameters results in less push/pop/mov's than the whole class thing.. you'd probably also realize that the whole argument is fucking pointless because your actually worrying about 0.0000000001% of the instructions in your app.

      of course, if all your app does is pass parameters to functions.. then hey, optimize away!

      --

      bite my glorious golden ass.
    41. Re:don't bother........ by gfody · · Score: 1

      your example is crap for telling people not to learn those optimizing techniques. you just had a bad habit of optimizing the wrong thing. I agree, when coding, keep it simple (stupid).. when you find your bottleneck and it's time to optimize you'll need to know and apply the techniques you mentioned. knowing them is half the battle.. knowing when to apply them is key.

      --

      bite my glorious golden ass.
    42. Re:don't bother........ by Anonymous Coward · · Score: 0

      I don't know what you mean by HAL, but I assume that you are trying to say that things like recursion and coroutines are hard to implement in an assembly language? If so, you are wrong.

    43. Re:don't bother........ by Tony-A · · Score: 1

      I don't know what you mean by HAL, but I assume that you are trying to say that things like recursion and coroutines are hard to implement in an assembly language? If so, you are wrong.

      Correct.
      HAL Higher Algorithmic Language is probably what I was thinking.
      Things like recursion and coroutines are nearly trivial in assembly language.
      There are things reasonably doable in assembly that are inconceivable in "higher" level languages.
      Recursive coroutines do not come naturally to the "higher" level languages.
      I have done coroutines in PL/I (with a little help, enough help to run FORTRAN in the context of PL/I ON ERROR;)

    44. Re:don't bother........ by Anonymous Coward · · Score: 0

      You realize that Knuth also advocates learning to program in assembly don't you? Also, the quote did not originate with Knuth.

    45. Re:don't bother........ by Anonymous Coward · · Score: 0

      Knowing Lisp and assembly is actually important. Believe it or not, some people use Lisp for code that requires a pretty high level of performance, and knowing what instructions are actually produced from the Lisp code is useful.

    46. Re:don't bother........ by livhan28 · · Score: 1

      your absolutly right, im so sick of this new "ignorence is bliss" trend in programming. i fail to see how, knowing more can hurt you or impact your code in a negitive way.

    47. Re:don't bother........ by 12357bd · · Score: 1

      Yes, and also the Error Oriented Programming (EOP)...

      The first error is just to think about programming.

      What's in a sig?

      --
      What's in a sig?
    48. Re:don't bother........ by CharlesEGrant · · Score: 1

      I'm not entirely sure what you mean by "this new ignorance is bliss" trend. I see it more as a division of labor. The problems I'm working with (identifying related DNA or protein sequences using support vector machines) are hard enough to understand in themselves that if I had to worry about finding buffer overruns in my assembly code I'd go nuts. Thank god for languages with run-time bounds checking and garbage collection.

      I've also heard it remarked that debugging is twice as hard as programming so if you are as clever as you can be when you write your program you are never going to be able to debug it.

    49. Re:don't bother........ by iabervon · · Score: 1

      Don't forget that some of the optimizations that you learned for fast C are actually good for readability. Temp variables, for example, are a good way of making it clear that two expressions are really the same.

      It's still a matter of writing optimized code; it's just that you now want to optimize for the next developer (either reading or changing the code), and the compiler optimizes for you.

    50. Re:don't bother........ by Anonymous Coward · · Score: 0
      So, if I am programming a database with SQL, it makes sense to make it easy and use cartesian products?

      It is programmers like this that make my DBA job a nightmare, due to not understanding nor wanting to understand how the computer really works.

      Oh, lets make everything a varchar,

      oh and by the way all of our numbers will be in varchar with a decimal point along with 4 significant digits.

      This is crap and it makes me furious that this kind of programming could be prevented with one class of assembly to show how the computer works with numbers. In programming, stick with numbers when possible, don't use time consuming joins that translate a character field into a number .... just plain foolish!

    51. Re:don't bother........ by sysopd · · Score: 1
      Easilly readable code is FAR MORE IMPORTANT.

      Easily readable code is more important to the programmer, however more efficient code is much more important to the user. If you are planning on selling your software or having anyone actually use it, you'd better at least think about efficiency. Also, you seem to think efficiency and readability/maintainability are mutually exclusive. That is simply not the case.

      SO WHAT! Programs should only be optimized if:

      1) the program is doing stuff so intensive that it runs slow

      What is your metric for 'running slow'? Running slow with no other programs running? Running slow on your development machine, a machine that is likely faster than your user's machine? I think it would do developers a lot of good to test all software on systems half the speed of the current middle-of-the-line system.

      2) It is being run all the time in the background by the system and can slow down the system as a whole.

      Most software is used in conjunction with, or adjacent to, several other pieces of software. You should not be forced to run the program standalone because of its excessive resource requirements.

      98% of the time it just does not matter.

      It is thinking like this that causes the escalation of poor, slow, bloated software.

    52. Re:don't bother........ by Anonymous Coward · · Score: 0

      This depends what you are trying to archieve. With modern CPUs you don't have to care about efficiency in 'normal' applications.

      But there are programs (scientific computing for example) where performance really matters. If computations will take 2 month with 100% optimized code by using the fastests computers money can buy, sloppy coding may increase running time by factor of 2-50.

      This means computations may take as long as 8 years! For similar reasons ability for program to meet realtime requirements is often question of careful optimization.

    53. Re:don't bother........ by Tony-A · · Score: 1

      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.

      Oh definitely!
      Good efficient asm will avoid most "optimizations" that compilers routinely do. You're after big gains not little gains. You happily lose 10 percent where it doesn't matter to gain a factor of 10 where it does matter.

      My favorite example (from long, long ago) is hand-multiplying constants.
      If the timing does not matter, the code is uselessly obscured.
      If the timing does matter, that's the wrong solution and it only makes finding a viable solution that much harder.

    54. Re:don't bother........ by arethuza · · Score: 1
      Well said!

      A basic approach in engineering is that you can only improve something that you can measure. So without benchmarks, instrumentation in your code and profilers the chances are that developers have no idea where the hotspots are, assembly language expertise or not.

      I've seen a huge number of bugs in production code that were caused by daft attempts to 'optimise' stuff that I am very very wary of the subject

      Sure, once you have identified performane hotspots that mean that your system isn't fast enough then deploy all the tricks in the trade - but only do this where and when it is necessary.

      Of course, past experience with particular systems may allow you to know where hotspots will be and plan aggressive optimisation up front in those areas, but that is still basing things on an empirical understanding of where the performance problems really are.

    55. Re:don't bother........ by chgros · · Score: 1

      I actually know asm, but if you have to put everything into a structure first I don't really see how it is better than pushing it to the stack (since putting the values into the structure takes as many instructions as it would take to put the arguments directly into the stack, and the structure is probably already on the stack anyway)
      Of course it's different if you pass the same arguments along several times...

    56. Re:don't bother........ by reallocate · · Score: 1

      I think your saying that it takes you too long to write well-constructed assembly. Fair enough. But, a number of the other posts seem to consider that writing in a high-level language, with all kinds of avilablestructure. automatically produces "algorithmic sophistication". It doesn't. The algorithm is in your head;coding is the act of implementing that algorithm. You can do that in 6502 assembly or in Common Lisp. Use the one that's appropriate.

      --
      -- Slashdot: When Public Access TV Says "No"
    57. Re:don't bother........ by griann · · Score: 1
      So, what you're saying is, understand less and submit to what others allow you to do? And this will make you a better programmer?

      Maybe I should stick to HTML then?

    58. Re:don't bother........ by julesh · · Score: 1

      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.

      The optimisation that the assembly language programmer would apply here also results in cleaner code... store the 15 arguments in a structure and pass a pointer to it.

      Of course, this is only faster if the function is being called multiple times, but heh, you only optimise your inner loops, right?

    59. Re:don't bother........ by noidentity · · Score: 1

      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.

      Performance can be improved only by changes to a small portion of the code, but correctness can be disturbed by changes to any secion of code. Thus, when optimizing one wants to change only that code responsible for performance, and as little as possible.

    60. Re:don't bother........ by cathouse · · Score: 1

      Taking the concept of learning to think like the machine farther, very nearly as far as the concept can go, is that the single
      most valuable learning experience I had in thinking like the machine was programing the control boards for Unit Record Machines.

      The actual hands-on pluging of a wire from BRUSH to REGISTER, from BRUSH to CONDITION, and so on, gives both the basis for writing the instructions that will generate clean,
      compact, fast code and the acceptance of all the human and machine forces that combine to prevent that from being acceptable.

      --
      Thelma, I'm not making ANY deals.
    61. Re:don't bother........ by Anonymous Coward · · Score: 1, Interesting

      I disagree wholeheartedly with the above, with the exception that readable code is important (more from a maintainability standpoint).

      You talk about your python code feeling 'instantaious' (ignoring the spelling), which yes may very well be true on your one-user 2.4Ghz linux box at home with nobody else beating on it...

      I manage java application servers used *worldwide* by perhaps 100K users/day. Our biggest server has probably 40 applications on it, any *one* of which, if ill-behaved, can affect the others. I've run into apps with poorly coded/planned sql queries that take 8 seconds to execute... throw that in a JVM taking 1000 hits/second with 100 threads.. you figure how long it takes for all the threads to block because they are waiting on DB requests, killing not only that one app but the other 5 in that same JVM. (hint, less than a second). It has *nothing* to do with the application code itself running slow (heck, the user hits return, and it generates that DB request in a fraction of a second), its just *poor design*.

      As a sysadmin with 300K+ users using my apps, I've gotten bitten *many* times with new code being pushed to prod after "QA" testing that kills the production environment. I don't *like* being woken up at 2AM for an hour+ of poking around and then rolling back the code that was pushed that night. Exactly the same as what you are doing, the QA people test the application *by itself*, and then when it goes to production *I* have to deal with the effects of it running alongside 39 other apps.

      My personal favorite OS is NetBSD. A year or so ago they made changes to the rc-script code, and after pushing to -current, a lot of people on older boxes (ie. vaxen, decstations) complained because it was so much slower. Yes, on your 2.4Ghz x86 box, your startup went from 0.5 seconds to 0.6 seconds... but on slower hardware it was far more dramatic.

      People today are spoiled by "ah, it runs slow on my 2.4Ghz box, I'll just buy a 3.2 and it'll be fine". Thats fine if its just you on the box. Put 100 people on the box, and your 1-second runtime (that lets say could be optimized to 0.1 seconds if you wrote efficient code) equates to 100 second response for those 100 users. Optimize it to that 0.1 seconds, they get 10 second response. Which would *you* prefer?

    62. Re:don't bother........ by BigJimSlade · · Score: 1

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

      I'm a software developer, and my job is to make the computer do what my customers want it to do. Personally, I'd take a developer that knows the theory of things (algorithms, relational databases, etc.) over somebody who *really knows* assembly language any day. CAVEAT: I develop end-user applications in high level languages. In the 5 years I've been working at my company, I have not had an occasion to need low-level optimization. Any optimizations that have needed to be made have been algorithm optimizations that made the app "fast enough". If you're unfamiliar with the equation for "fast enough", it goes something like this:

      FastEnough = SpeedOfExecution/DevelopmentTime

      For small increases in SpeedOfExecution, even a smaller increase in DevelopmentTime will lower your overall "fast enough" factor.

      Customers don't care how clean your loops are. They care about solving their problem *now*. If you can develop an app for them that is "fast enough", optimizing at the assembler level is irrelevant.

    63. Re:don't bother........ by Anonymous Coward · · Score: 0

      Knowledge about query analysis and optimization != code analysis and optimization.

      ANSI SQL is not a turing-complete language (ignoring PL/SQL and MS SQL and whatever else). Knowing about assembly language or code optimization won't help you. Knowing about hashing, scanning, indexing, etc. will -- but those a sufficiently high-level ideas divorced from the code.

      You don't have to know assembly to know that numbers are stored different from strings of text. Any competent programmer should know this. Those that don't (like the people you work with) are clueless dorks that shouldn't have gotten the job in the first place.

      I don't know how Oracle was implemented but I know I can ask it what algorithms will will use to perform my query. The greatest demo hacker with years of assembler language experience might still forget to use indexes if he starts doing web development.

    64. Re:don't bother........ by Anonymous Coward · · Score: 0

      And learning asm would help this?

    65. Re:don't bother........ by Anonymous Coward · · Score: 0

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

      Yes. Doing 99% of a program "right" (wrong) is obviously more time consuming than doing the performance sensitive 1% twice. Or ten times.

    66. Re:don't bother........ by voodoo1man · · Score: 1
      Although i have never programming, my first college leve CSCI class used SCHEME (a direct descendant of Lisp if i remember correctly) as the language.
      Scheme is not an acronym, and it's not a descendant of Lisp. It's a Lisp-like language that borrowed and extended the idea of lexical scoping from Algol, and kept some of the good ideas of Lisp (such as the syntax and source code representation).
      This language is structed very difficult for a new computer science student to easily understand.
      I disagree. I first learned Scheme (and computer programming) in the introductory CS class at Stuy, and I don't recall that anybody in the class had any problems (I certainly had a lot of fun!). I abandoned computer programming for two years after taking the class, until I read about Abelson and Sussmans' Structure and Interpretation of Computer Programs somewhere. Within a week of picking up that book, I not only had a firm grasp of the language, but a much better understanding of programming and recursion as well.
      The endless parenthesis does not help either.
      Scheme was invented in 1975, well after glass teletypes first became available. I suggest to anyone using or learning Scheme that they avail themselves of a full-screen display editor with such advanced capabilities as character blinking (to help match parenthesis, among other things).
      And, on top of this, the language is completely dead!
      Tell it to these people, and these, and these.
      I much rather would have learned an assembly language. This would have given students a better feel for the hardware and would have had useful applications.
      You obviously didn't have SICP as your course textbook. In chapter 5, you first write a simulator for a simplified register machine, and then write a simplified Scheme compiler targeting it.
      --

      In the great CONS chain of life, you can either be the CAR or be in the CDR.

    67. Re:don't bother........ by rastos1 · · Score: 1

      I have to disagree. In the given axample the understanding of assembly helps to make a decission for high level language. That is the point of understanding assembly these days, IMHO.

    68. Re:don't bother........ by Methuseus · · Score: 1

      My problem with that claim is, the things that this is supposed to help with in higher level languages I was already doing right before I took the assembly class. THen I had trouble in my assembly class. So I never really understood how it was suposed to make your higher level coding better.

      --
      Two things are infinite: the universe and human stupidity, though I'm not yet sure about the universe. - A Einstein
  7. 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 csimpkins · · Score: 1

      And when that software breaks and costs them millions because it sucks, they'll come back to those that take the time to do it right.

    2. 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.

  8. 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 aflat362 · · Score: 1
      >>I'd love to see a return to applications that were under 100K

      Spare me. nobody wants to stare at a terminal all day long. There are valid reasons for GUI applications you know. (yeah yeah, I'm making assumptions here, you know what I mean)

      >>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.

      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. Why take precious hours to pick out every class to include in your app when you can just include the whole damn library and the program performs the same?

      The quicker an app can be developed the better. Every day that you aren't running your code in production is a day that your corporation loses money. Yes I know that programs still have to be well written and protect the interests of your company but my point is I don't think that bloat is as big of a deal as your sentimental for the olden days post makes it out to be.

      --

      Conserve Oil, Recycle, Boycott Walmart

    5. 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?

    6. 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
    7. Re:Smaller code? We can hope... by PaulBu · · Score: 1

      If I need to write a GUI app, I'll do it in Python with GTK or QT bindings.

      Almost by definition any GUI app spends all its time waiting for the user to press a button (responce time in milliseconds range), so noone in their rigth mind would code one in assembly. Low-level (think BITBLT) parts of the GUI is coded in assembler or maybe even microcode (extreme cases ;-) ).

      You being able to pick an efficient library and sensible approach to the task at hand in no way invalidates the granny-post's point that businesses relying too much on levels and levels of crud (bought for big $$ from the companies employing people who have not learned assembly in college, not to mention high school ;-) ) tend to produce code bloat.

      Paul B.

    8. Re:Smaller code? We can hope... by Just+Some+Guy · · Score: 1
      On my Debian/unstable machine, /bin/busybox is 144652 bytes in length. Embedded in that single program is the functionality 203 shell commands, for an average size of 713 bytes per command.

      It's written in C and runs well on my Linux and BSD servers on Intel and Alpha hardware. To me, this proves yet again that good organization and solid algorithm design buy you a lot more than huge amounts of low-level optimization.

      --
      Dewey, what part of this looks like authorities should be involved?
    9. 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.

    10. Re:Smaller code? We can hope... by Just+Some+Guy · · Score: 1
      Almost by definition any GUI app spends all its time waiting for the user to press a button

      You could say the same for the wide majority of modern applications. My web server sits there idling until a request comes in. My KPilot is bored until I press the HotSync button on my Palm. PostgreSQL doesn't do much unless someone is running a query.

      I'd never claim that there's no need for assembler, mainly in the exact types of places that you mention. However, I would contest the idea that it still has a reasonable existence outside of those tiny niches. Assembler is great for tweaking the inside of a tight loop, but that's about it.

      businesses relying too much on levels and levels of crud (bought for big $$ from the companies employing people who have not learned assembly in college, not to mention high school ;-) )

      Do not get me started on that topic - we just don't have the time to go there. ;-) Any time I hear someone say "middleware", I feel the urge to run screaming.

      One of the things I like about high-level languages like Python is that I recently found the need to interpret barcodes in images on our system. The end result was maybe 40 lines of Python. The idea of trying to do the same task in assembler (or even C) is, to me, completely unthinkable. Furthermore, since I was making calls to the Python Image Library, I doubt that the "low-level versions" would've been any more time or space efficient. Finally, I can migrate that work to a new OS or hardware platform just by copying my little Python script. If I wrote a barcode reader in Intel assembler and my boss called me to the server room to show off a new Sun server, I think I'd just keel over dead and never get back up.

      --
      Dewey, what part of this looks like authorities should be involved?
    11. Re:Smaller code? We can hope... by CoolGuySteve · · Score: 1

      Why is executable size even an issue? A jump or branch instruction can cover a fairly wide chunk of memory so that it doesn't really make much of a difference if you jump over 10 or 10 000 lines of code and dynamic linking doesn't have much overhead. If anything, the 100K app will probably run slower because of shortcuts the programmer took (not unrolling loops, storing more arguments on the stack than necessary, etc.).

      For most architectures, less instructions != faster code. The only time I can think of where this isn't true is when you have a large cache, want to fit your whole program into it, the OS and hardware will actually let you do so, and the larger executable wouldn't be able to fit.

      The bloat isn't in the language, it's in the libraries people are using. Fltk and KDE/Qt are both C++ libraries but have a huge difference in performance/features/appearance/usability. Using either is a matter of tradeoffs that the programmer is willing to make but both are miles ahead of raw assembly in most matters.

      Libraries also allow for far more functionality and reliability. It's the little things like having functional and bug free scroll bars in your interface that people take for granted. Try, for example, loading a JPEG image in assembly. You can do it, somebody probably has already, but I'd rather just call to something that can be compiled for all the platforms I'll ever use.

      On the other hand, programs streaming megabytes of things like useless images off the disk is responsible for a lot of the shittyness in modern computing, so maybe some libraries are making things a little too easy.

    12. Re:Smaller code? We can hope... by Cuthalion · · Score: 1

      Even if you could duplicate the functionality in the off-the-shelf components instantaneously, it STILL wouldn't be worth it in most cases.

      Why? The more code you write, the more code you have to maintain, the more code you have to debug, and the more code additional programmers who join the project have to learn.

      --
      Trees can't go dancing
      So do them a big favor
      Pretend dancing stinks!
    13. Re:Smaller code? We can hope... by PaulBu · · Score: 1

      I see that we do agree on the most important points, just a bit of nitpicking on my side! ;-)

      "... wide majority of modern applications." -- yeah, the _modern_ part is what makes me kind of nervous... Is it me getting old, or, as I said to my friend some years ago, "You do not get much out of Java which you can not get from a g++ with an added flag to disable dereference operator"?

      My KPilot is bored until I press the HotSync button on my Palm. Hey! This is what HLT instruction is for! Save some electrones until that hardware interrupt arrives! ;-)

      Do not get me started on that topic - we just don't have the time to go there. ;-) Any time I hear someone say "middleware", I feel the urge to run screaming. As you could tell, I used much less respectful word for the thing... ;-) I am happy I do not have to actually work on the marketplace when the intimate knowledge of the middleware flavour of the day is required (though I would not mind being paid like those guys ;-) ).

      Your story about Python (and above-mentioned GTK) was exactly what I would expect from a reasonable educated guy, really, especially since I pretty much hold the same views. One of the coolest systems I ever had to work with was Cadence (big EDA CAD system), most of interesting parts written in their Scheme dialect. Autocad, BTW, too... ;-)

      I even enterntaned for a while an idea of sitting down and writing a chip layout editor in Python and GTK (around GnomeCanvas), except that the Canvas did not keep the CTA matrices with the object groups (think, cells) and I could not have the same cell on the screen in, say, different orientations. ;-) OTOH, the GnomeCanvas low-level implementation deserves to be coded not even in assembly, but in different GPU's assemblies, to bring us back to the original point! ;-)

      Anyway, good luck!

      Paul B.

    14. Re:Smaller code? We can hope... by rhild · · Score: 1

      If you want to see someone who writes incredibly useful Windows GUI programs in assembler, some in less than 20Kb, check out Gibson Research

      I'm always amazed when I go to download one of his programs and it takes less than a second, and that's an uncompressed EXE, not a zip file!

    15. Re:Smaller code? We can hope... by Khelder · · Score: 1

      If your biggest problem with modern apps is that they're too big and slow, I envy you. As a user, I'm a lot more annoyed by the fact that so many apps are hard to use and insecure. As a developer, I'd put a *much* higher priority on making programs easier to debug, maintain, and extend than on size and speed.

      (Of course, in some application areas, like scientific computing, performance is critical. But for the vast majority of apps, that's not the case.)

  9. 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.
  10. original title by Anonymous Coward · · Score: 1, Funny

    "Why Learning Assembly Language Is Still Good and Why I Still Can't Get Laid"

    1. Re:original title by Anonymous Coward · · Score: 0

      Hey, don't knock it. Learning Assembly is one of the most powerful contraceptives known to man!

  11. Suprised there isn't a Visual Assemblers by now... by Anonymous Coward · · Score: 0

    :)

    What ever happened to Intel's X86 Reference Manuals?

  12. 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 Daniel_Staal · · Score: 1

      I feel I should mention assembly was the one class where I ever turned in a program that was my first draft, and that I had never tried running myself. (And yes, it ran for the teacher. I was not surprised.)

      Now, my classmates could never quite seem to get theirs to work right...

      --
      'Sensible' is a curse word.
    2. Re:I disagree by Anonymous Coward · · Score: 0

      output: ".dlrow olleH"

    3. 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.

    4. 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.

    5. Re:I disagree by Junta · · Score: 1

      One aspect that bothered me about the assembly course I did was that the professor had the exact opposite beliefs. He felt that no C compiler could ever beat a hand crafted assembly program in terms of speed/efficiency. His absolute measurment of this? LOC. If the resultant assembly had more LOC, it was obviously inefficient as there were more instructions to execute. Discarded was the fact that his provided 'dramatic example' leveraged several loops in the assembly code and the C compiled equivalent had none... His response was that the unrolled loops did nothing but take up system memory and disk storage, and that though he could not prove it, he was sure the assembly program would complete the task first...

      --
      XML is like violence. If it doesn't solve the problem, use more.
    6. 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.
    7. 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

    8. Re:I disagree by multipartmixed · · Score: 1

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

      Let him pick the dataset size if you can pick the data.

      (Hint: sort it first, and flip the last two elements)

      --

      Do daemons dream of electric sleep()?
    9. Re:I disagree by Alwin+Henseler · · Score: 1
      Speed measured in LOC, Lines-Of-Code? That's nonsense.

      For all assembly languages that I've seen, there's 2 metrics involved: code size (exact number of bytes) and clock cycles needed for execution.

      Most assembly languages have varying number of bytes per instruction, and varying number of clock cycles needed. Almost always, the simplest form of an instruction executes fastest, because a) it's coded in less bytes, and b) takes less cycles to execute

      A fancy looking one-liner might look fast, but gets coded in a long sequence of bytes, eating more clock cycles than a short sequence of simple counterparts.

    10. Re:I disagree by nacturation · · Score: 1

      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.

      I assume you'll be providing the fully compliant Javascript implementation for the PIC microcontroller? :)

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

      I'll put my crudely coded Javascript quicksort algorithm against your finely honed 100% assembly bubblesort algorithm any day.

      Only if Java's sort routine was written by someone intimately familiar with the target environment's assembly language.

      -michael

    12. Re:I disagree by Jeff+DeMaagd · · Score: 1

      The entire argument is that the people that understand assembly can write better programs even if they are using compiled or interpreted languages. The argument was never to see if you can get all programmers to use assembly all the time, that is stupid, even if half the programmers programmed asm half the time. It is about knowing how the computer works.

      As I've said before, a good mechanic can tear down and reassemble an internal combustion engine, and that my argument is that a good programmer can do the same on an ASM level should the need arise.

      The thing here is that assembly wasn't being promoted for general use, but for education. Education is this wonderful place where you learn lots of things, 90% of it which you may never find a use for, but you never know which 10% you need, so you learn a much broader range than you need.

      If you only learn the skills that you need to perform a certain kind job, you just went to a trade school.

    13. Re:I disagree by imsabbel · · Score: 1

      Well, what you call "properly designed bubblesort" is commonly known as "insertion sort".
      Bubblesort ALWAYS run O(n^2).

      --
      HI O WISE PRINCE. WHT TOOK U SO DAM LONG?
    14. Re:I disagree by shadow_slicer · · Score: 1
      I'll put my crudely coded Javascript quicksort algorithm against your finely honed 100% assembly bubblesort algorithm any day.

      Sure! I happen to have 8 millon lists, each containing 2 elements. Let's see who can sort them the fastest.

      Don't forget that the purported speed to these algorithms only really comes into play if the "problem size" is large. For practical problems you must take the average problem size into account when choosing your algorithm. There is no one-size-fits-all algorithm for anything (and that's why they still teach them..).

      What the article was saying this this:
      Writing in assembly language forces you to think about your problem. In order to write a solution in assembly language you almost have to have a god-like understanding of the problem. If you take this approach of near-god-like understanding of a problem and use it for higher language programming you end up getting much faster code much sooner with fewer bugs.

      There's nothing wrong with higher level languages in their place, but often times people use the ease of writing in these languages to write some quick solution with little thought behind it, and hope to test the bugs out of it.


      Myself, I don't agree with the article. I think that it's just that now that programming has become easy, a lot more people are doing it that wouldn't have bothered to take the effort necessary to program when it was hard. This means that you have more people that have lower expectations of required effort to do a certain job. Is it that suprising that the amount of effort expended by those involved is shows a correlation with the amount of effort they expect is required? But that's just my 010b cents....
    15. Re:I disagree by c · · Score: 1

      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.

      You know, I really hate that "it's okay if my code sucks as long as it's not bubblesort" argument.

      Good algorithm selection is, of course, good coding practice. But that's not the point of the article.

      Yeah, quicksort beats bubblesort anyday. A large man can beat up children, too, but that doesn't mean he can fight.

      The reality is that your crudely coded Javascript quicksort would never go up against an assembly bubblesort. It would be compared to a C implementation (like, say, qsort(3)) done by someone who actually understands stuff like cache footprints, memory access patterns, tail recursion, and all that other goodness that you learn from spending time close to the metal.

      c.

      --
      Log in or piss off.
    16. Re:I disagree by Anonymous Coward · · Score: 0

      The thing here is that assembly wasn't being promoted for general use, but for education.

      Wouldn't understanding what the article is promoting require one to read the article? Am I on the wrong site?

    17. 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!
    18. Re:I disagree by Jason1729 · · Score: 1

      I assume you'll be providing the fully compliant Javascript implementation for the PIC microcontroller?

      You're the one who seemed to think Java was a good development choice. It should be your responsibility to make it work in the required environment.

      Anyway, take a look at the Aino Java cross-compiler for the PIC family. It will compile Java to run on the PIC.

    19. Re:I disagree by nacturation · · Score: 1

      You're the one who seemed to think Java was a good development choice. It should be your responsibility to make it work in the required environment.

      Yeah, okay dude. You specifically selected your so-called "required environment" to make the comparison fully meaningless. I'll just let you enjoy adding ridiculous constraints to a problem stated in an analogy. I'm sure I could also think up constraints of my own to make your choice of a PIC controller useless, but what's the point? It's an analogy.

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

      No, my point all along is that it is essential for any good programmer to know how to program in assembly language, simply because it's necessary to really understand how the underlying hardware works so you can write effective code.

      Your blind statement that your inefficient coding of what you're saying is an efficient algorithm is better than any possible efficient coding of a less efficient algorithm simply proves that point.

      If you had a strong foundation in assembly, you wouldn't have made such a broad statement, because you'd understand the large demands quicksort has for system resources. Recursion is computationally very expensive to do, but in your high level ivory tower, that's all hidden from you. By choosing a platform that is incapable of the requried recursion, I just highlighted the point.

      I'm also not sure what you're calling an analogy.

      I never said a PIC controller was the ultimate computing platform. In fact, I picked a specific task the PIC was essentially useless for. It also is pretty useless at bit banging gigabit ethernet or USB. The baseline units don't even have an integer multiplication instruction.

    21. 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.
    22. 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.

    23. Re:I disagree by nacturation · · Score: 1

      No, my point all along is that it is essential for any good programmer to know how to program in assembly language, simply because it's necessary to really understand how the underlying hardware works so you can write effective code.

      Sometimes knowledge of the underlying hardware is required. For most modern desktop systems, writing typical application software doesn't require this and it's completely unnecessary.

      Your blind statement that your inefficient coding of what you're saying is an efficient algorithm is better than any possible efficient coding of a less efficient algorithm simply proves that point.

      How's that? Your point is that it's necessary to really understand how the underlying hardware works. Okay, great. So if you write perfectly optimized assembly using an O(n!) algorithm, are you saying it'll be better performing than an O(n) algorithm written by somebody who doesn't really understand the hardware? That's absurd.

      If you had a strong foundation in assembly, you wouldn't have made such a broad statement, because you'd understand the large demands quicksort has for system resources. Recursion is computationally very expensive to do, but in your high level ivory tower, that's all hidden from you. By choosing a platform that is incapable of the requried recursion, I just highlighted the point.

      You shouldn't assume things you don't know. Given additional constraints, I would have selected a different algorithm. It's very rude of you to assume I'm such an idiot that I'd choose an algorithm which is impossible to implement on certain hardware. I mean, really. You should give people a little more credit than that before making such a stupid statement.

      In any software project, part of planning includes an analysis of the target platform and what constraints will be imposed. In the case you mentioned, a simple microcontroller, I would likely also choose assembly for performance and due to size constraints. However, I probably wouldn't choose bubble sort as there are much more efficient algorithms available which don't consume much more additional resources and which would give much better performance. As for what I would choose, that's what detailed analysis is for.

      Given modern desktop systems with sufficient resources, I'll take my high-level ivory tower, thank you. I've been in the dirty dungeons of assembly before and I'll take the tower over the dungeon whenever I can.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    24. Re:I disagree by Anonymous Coward · · Score: 0
      Direct algorithmic complexity doesn't always matter. If you typically sort 10000 lists of 200 elements long and only seldomly 10000 element lists then O(f(n)) type increasement of computational requirements measure doesn't matter.

      People sometimes choose algorithms which are faster with large N but fail to remember that whne program is run, N = M, where M is quite small number.

    25. Re:I disagree by marsu_k · · Score: 1
      Anyway, take a look at the Aino Java cross-compiler for the PIC family. It will compile Java to run on the PIC.
      Looks quite interesting. However, you are confusing terminology here. Javascript is a scripting language developed by Netscape, often abused in web pages but it has some genuine uses (form validation in the client side, for example). This is the language the original poster was referring to.

      Java, on the other hand, is an object-oriented language developed by Sun - IMHO a very good language in it's own right, definitely not the right tool for every job but very suited for some; just a shame that the current Sun administration seems to be very talented in making very poor decisions. Certainly not as slow (anymore) than most people claim here.

    26. Re:I disagree by bendelo · · Score: 1

      On a P4-M 1.4GHz notebook, it takes 581ms while running in Opera under Windows XP

      Not bad, you certainly owned the assembly Bubblesort. However your program only manages 40,000 comparisons (compared to my 16,000,000) per second.

    27. Re:I disagree by Frnknstn · · Score: 1

      > (Hint: sort it first, and flip the last two elements)

      hint for the other guy: Pick a dataset size of one element :)

      --
      If it's in you sig, it's in your post.
    28. Re:I disagree by nacturation · · Score: 1

      Not bad, you certainly owned the assembly Bubblesort. However your program only manages 40,000 comparisons (compared to my 16,000,000) per second.

      I knew it would be less performance. But it seems to validate my assertion that a better algorithm can do better than a hand-coded assembly poor algorithm even if it's far less than optimal.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    29. Re:I disagree by no+longer+myself · · Score: 1
      No. An insertion sort requires 2 list structures. Bubble sorts only require one.

      Insertion sorts "insert" the data in order to a second list, while bubble sorts "swap" if O[n] > O[n+1].

      If you simply run a bubble sort in a nested loop, then yes, it will run n*n, but adding a simple flag that checks to see if there were no swaps during an inner loop pass followed by an exit can greatly reduce the number of unnecessary passes. Therefore, the less random the data, the better the bubblesort performs.

      All that and without the need to allocate room for a second list structure.

    30. Re:I disagree by bendelo · · Score: 1
      Ok, I've improved my Bubblesort implementation. It just about matches the Javascript quicksort time for 3,000 bytes.
      0100 MOV CX,0130
      0103 MOV DX,3000
      0106 MOV BX,CX
      0108 MOV AX,[BX]
      010A CMP AL,AH
      010C JLE 0112
      010E XCHG AL,AH
      0110 MOV [BX],AX
      0112 ADD BX,+01
      0115 CMP BX,DX
      0117 JL 0108
      0119 SUB DX,+01
      011C CMP CX,DX
      011E JLE 0106
      0120 INT 20
      Datasize / Time
      3,000 - 0.6s
      12,000 - 2.5s
      24,000 - 7.4s
    31. Re:I disagree by nacturation · · Score: 1

      Very interesting. I changed around the numbers and re-ran the javascript version. In Opera, still on a 1.4GHz P4-M notebook, it finished with the following times:

      3,000: ~580ms
      12,000: ~3.9s
      24,000: ~11.2s

      Then I tried it under Internet Explorer:

      3,000: ~610ms
      12,000: ~5.8s
      24,000: ~21.4s

      And, the interesting part, under Netscape 7:

      3,000: ~171ms
      12,000: ~1s
      24,000: ~2.8s

      So it looks like Netscape has the best javascript implementation, whereas IE's is a real pig. I haven't tried Mozilla, Firefox, etc. but I'm guessing there's no real difference from Netscape.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    32. Re:I disagree by slashdotjunker · · Score: 1
      Kernel-level routines, games, drivers, etc. all benefit from tight coding in assembly language.

      I just want to kill an urban legend in the making. The public still seems to buy into the myth that games are written in tight assembly loops and game programmers are elite assembly hackers. This was true about 10 years ago. Modern games use very little assembly code. On a 25 man team, maybe only 1 person will write any assembly code at all (the lead graphics programmer). Even then, it will generally be only about 100-200 lines of GPU code.

      Sometimes old assembly code will get grandfathered into a new project. A PS2 project I worked on had a few routines that were originally written for the Sega Genesis. Someone had translated the assembly code into C code so it would compile. All the local variables were named after registers and there were gotos everywhere instead of flow control statements. It was both sad and funny. The really sad part was that we shipped it that way because no one had time to waste rewriting something that worked.

      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.

      I'll take your Javascript quicksort against my bubblesort. I have no doubt at all about who will win. You should try to really understand algorithms instead of just looking at the big-O in a reference table. It will make you a better programmer.

    33. Re:I disagree by bendelo · · Score: 1

      Looks like assembly Bubblesort beats javascript Qsort (under Opera/IE) for large (<24,000) datasets. Very interesting indeed.

      Now back to revising...

    34. Re:I disagree by nacturation · · Score: 1

      What would be really fun to see is an assembly version of quicksort. It would probably finish in about 10ms for 24,000 items. :)

      But I think we've exhausted the bubble- to quick-sort comparison already. Even a bloated interpreted environment with all its overhead can hold up pretty well against optimized assembly given a sufficiently better algorithm.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
    35. Re:I disagree by bendelo · · Score: 1
      What would be really fun to see is an assembly version of quicksort. It would probably finish in about 10ms for 24,000 items.

      Guess what? I've just coded an assembly quicksort. And yes.. it takes < 150ms for 24,000 items (and 140ms for 1,000 items). I could probably improve the swapping method for the 'split'.
      0100 MOV BX,0150
      0103 MOV CX,6000
      0106 PUSH BX
      0107 MOV AX,BX
      0109 INC AX
      010A CMP CX,AX
      010C JLE 013D
      010E PUSH BX
      010F PUSH CX
      0110 PUSH BX
      0111 MOV AH,[BX]
      0113 INC BX
      0114 MOV AL,[BX]
      0116 CMP AH,AL
      0118 JL 011D
      011A INC BX
      011B JMP 0128
      011D DEC CX
      011E XCHG BX,CX
      0120 MOV DL,[BX]
      0122 MOV [BX],AL
      0124 XCHG BX,CX
      0126 MOV [BX],DL
      0128 CMP BX,CX
      012A JNZ 0114
      012C DEC CX
      012D MOV DX,BX
      012F MOV BX,CX
      0131 MOV AL,[BX]
      0133 MOV [BX],AH
      0135 POP BX
      0136 MOV [BX],AL
      0138 MOV BX,DX
      013A POP CX
      013B JMP 0141
      013D MOV CX,BX
      013F DEC CX
      0140 POP BX
      0141 CMP SP,-02
      0144 JNZ 0107
      0146 INT 20
    36. Re:I disagree by nacturation · · Score: 1

      Yep, that'll kick javascript ass! :)

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
  13. 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.

    1. Re:It's like learning any language by Jonah+Hex · · Score: 0

      Anyone care to define these bits of language, I've seen at least something similar in the news/discussions about the new linux scheduler but I can't recall what the heck the notation means:
      O(n^2)
      O(n lg n)
      O(1)

      Jonah Hex

    2. Re:It's like learning any language by RichMan · · Score: 1

      These are expresions for the complexity of a problem.
      Given n elements to deal with different algorithms will require different amounts of processing to complete.

      Given n elements in a linear array and a normal processor finding the sum of those elements is an Order(n) task. Written O(n) it means the complexity of the task scales directly with number of elements n.

      O(n^2) -> order n^2, as n goes up the complexity of the task goes up as n squared.
      O(n log n) -> order n * log(n)
      O(1) -> order 1, operation is independent of n.

      For a lisp like list finding the length of a list is O(n) because you have to traverse the elements and count them. A good vector class will keep the length of the vector along with the data and finding that length is O(1) because it is directly available.

      Search, sort , merge, and insert algorithms go O(n log n), O(n^2) and all sorts of other orders.

    3. Re:It's like learning any language by ChrisLambrou · · Score: 1

      Known as 'big-O' notation, it's a way of describing the efficiency of an algorithm. A quick google search for 'big o notation' led to this page which has a fairly clear explaination, provided your maths isn't too rusty.

      Basically it's an expression of how much computation is required to execute an algorithm on a problem of size n.

      O(n^2) indicates that the amount of computation required to execute the algorithm is of the order of n squared. That it, if you double the size of a problem, it will take the algorithm appropximately four times the amount of computation to solve.

      O(n log n) indicates that the amount of computation required to execute the algorithm is of the order of n times the logarithm of n.

      O(1) indicates that the amount of computation required to execute the algorithm is fixed and is independent of n.

      If you look at how these different functions 'blow up' as n increases, you can see that for large problems we ideally look to use O(1) and O(log n) algorithms. O(n), O(n log n) and O(n^2) algorithms have significant scaleability issues and generally should only be used for problems where there is no practical alternative, where you can be sure that n will never be large enough to cause problems due to excessive computation.

    4. Re:It's like learning any language by mindstrm · · Score: 1
      Nitpick.. the O does not stand for Order, though it does seem convenient.

      It used to be a capital Omicron.. nowadays it's just a capital O.

      Wikipedia does it better.

  14. 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.

    1. Re:Exposure useful, mastery not needed by Sunnan · · Score: 1
      Developers smarter than you have spent decades

      But if you want to become one of them?
      There has to be (and will be) a new generation working on kernels and compiler tech.
    2. Re:Exposure useful, mastery not needed by Ars-Fartsica · · Score: 1
      But if you want to become one of them?

      Build the next layer - semantic web tools, search engines, p2p networks etc. You don't need to rewrite the compiler or the OS - its done. You are free to move forward to the next layer, safely assuming you probably can't do a whole lot to vastly improve what already exists beneath.

    3. Re:Exposure useful, mastery not needed by TheGavster · · Score: 1

      The attitude that you can't improve the underlying layers leads to the feeling that inspecting how they work is pointless. Sure, HLL's presently compile things really efficiently, but without seeing how they work you can't make a logical progression upward; you can only guess at how the next stage is to be made. You don't need to be able to write it; you just need to be able to explain to yourself how it works in general terms, to see how the next step continues out from it.

      --
      "Because Science" is one step from "Because old book". Try "Because of my experiment testing my falsifiable assertion".
    4. Re:Exposure useful, mastery not needed by ErroneousBee · · Score: 1
      Developers smarter than you have spent decades building useful higher-level layers to speed up the development of complex code.

      What if all those high level languages start getting replaced bu IDEs that turn out the raw assembly? Assembler is supposed to be 7 times slower to code as a HLL, but most of that is in having to maintain lables and equates all over the place.

      I can see the day when something like eclipse gets good enough that it handles all the parmlist work and maintains a DSECT as you go, without having to scroll between CSECT and DSECT parts of the program. It could also maintain the boilerplate for well known situations, have a macro wizard that does the MF=E and MF=L forms simultaneously, and perhaps even be more efficient in its use of register saves, I'm always using STM into a 16 fullword savearea when Im only using a couple of registers.

      --
      **TODO** Steal someone elses sig.
    5. Re:Exposure useful, mastery not needed by t_allardyce · · Score: 1

      True but assembly does give you an insight into the lower levels and while it might not be relevent to learn every architecture in detail, it certainly helps to know some basics, even if its just learning PIC!

      --
      This comment does not represent the views or opinions of the user.
    6. Re:Exposure useful, mastery not needed by mike260 · · Score: 1

      It's not about "obsessively tweaking the finest details", it's about optimising a small amount of code and getting disproportionately large performance gains. What's wrong with that?

    7. Re:Exposure useful, mastery not needed by Brandybuck · · Score: 1

      Programming is like building a house. When you look at the best building contractors, you'll notice an odd thing. They all know how to use hammers and nails! Gasp! Only in programming do we cast aspersions upon those who know how to use hammers, saws and screwdrivers.

      You don't have to currently program in assembly, C, or another low level language, but you are expected to know how.

      --
      Don't blame me, I didn't vote for either of them!
    8. Re:Exposure useful, mastery not needed by Ars-Fartsica · · Score: 1
      The attitude that you can't improve the underlying layers leads to the feeling that inspecting how they work is pointless.

      No, its just the realistic understanding that I cannot write a kernel demonstrably superior to FreeBSD, Linux, etc.

      That doesn't mean I can't read the source.

    9. Re:Exposure useful, mastery not needed by Ars-Fartsica · · Score: 1
      You don't have to currently program in assembly, C, or another low level language, but you are expected to know how.

      Okay expert, write quicksort for me in assembler.

    10. Re:Exposure useful, mastery not needed by Sunnan · · Score: 1
      Sure, there needs to be people that build upward and just "trust" the layers beneath, but I'm talking about those who can still improve on the layers beneath.

      A few examples
      1. GCC could use optimization.
      2. Psyco still only works on x86
      3. Mono could use work on non-x86-platforms.

      No, its just the realistic understanding that I cannot write a kernel demonstrably superior to FreeBSD, Linux, etc.

      But maybe improve on them?
    11. Re:Exposure useful, mastery not needed by Anonymous Coward · · Score: 0

      Mono could use _a lot_ of work on the x86, so I'm sure it needs a few times that for other platforms.

  15. 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 Anonymous Coward · · Score: 0

      you should write a series of in-depth tutorials or something. i'm interested.

    2. Re:desire to teach someone 6502 assembly language by Handpaper · · Score: 1
      Damn, the instruction set and address space on that thing is small enough that you can keypunch in hex if you want to - I did in an A-level electronics (not CS) class c.13 years ago, as an introduction to microprocessors. We had to write a simple program to control a set of 'traffic lights' - it could be done by loading/storing preset data, but was more fun (and faster, as if that mattered) to play with registers. IIRC, 0xA9 was the instruction to load the main register.
      I just looked - people still use those things!

    3. Re:desire to teach someone 6502 assembly language by RGreene · · Score: 1

      Not only do we USE these things, we design and build our own computer with them!!

      By the way, there are a number of true wizards at 6502.org. If you need the resource, they are the ones to talk to.

    4. 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.
    5. 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

    6. 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.
    7. Re:desire to teach someone 6502 assembly language by sm8000 · · Score: 1

      Why not see if your local community college or technical school will let you teach it there?

    8. Re:desire to teach someone 6502 assembly language by Handpaper · · Score: 1
      Totally offtopic now, but perhaps somebody knows....
      There was a rumour circulating about ten years ago that someone was trying to build ether a massively-parallel system or a neural-net processor using up to 64 6502s. I'd be interested to know if anything came of it. RGreene, you seem to be in the loop. Heard anything?

    9. Re:desire to teach someone 6502 assembly language by RGreene · · Score: 1

      Sticking in the off-topic arena, I'd suggest posting the question on 6502.org. I've never heard of it - although there have been discussions regarding how to do multi-processor 6502's.

  16. 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 exp(pi*sqrt(163)) · · Score: 1

      Game developers - especially console game developers.

      --
      Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    2. 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.

    3. Re:how many people actually program in assembly? by Jeff+DeMaagd · · Score: 1

      None of those arguments are terribly convincing, Being able to understand how the internals work can be critical to how well one can maintain a system. Would you want a mechanic that doesn't understand how an internal combustion engine works? If not, then why would you want a programmer that hasn't at least been exposed to how a basic CPU works?

      I've done two or three major microcontroller architectures, and I think it's kind of fun for those tasks. I now have a C compiler, but there were still instances where I did a complete assembly program.

      While most programmers may not use assembly in actual practice, I still believe it is a necessary part of computer science education, because education is often about blitkrieg - there isn't enough time to truly master anything, but at least you've covered it enough to understand the basics, whether it be compiled, interpreted or assembled.

      I fully understand that very few programmers will program in assembly, but I think having mastered that skill helps create a better breed of programmer.

    4. Re:how many people actually program in assembly? by Anonymous Coward · · Score: 0

      To make matters worse, each CPU has it's own instruction set

      For almost everyone, this is obvious. The simple fact that you mention this, prove that you don't have much experience with assembly.

      This is the problem with assembly. There's a lot of people who have an opinion, but very few who really know what they are talking about.

    5. Re:how many people actually program in assembly? by Anonymous Coward · · Score: 0

      OS developers. Even then, a shockingly high number don't understand assembly.

    6. Re:how many people actually program in assembly? by Anonymous Coward · · Score: 0

      "To make matters worse, each CPU has it's own instruction set"

      Yup, they do. And having learned assembly years ago on the Z80 and 6502, I can pick up the 68K manual and program in that, the x86 manual, and program in that.. albeit a small learning curve, but knowing how a processor works, I can pick up any architecture in a day. Becoming a "guru" at it, naturally, takes some time... but I could pick up the manual and write you a quick asm program in a day.

    7. Re:how many people actually program in assembly? by Doppler00 · · Score: 1

      I don't mean that it makes it more difficult to program in various flavors of assembly, but that the resulting code your write is non-portable. If I write a routine in C, I'm almost guaranteed to be able to use it on another platform.

    8. Re:how many people actually program in assembly? by Angst+Badger · · Score: 1
      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.

      Compilers don't optimize everything, though. No compiler will correct for your inefficient use of memory, for example. Compilers won't compensate for your failure to understand how the CPU cache works, secondary storage and network latency, etc. Neither will assembly, mind you, but when writing in assembly, you have to think about these things, and when you later spend 99% of your time in a high-level language, you will at least be conscious of them.

      One thing I see in programs all the time that just boggles my mind are elaborate sets of conditionals revolving around the value of several boolean variables -- usually implemented in C as ints. You'll see something like this...
      if(flag1 && flag2 && flag3 && flag4) {
      /* something happens here */
      }
      ...which wastes (on a 32-bit machine) 128 bits to store what only needs four bits, and a bunch of clock cycles to load and test four separate values before executing a jump. If all these values were bits in a single int (or short int, for that matter), you could do a bitwise mask by ORing several constants together...
      if(flagvar & (FLAG1|FLAG2|FLAG3|FLAG4)) {
      /* something happens here */
      }
      ...and get your result much more efficiently. This is going to be flamingly obvious to someone with assembly language experience, but will probably not occur to someone who recently learned C++ or Java as a first language in school. Nor will it be obvious that
      if(flag)
      is more efficient than
      if(flag != 0)
      nor will it be clear why.

      Now, none of this is a recommendation that everything be written in assembly language. You should probably always use the highest-level language that meets your needs. But knowing what's happening "down there" will help with those high-level languages, and won't necessarily make your code unclear.
      --
      Proud member of the Weirdo-American community.
    9. Re:how many people actually program in assembly? by Anonymous Coward · · Score: 0

      Any compiler is free to store several bitfields in one word. The downside is that you have to read-modify-write the word with memory barriers (or risk losing other threads' writes) instead of just writing a constant.

      "if (flag)" and "if (flag != 0)" are exactly equivalent, and a compiler that produces different code for them is severely brain-damaged.

    10. Re:how many people actually program in assembly? by Angst+Badger · · Score: 1

      "if (flag)" and "if (flag != 0)" are exactly equivalent, and a compiler that produces different code for them is severely brain-damaged.

      Then the overwhelming majority of compilers are severely brain-damaged, but then, you'd have to know assembly language to realize that. (Or type promotion rules in C.)

      --
      Proud member of the Weirdo-American community.
    11. Re:how many people actually program in assembly? by Anonymous Coward · · Score: 0

      Uh, what do you think "if (flag)" means, if not "does that object contain zero or null?"

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

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

    1. Re:In what other languages by Dwedit · · Score: 1

      For a second there I thought you were defining the origin address...

      - Hopelessly obsesswith with asm.

  18. 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.

    1. Re:Not just efficiency but correctness by IamTheRealMike · · Score: 1

      To be fair I think double-check locking is only broken on non-x86 architectures where you need to erect memory barriers, or something similar. It's very subtle and wouldn't surprise me at all that your co-workers didn't realise it was broken.

      Of course, I may have got totally the wrong idea, in which case please explain it to me too :)

      ps. i am assuming you are talking about

      if (condition) { // first check
      synchronized(whatever) {
      if (condition) { // second check
      }
      }
      }

    2. Re:Not just efficiency but correctness by jkabbe · · Score: 1

      In Java that's not guaranteed to work. The Java spec does not require that it work on any architecture.

  19. 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
    2. Re:So What? by Anonymous Coward · · Score: 0, Offtopic

      Even more annoying if you admin a webserver with an insecure cgi script that will pass stuff to the shell. Ouch!

    3. Re:So What? by 42forty-two42 · · Score: 1

      If that's happening you have worse things to worry about than a mere DoS.

  20. HLA?...nah. by Anonymous Coward · · Score: 0

    He's just trying to promote his invented High Level Assembly language, which is no way proper assembly. Well, read his book and judge for yourself.

    1. Re:HLA?...nah. by exp(pi*sqrt(163)) · · Score: 1

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

      --
      Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    2. 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.

    3. Re:HLA?...nah. by exp(pi*sqrt(163)) · · Score: 1

      I've nothing against assembly. I just think 3 stories about a not very significant programming language (HLA) is getting dangerously close to spam.

      --
      Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
  21. The best reason to learn Assembly by GillBates0 · · Score: 1
    even *moreso* than efficiency, functionality and flexibility is that it enables you to delve into the innermost functionality of a computer.

    Master Assembly, and you've mastered computer organization, computer architecture, compiler construction basics, logic, code optimization, and ofcourse programming (I may have missed a few).

    It's no coincidence that every good programmer/compiler engineer I've met (I'm one too) has had a strong grasp of Assembly.

    --
    An Indian-American Hindu committed to non-violent thought/speech/action alarmed by the global explosion of radical Islam
  22. Sourcer, if you ever wanted to learn assembly... by Anonymous Coward · · Score: 0

    from someone else's experience.

    Sourcer

  23. Because by dtfinch · · Score: 1

    You need it to work on the zsnes project.

    Honestly, a fair understanding of assembly language may help you in the long run, despite the fact that you can probably go your entire career without using it directly, and that you're probably going too far most times you do use it. It's just part of knowing how a computer works.

  24. 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 skifreak87 · · Score: 1

      Biggest difference I've seen. Wrote a circuit simulator in C and then wrote it in assembly (in an array in C that was then executed as if it was a function - gotta love casting and pointers (*(void(*)(int*, int*, int*)) piCodeArray)(piInput, piCurrent, piNext); - that executed piCodeArray as a function w/ 3 int array params representing the input values for some constants, the current values for flip-flops, and the array to store subsequent ff values). Results: Using the Turing machine to emulate, the compiled version required .06
      seconds to emulate 10,000 clock cycles while the interpretive version used
      2.12 seconds (over 35 times as long to emulate that).

      Point: assembly can be advantageous but I wouldn't advise it in normal circumstances. I can write the unix wc command in C real quickly, to do it in assembly is a waste of my time b/c the C version is fast enough (i've done both for assignments, as well as echo and sort). It's important to know WHEN to optimize. 99.99% of stuff you write doesn't need it, so don't waste your time. Make the code clear and correct, better than unreadable and efficient and definitely better than efficient but wrong.

    2. 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.

    3. Re:As somebody who has done DSP algorithms by SMN · · Score: 1
      Was this by any chance something you did as an assignment for a class at Princeton? It sounds very familiar.

      That said, the difference between the simulated and the compiled circuits is analagous to difference between an interpreted language and compiled code, not a compiled language. It's more like Java vs. assembly than C vs. assembly.

      --
      -- Imagine how much more advanced our technology would be if we had eight fingers per hand.
    4. Re:As somebody who has done DSP algorithms by skifreak87 · · Score: 1

      Yes it is. CS 217 (Introduction to Programming Systems) at Princeton. Took it last fall.

  25. Even when you write in C... by Archeopteryx · · Score: 1

    Even when you write in C it helps a lot, especially in the embedded systems field, to know what sort of code the compiler is generating. For example, say I have a i++; operation that I expect to use to set a semaphore - is that one operation, such as a Z-80's inc , or is that a lda, inca, sta operation that might be interrupted? This can matter a lot! And I have seen compilers which were inconsistent as to what sort of code they would generate for such an operation. This is just one example, but there are many more, and they can make a BIG difference.

    Also, if you cannot read assembler, how are you ever going to figure out what strange compiled code, which has been stripped of its debugging symbols, is doing?

    --
    Dog is my co-pilot.
  26. 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.
    1. Re:Not sure about his premise by cbrocious · · Score: 1

      I don't think the point of the article was that assembly neccesarily be used. I think the point was more that knowing assembly and how computers work at a lower level will help you develop better code.

      --
      Disconnect and self-destruct, one bullet at a time.
  27. 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 Anonymous Coward · · Score: 1, Funny

      Shut up, Gabe, and release Half-Life 2 already.

    2. 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?
    3. Re:far more important than optimization by Stone316 · · Score: 1

      Thats why you run the code through a profiler, find the bottlenecks and optimize them. Maybe you will need to rewrite them in assembly, maybe you won't. I don't think he's saying that you'll never need it but you don't really need to focus on optimizing while coding. I think he hit the nail on the head.

      --
      "Thanks to the remote control I have the attention span of a gerbil."
    4. Re:far more important than optimization by gfody · · Score: 1

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

      write your shaders in C?

      --

      bite my glorious golden ass.
    5. Re:far more important than optimization by jeremyp · · Score: 1

      But if your game comes out three months earlier, you have the advantage.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    6. Re:far more important than optimization by Anonymous Coward · · Score: 0

      And when your billing system is down and your clients are sitting on their thumbs for a day while you try to figure out what the *heck* some jerk who worked here three years ago was doing in his code for the sake of "optimization" when it didn't need to be optimized at all...

  28. Embedded systems by Jason1729 · · Score: 1

    I use assembly every day to program embedded controllers. There are compilers for them, but I often use controllers with a few hundred instruction words of storage space and a few dozen bytes of ram. Compilers just aren't efficient enough.

    Jason

    ProfQuotes

  29. 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 Osty · · Score: 1

      The answer is simple -- use an emulator. That way, you don't have to provide hardware to your students, and you can use a nicer assembly language without worrying that you're actually using a x86. In short, the answer is SPIM, the MIPS R2000/R3000 simulator. The MIPS assembly language is nice and simple, with an abundance of registers that let you get going with simple apps early on. As complexity grows and the students learn, you can bring in the concept of pushing data onto the stack. It's free, and runs on Unix/Linux and Windows, so you don't have to track down a bunch of old R2000 or R3000 machines for students to use.


      If the end goal is to be able to write immediately-applicable code, x86 would be the way to go. If the goal is to learn about assembly languages and concepts, the platform doesn't much matter (or if it does, only to the extent that the language and hardware should be easy to learn).

    3. Re:Which Platforms? by UserChrisCanter4 · · Score: 1

      A friend of mine graduated with an ECE degree a couple of years ago. They learned on motorola 68K-series chips that were attached to a PCB with a small-ish amount of RAM. Data was loaded into and read from the PCB over a serial connection.

      The advantages of this situation were pretty obvious. You got platform portability, since you just have to find something with a serial connection and whip up an interface program for loading/reading the data. You get the 68K series ASM language, which I'm told is fairly pleasant as far as ASM goes, and you get to learn on a chip that's still very common in embedded markets, which counts for a bit more with ASM where there's so much difference between the various architectures.

    4. Re:Which Platforms? by pedantic+bore · · Score: 1

      I recommend the Ant microprocessor (which pre-dates and has nothing to do with the Java Ant project). It's a small architecture and was designed specifically for teaching. It has everything you need, and nothing that you do not.

      --
      Am I part of the core demographic for Swedish Fish?
    5. Re:Which Platforms? by Piquan · · Score: 1

      MIPS. It's a good baseline RISC system. There's free simulators (SPIM) and good books (Computer Organization and Design) for it. It's a straightforward and orthogonal system, so you learn about how assembly language works, rather than all the funky quirks of the architecture you're being taught on. The only thing that I might consider "quirky" is the prefetch execution slot, and that's common on RISCs anyway. You can ignore it by just sticking NOPs after branches until you're ready to learn about pipelining.

      When you are ready to tackle pipelining, the orthogonality of the instruction set makes it easy to discuss. When you're ready to do some gate work, you can make a basic CPU design for it in under a week.

      IMHO, you don't teach assembly so people use exactly what you teach to write programs after they graduate. Only the very worst CS programs think of things that way. You teach assembly so that the students understand computers. If you're teaching carpentry, you start by building birdhouses and tables that are easier to buy from a factory than build. Not because the student is going to build birdhouses, but because it's a good way to start teaching the basics.

      If you're still wanting something you can write to a machine you own, then skip x86; it sucks for learning. The Palms run on either a Dragonball or ARM. The Dragonball is 68000-descended. While that's better than x86, it's still CISC, which can be confusing to learn (paradoxically, since CISC has stuff to make assembly theoretically easier to write). The ARM is cool, but it has its own quirks that might not translate well to other machines. PowerPC (Mac, RS/6000, GameCube, series 1 TiVo) is probably your best bet if it's widespread enough for you.

    6. 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
    7. Re:Which Platforms? by Eil · · Score: 1


      I've always thought that the perfect cheap, low-level computer to teach Computer Science students assembly was with the one that most of them already have: A TI calculator.

      There's an entire subculture devoted to programming these things and it's amazing what some have done. I've been tempted so many times to take up assembly on my calculator, but for some reason my TI-86 was just never all that popular and TI no longer makes cables for it.

    8. Re:Which Platforms? by Alternate+Interior · · Score: 1

      I've always heard RISC chips aren't supposed to be coded by hand. CISC with its expanded instruction set is a much better candidate for hand coding, even at the cost of backwards compatibility.

  30. Well.. by Anonymous Coward · · Score: 0

    Well Bootloaders and ISR forced me to learn assembly. If you're going to do system programming then I'd highly recommend learning it. Otherwise I don't think its really nessacery.

  31. 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).

    2. Re:Try the games industry by TheRaven64 · · Score: 1
      To take full advantage of processor features like SSE or AltiVec you don't really have a choice.

      Writing SSE code is a nightmare at the best of times, but for AltiVec you should take a look at the C interface which has a direct correspondence with the assembly instructions but is a lot clearer to read.

      --
      I am TheRaven on Soylent News
  32. Important ....because Randal needs to sell books! by Anonymous Coward · · Score: 0

    The "Art of Assembly Language", anyone?

  33. i agree by Anonymous Coward · · Score: 0

    mov ax, assembly
    learning ax
    mov bx, good
    is ax, bx

  34. 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.

    1. Re:x86 aint what it used to be by DarkEdgeX · · Score: 0, Redundant
      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.

      Actually it's still pretty well documented which instructions are executed in which order, even on the Pentium 4. Agner Fog has a very nice document that I tend to reference when writing x86 ASM routines (usually to be linked in with a higher level language because the HLL emits poorly optimized code (or simply is unable to take advantage of certain processor features)). Give it a look--

      http://www.agner.org/assem/

      --
      All I know about Bush is I had a good job when Clinton was president.
  35. OS using assembly by zymano · · Score: 1

    Checkem out.

    menuetos
    Unununium Operating System

    Nasm is the portable type assembler. Pretty cool.

  36. mother of OOP by Anonymous Coward · · Score: 0

    just try to code assembly without functions. :)

  37. uControllers + Assembly = Fun by Anonymous Coward · · Score: 1, Interesting

    Got my education in mechanical eng. once upon a time but was able to take a course on uprocessor applications and then ucontrollers (8bit) for robotics. No high level language here. Just straight Assembly code to fit in 32K of memory. You'd be surprised how much you can fit in there. Programs were fast and had to be efficient and I learned alot about architecture, as much as a mech eng could of course.

  38. TIME TO MARKET, even for free software by Ars-Fartsica · · Score: 1

    Even in open source apps, getting something out there ready to play with is key. Actually this may be even more central to open source ecosystems than corporate development. Would you prefer that the Mozilla developers have taken the assembly route? They'd probably be well on their way to rendering the bold tag by now but thats about it.

  39. It's tough to do well on some architectures by tommasz · · Score: 1

    Assembly is a great idea when speed and compactness is necessary, but it's tough to do it well on some processor architectures, RISC in particular. A well-tuned compiler backend for those can probably out-code most (but not all) humans - and the more registers you have to keep track of, the bigger the gap. But even CISC (or CISC-like) architectures can be problematic. Consider branch prediction, to cite one example. As much as I loved getting down to the "bare metal" on the 6800 and 68000, I'm glad I can use something else today.

  40. 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.
  41. Intel Architecture Manuals by Anonymous Coward · · Score: 1, Informative

    Here they are.

    Or you may prefer AMD-64, here.

  42. 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

    1. Re:The problem with assembly... by sodergren · · Score: 1

      But it really depends on the requirements of the code that you are writing...

      Coding a time-critical interrupt service routine is a lot different than coding an instant messenger GUI or a word processor. Sometimes knowing the base hardware and coding directly for it is the only way to get a task done. Knuth's optimization rule doesn't make sense if you are trying to squeeze every last cycle out of a hardware-specific routine.

      As usual, no one methodology covers all cases. The right tool for the job, etc.

  43. How can learning assembly not be mind expanding? by exp(pi*sqrt(163)) · · Score: 1
    It's a different paradigm for programming. Every paradigm opens up new ways of developing software that can be applied to other programming languages.

    Even if you never write a single line of assembly in your life there are times when you might need to understand the concepts - for example you might need to embed an interpreter for a language in your software and use a virtual machine. Before you do that it might be a good idea to know how people have designed real machines.

    --
    Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
  44. MIPS by IshanCaspian · · Score: 1

    At Boston University they teach us on MIPS. It was actually one of the easier courses I took there, but maybe that's because I've done a lot more programming than the average BU CS student.

    I would have rather bitten the bullet and learned x86, because I could actually USE that for something.

    --

    But there is another kind of evil that we must fear most... and that is the indifference of good men.
  45. Custom Built Embedded Boards by Rufosx · · Score: 1

    Just like I learned on in college. Ours were 6502 boards with a bunch of other stuff on them, like D/A converters and space to wire up more stuff. At that time we used Mac Pluses as the interface to program and load the assembly into the boards.

    These are produced specifically as teaching aids and I'm sure they are still available. We built all sorts of stuff on the boards including traffic light controllers, elevators control and robot servo controls. Fun stuff.

  46. 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.

  47. 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)
  48. The fact... by the_skywise · · Score: 1

    That somebody has to write an article to state this obvious point shows the sad state of programming that the 90's guerilla engineering training has brought us.

    (You too can earn a 6 digit salary in computer programming after our simple 2 week course that guarantees certification!)

    1. Re:The fact... by Wienaren · · Score: 1

      > that the 90's guerilla engineering training has brought us.

      Yeah, quite VISUAL, isn't it.

      --
      -- The Online Photo Editor - http://www.phixr.com
  49. it's a tradeoff by Trepidity · · Score: 1

    It's a tradeoff between maximally efficient code and simple code. Complicating matters further, in many cases what you'd think would be "maximally efficient" code isn't actually maximally efficient anymore, given that it's hard to predict what exactly is going to happen when your code is run through an optimizing compiler and then run on a pipelined CPU. In some cases silly optimization tricks C programmers who know assembly do actually slow down the code, because if they had written something simpler, the compiler could have optimized it, and the compiler knows better optimizations (or can compute better optimizations by looking at literally millions of different factors).

    Optimization tricks are also notoriously brittle--they're clever hacks that solve a particular problem more efficiently than the straightforward solution. The problem is that if you want to change things, the trick may not work anymore, so you're stuck rewriting it, or often you end up with subtle bugs, because you relied on some clever hacks whose assumptions no longer hold.

    And finally, "optimization" of the assembly-programmer sort often has negligible effects. If you actually profile, the biggest speed hits are invariably in a very few places. Most of your other "optimizations" are going to be making 0.001% speedups, if they even speed anything up at all (and sometimes they slow things down!). That's not only not worth it, it's detrimental to your application's development.

    This is even more of a problem in higher-level languages. Lisp, Haskell, and other functional languages do all sorts of stuff under the hood to optimize things, and various scattered parts of your code can interact (if some redundancies are found that can be optimized away, even across modules) so premature optimization is generally a bad idea.

    1. Re:it's a tradeoff by Anonymous Coward · · Score: 1, Informative

      You sound like someone who has read Knuth. Write clean and then find the bottlenecks. But remember that Knuth wouldn't argue against learning assembly language because to become a wizardly programmer you must do many things simultaneouly: understand how the computer works and be able to think like it (digital electronics and assembly programming), know how to translate abstract ideas into code (discrete mathematics and high level languages), know how to make something abstract enough to be able to be extended gracefully, know how to document code to be able to be understood, and know how to find bugs (thorough understanding of the architecture--OS, hardware, and application and an in-depth knowledge of memory operations (only taught by debugging assembly code)). Assembly isn't taught so that you can know tricks. Its taught so that you can have the knowledge to become a system expert if needed. This is similar to how most automotive mechanics don't know much about the metallurgical properties of the metals they are working on, but if you want to build a Formula 1 racecar you had better have one who does. Your companies VB monkies don't need to know assembly but it would be very nice to have at least one person who does.

    2. Re:it's a tradeoff by Anonymous Coward · · Score: 0
      It's a tradeoff between maximally efficient code and simple code. /blockquote. Many times simplicity goes hand in hand with efficiency. There is not necessarily a tradeoff.
  50. Knowing assembly is good by Maljin+Jolt · · Score: 1

    In past years, I noticed people who learned assembly previously are usually good C/C++ coders. I believe this is because knowing what machine really does at it's instruction level helps to imagine how it should be written in higher language. It is sad that Java and C# exists just because former visual basic people can't grasp a concept of a C pointer.

    What makes assembly superior is a hardware where resources such as memory or cpu speed are very scarce: embedded devices. Microcontrollers. Either you need less energy, either you stuff there more functionality, in critical systems that counts.

    Myself I began my coding experience on Z80, typing instructions on hexpad. Using own mind as an assembler, to this very day I remember 00 is a nop, C3 is jmp and C9 is a ret. Being able to do hex subtraction in head brought me great popularity in my first job, where reading cobol dumps from Univac mainframe was common daily task for programmers, usually trained in "higher" language only.

    Even today, unlike bugs in other software, compiler defects could be found only with a good understanding of assembly language.

    --
    There you are, staring at me again.
    1. Re:Knowing assembly is good by dtfinch · · Score: 1

      I've never had to code in hex. At best I'd assemble then copy the hex to use with languages that didn't support inline assembler. On the x86, about all I remember is that CD is INT, EE is OUT DX, AL, EB xx is JMP SHORT, FA is CLI, and FA EB FD freezes win9x.

  51. Assembly won't make logic die out by Wienaren · · Score: 1

    Assembly will educate your logic and your ability to think like the very machine does. Compilers, in the long run, just fade out that close feeling for effective code and noone - ever - can convince me that a compiler can optimize code better than a good assembly programmer. Being an assembly junkie myself, having won all benchmarks ever, still dreaming about the CPU cycles saved when using a moveq instead of move.l, I think assembly never will die out. SMON, where are you. And O.M.A., I hope you rest in peace.

    --
    -- The Online Photo Editor - http://www.phixr.com
  52. I program in assembly every day. by the_rajah · · Score: 1

    It's still the best way to produce a program that runs fast and with minimal resources. I wrote my first assembly language program in 1964, probably before a lot of you folks were born. The bulk of my assembly language programming has been for various microprocessors going back to the Fairchild/Mostek F-8, a horrible chip set, but it worked and was relatively cheap at the time (1976). I've done a lot on 8085 and 8051 systems for agricultural control systems and elevator (vertical transportation) controllers which are still supported some 20 years after they were first designed.

    If you understand assembly language, then you understand the intimate details of the system you are programming for.

    "Do the Right Thing. It will gratify some people and astound the rest." - Mark Twain

    --


    "Do the Right Thing. It will gratify some people and astound the rest." - Mark Twain
  53. knowing how the machine works if valuable by jay2003 · · Score: 1

    Computing is all about layers. To be really good at the layer you work at, you need to know something about the layers above you and the layers below you. For C/C++ programming, this means having an understanding of assembly and how the operating system works. I've seen many bad implementations when progammers did not understand the consquences of what they were doing.

  54. If you want to teach somebody 6502 by tepples · · Score: 1

    If you want to teach somebody 6502 assembly language, then find somebody on the forums at NESdev who's struggling.

    1. Re:If you want to teach somebody 6502 by Black+Acid · · Score: 1

      I second this. Programming the NES is a great application of 6502 assembly. Not only for coding games, but also Game Genie codes.

  55. PowerPC assembly? by An+Anonymous+Hero · · Score: 1
    The first milestone I achieved was the release in the mid-1990s of the electronic edition of The Art of Assembly Language. This book, along with the use of the accompanying UCR Standard Library for 80x86 Language Programmers, reduced the effort needed to learn assembly language programming.

    OK, is there (should there be?) anything like this for PowerPC assembly? I'm aware of these web pages:

    ...but neither seems to mention anything quite comparable to Hyde's book.
    1. Re:PowerPC assembly? by An+Anonymous+Hero · · Score: 1
      (should there be?)

      As a P.S. -- the sort of quote I had in mind, suggesting an affirmative answer is this:

      assembly language programming is essential background for every computer science and electronic engineering student. It is, however, often considered an arcane and complex discipline because many first encounter it through the daunting instructions and registers of the Intel 8086 family.

      Programming in a simple RISC architecture is very different due to the elegant and compact instruction set. Students of this text who have never programmed before and study it simultaneously with a course on a higher-level language report it is easier and more logical to program in assembly!

      (referring unfortunately to an MIPS, not PPC book).
  56. 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

  57. 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.

  58. 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.

  59. 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.

  60. I read Randal Hyde's AoA by ta+bu+shi+da+yu · · Score: 0

    Or rather, Art of Assembly. Possibly the best information on assembly language programming I've ever seen!

    --
    XML is like violence. If it doesn't solve the problem, use more.
  61. Orgasm is an assembler... or two by tepples · · Score: 1

    Given that one of the keywords in most assembly languages is ORG, stating the origin point where the assembly begins, yes you can if you're compiling it with an assembler called Orgasm or another assembler called Orgasm.

  62. 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
    1. Re:This is the wrong reason to learn assembly by Jamie+Lokier · · Score: 1
      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

      I beg to differ. Two decades ago I learned to program around the age of 10. Classes: none. I didn't have formal education in computing until I was 18. Languages: 6502 and Z80 assembler, and BBC BASIC. Documentation: a two page table at the back of the BBC manual, and the equivalent in a Torch manual, showing mnemonics, opcodes and timings. A 10 year old was able to guess what most of the mnemonics meant and figure it out from there.

      Most of my peers who went on to be seasoned programmers seemed to be doing similar things with other computers. That was the age of 8-bit microcomputers, when people's first language was BASIC and/or assembly language, and lots of people were writing tightly-coded games in their bedrooms, remember?

      I agree with the observation that having studied machine language is helpful for understanding pointers, pointer arithmetic, memory layout, references, boxed and unboxed types and such. However, I would say that anyone who properly understands C has adequate understanding of these things too.

      If one is going to do programming where pointers would be used (systems programming and lower level applications programming, such as in C)

      In high-level Java and Javascript, every non-primitive value is a pointer. Discuss. :-)

      -- Jamie

    2. Re:This is the wrong reason to learn assembly by Skapare · · Score: 1

      You are one of the exceptions; why I used the word "most".

      What you call pointers in Java and Javascript are really references. You do not have methods available to increment or decrement that pointer. You can only either use it, or ignore it. To be a true pointer you have to be able to modify it, including doing things like masking it to move it to certain storage boundaries.

      --
      now we need to go OSS in diesel cars
  63. 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...
  64. Agree...but it's more about the OS than the proces by mindstrm · · Score: 1

    So long as we are talking about making full applications work in assembly in the target system.

    (ie: not so much about the code & algorithms, but abouut how that code exists in the system.)

    Understanding the OS, how sockets are dealt with, what context switches are, how shared libraries are handled (ie: Windows and Linux are VERY different in this regard, and not understanding this can lead you to write really shitty applications) is very important.

    I've had to use so many applications that just SUCK from a systems point of view, because they were written without consideration for the target system.

    I think assembly still has a lot to teach us, but it's no longer simply in the area of optimized instructions... that is done almost as well, if not better overall, by compilers nowadays. The real trick is that working in assembly makes you learn how the OS *really* works, and moves data around.. and that's what you really need to know.

  65. 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 Temporal · · Score: 1

      And my point is, in the vast majority of cases, thinking about efficiency is a waste of time. Passing a 2k struct by value (although I've never seen it done) is irrelevant if you're only doing it a couple times per user input. So, if it is for some reason more convenient to pass by value, don't waste you time coding it differently. As for moving independent code out of loops... that's just an obvious thing which you might as well do for cleansliness as much as for efficiency.

      The only time you should think about efficiency at all is when dealing with I/O or with functions that your profiler tells you are taking significant CPU time (usually only a handful of inner-loop functions, if anything). By definition, anything else isn't taking significant CPU time and thus there's nothing to gain from optimizing it.

      Usually, thinking about efficiency will lead you to spend more time coding and debugging than you would otherwise. Thus, there is an advantage to ignoring it. If you spend more time writing an efficient solution than the sum of all the time it ends up saving, then the time you spent was clearly a waste.

    5. 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?
    6. Re:Counterpoint by skifreak87 · · Score: 1

      Nitpicking. In small datasets, O(n) might be faster than O(logn). For instance, insertion sorting 5 elements is often faster than shell sorting them. But w/ such small datasets the speed difference is still probably negligible. As someone who's dealt w/ a lot of other people's code. I hate optimized code in unneccessary spots. It makes it harder to understand, when char s[16] is used in 8 spots to avoid allocating extra space by having multiple variables or when weird shortcuts are taken that might save 4 instructions @ the computer level but make it take an extra few minutes to understand the algorithm.

    7. Re:Counterpoint by Temporal · · Score: 1

      Did you try UltraEdit? I just loaded up a >100MB text file and tried a search-and-replace with it... seems to work pretty well.

    8. 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.

    9. Re:Counterpoint by Anonymous Coward · · Score: 0

      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."?

      About 2 minutes ago. Damn Windows XP. Need to get back to a computer with Linux and KDE.

    10. Re:Counterpoint by anethema · · Score: 1

      I agree. I was also thinking when he was talking about using a word processor and having it be slow.

      Try using Word XP on a pentium 200mmx. See how fast that runs.

      Back then we had word 95...which seemed to do almost exactly all the same stuff. And ran about the same speed on a p200mmx as word xp does on a 2.x ghz machine today. So what exactly did they do to word xp to make it take 10 seconds to start, and run as it does on a machine with more than exponentially more processing oomph.

      --


      It's easier to fight for one's principles than to live up to them.
    11. Re:Counterpoint by Temporal · · Score: 1

      Start-up times have nothing to do with this. Starting up a program or an OS is I/O-intensive. Probably 95% or more of the time it takes is time that the CPU is sitting idle waiting for data from the hard drive. I/O is slow, yes, and if it's slow enough that it causes noticeable delays in your program, then you absolutely should look into ways that you can optimize it to make it faster. However, this has absolutely nothing to do with the original article. The original article was talking about how knowing assembly can help you write faster software. Well, knowing assembly will do nothing to make your I/O faster, since I/O means waiting for external devices which you cannot optimize yourself.

    12. Re:Counterpoint by noidentity · · Score: 1

      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.

      Nowadays the OS and other libraries provide common media services, like video and audio playback, so even processor-intensive things are mostly outside application code.

      When Apple moved from 68K to PowerPC processors, they added a 68K emulator to run old apps. Many of them run just fine because they call the OS to do most significant operations, which run in native PowerPC. I think that Microsoft had an issue where their newer PowerPC-native word processor ran slower than the older 68K version because PowerPC code is larger on average and was taxing the cache.

      It might be that in the future interpreted application code runs faster because it places less of a burden on the cache. I/O isn't keeping up with CPU speeds.

    13. Re:Counterpoint by the_greywolf · · Score: 1
      when was the last time you thought "This word processor just doesn't respond to my keypresses fast enough."

      the last time i used Lotus WordPro from the SmartSuite Millennium Edition. on a 386. running Windows 95.

      it literally took 1/4 second to respond to a single keystroke. yet i typed constantly on it. i put up with it. why?

      because Dad was using the damn Pentium.

      i still think OpenOffice doesn't respond fast enough to my keystrokes. so nyeh.

      --
      grey wolf
      LET FORTRAN DIE!
    14. Re:Counterpoint by Anonymous Coward · · Score: 0

      "Start-up times have nothing to do with this"

      BS. Efficient code tends to be smaller, less bloat. The function call with 10 parameters mentioned elsewhere in this thread takes many more instructions to execute than two paremeters (and on CISC probably runs out of registers and requires stack to store the parameters). Code size increases, memory use increases, and as a result the application size itself increases, increasing the time to load.

      My micro from years ago booted from disk in maybe 2 seconds. My 1Ghz desktop takes at least a minute. True, the OS is far more sophisticated, GUI and all, so I live with it. But tell me, office 2K on my 1Ghz box is no faster than office 95 was on my 100Mhz 486.. but is 800% larger in terms of disk space. That is progress? Efficiency?

      And one of these days someone is going to have to explain to me whats going on when I shut windows down and it says "saving unsaved data" for a minute before the hard drive light flickers for 2 seconds and then the machine shuts down... umm, what exactly *is* it doing for that minute? Obviously *not* "saving unsaved data", since my hard drive never gets accessed during that time. Funny, my BSD box says "syncing filesystems" (ie. "saving unsaved data") when I reboot it, and *it* only takes a couple seconds.

      Oh, should I mention that my old micro booted off *floppy* in that 2 seconds, my 1Ghz x86 boots off a hard drive thats got phenominally faster access times, and takes far longer.

      I could type a one page letter on my micro and save it, and it took like 10K. I type the same letter in MSWord, same bolding/italics as my original, and it takes 100K. Why is that? Efficient use of storage? Efficient programming?

    15. Re:Counterpoint by Reziac · · Score: 1

      I've heard of it, but don't think I saw a download link for it when I was looking for a large-file text editor ... it's getting harder and harder to locate real freeware among the explosion of sites that have more or less hijacked the concept and are now trying to get you to pay for downloads :(

      Does it do fuzzy S&R? so far I've not seen anything that does other than old WP5.1.

      --
      ~REZ~ #43301. Who'd fake being me anyway?
    16. Re:Counterpoint by Temporal · · Score: 1

      Not sure what "fuzzy" S&R is, but UltraEdit supports regular expression S&R, which should do anything you need. It is shareware, yes, but you can download a 30-day free trial on the web site (here). Personally, I think it's worth buying. It's a little sloppy as software goes, but it has, like, every feature you could ever want in an editor.

    17. Re:Counterpoint by Temporal · · Score: 1

      You are not going to be able to shave much off the size of your program code by using the techniques discussed in the article. Maybe 25% if you're really lucky, but it will take a lot of work to do. This won't help start-up times much, though, because most programs that start up slowly are spending the time reading config and data files, not their own executable. Even a 20MB executable only takes a second or two to load, after all.

      Anyway, most of your arguments are, again, talking about poor I/O coding. The article is talking about how knowing assembly can help you improve your code's efficiency. Knowing assembly will not help you improve I/O time.

    18. Re:Counterpoint by Reziac · · Score: 1

      Thanks for the link, I'll snag a copy to look at.

      "Fuzzy" S&R:

      The text I needed to S&R was in the form
      <aNNNNN>
      where N could be any number from 1 to 48000-something.

      In WP5.1, there is a wildcard for text strings where there is a known starting character, but the characters after that can be anything. So if I feed WP's S&R a string like
      <a*****>
      it finds any five-character string bounded by <a and >

      So all I had to do was run the same S&R five times, adding one wildcard indicator each time to lengthen out the string, and in less than a minute the job was done -- for almost 150,000 instances of this string. Imagine doing THAT by hand!

      Fuzzy S&R is an amazingly useful feature, which I've never seen anywhere else. The sort of thing that you hardly ever need, but when you DO need it, having it saves tons of time and effort!

      --
      ~REZ~ #43301. Who'd fake being me anyway?
    19. Re:Counterpoint by Temporal · · Score: 1

      Yeah, you could easily do that with regular expressions, except you could have done it in one step. Just search for "]*>", which will find strings of any length bounded by "". The "[^>]" part means "match any character other than '>'", and the "*" means "match any number of the previous item". (That's a unix-style regexp, btw. UltraEdit uses some other style by default, but you should switch it to unix style for standards' sake.)

    20. Re:Counterpoint by Temporal · · Score: 1

      Crap, slashdot thought that was HTML... Curse me for not previewing... let me try again...

      Yeah, you could easily do that with regular expressions, except you could have done it in one step. Just search for "<a[^>]*>", which will find strings of any length bounded by "<a" and ">". The "[^>]" part means "match any character other than '>'", and the "*" means "match any number of the previous item". (That's a unix-style regexp, btw. UltraEdit uses some other style by default, but you should switch it to unix style for standards' sake.)

    21. Re:Counterpoint by Reziac · · Score: 1

      Cool, saved for reference, thanks!

      --
      ~REZ~ #43301. Who'd fake being me anyway?
    22. Re:Counterpoint by Anonymous Coward · · Score: 0

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

      Using Microsoft Word earlier today.

  66. WTF by Anonymous Coward · · Score: 0

    seriously. WTF?

  67. 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.

    1. Re:Long article makes one point. by Anonymous Coward · · Score: 1, Informative
      Moderators: Please note that "twitter" is a known fanatical psycophant whose obnoxious offtopic rants are legend here on Slashdot. It doesn't matter what the topic is, he'll find a way to scrape in some pointless Microsoft bashing. While nobody expects us to love Microsoft in any way, his particularly tepid style of calling anyone he replies to "troll" or "liar" or "fanboy" because he happens to disagree with whatever they're saying is well documented and should not be rewarded. If anything, twitter is the type of person that should not be part of the open source/free software community. He is an anathema to all that is good about free software.

      I'm posting this so that you (the moderator) have some context to consider twitter and not mod him up whenever he posts his filler preformatted rants about installing Knoppix or whatever that unfortunately get him karma every single time and allow him to continue posting his trademark toxic crap (read on) day in and day out. You may consider this a troll - I consider it community service. And I ain't kidding.

      If you're a /. subscriber, I invite you to look through some of his posting history. I guarantee that you'll be hard pressed to find someone that is more "out there" than twitter. You'll also probably notice he's got quite an AC following. Don't just read his posts, make sure you go through the replies.

      To get an idea of what I'm talking about, check this post out. I mean, this is an article about email disclaimers, right? The parent of the post is complaining about the ads in the linked page and so on, and twitter actually goes off on a rant to blame it on Microsoft and recommend Lynx. WTF?

      Here's another. In this post twitter not only calls the OP a troll but attempts to "tell it like it is" while making some vague argument about "GNU". Yes, if you're confused, you're not alone. The reply (modded +4) proceeds to simply destroy his bogus argument. You will notice he did not reply. This is what some people call "drive-by advocacy". A sort of I'll just leave you with my thoughts here and move on to the next flamebait kind of deal. In fact, he almost never replies because he knows that his fanatical arguments simply do not hold up to any sort of discussion. It's not that he's chosen the wrong cause - he's just going at it in a completely wrong way.

      More? Just read though this post and the subsequent replies. I guess this stands on its own. Or this. Or this.

      More? Bad spelling in astounding conspiracy theories, more offtopic FUD and uninformed "I'm right, look at me" rants, promptly proven wrong. Worse even, twitter wants to be RMS, apparently (that first one is a winner). I mean, really. You think?

      FUD, FUD, FU

    2. Re:Long article makes one point. by TheRaven64 · · Score: 1
      Like he says, it works with any speed processor to make things faster.

      Except that this is not the case. It may be within a single processor family, perhaps within a single architecture, but once you step out of that then you will find that different operations have different costs. Optimising your code for one architecture can make it run more slowly than unoptimised code on another.

      --
      I am TheRaven on Soylent News
  68. That's not the point though.. by mindstrm · · Score: 1

    I agree totally that hand-optimized assembly is no longer necessary.

    What IS often necessary is that working in assembly on a given system teaches you a lot about how the system (including the OS, library loaders, etc) actually works.

    Understanding things like context switches, why some sycalls are slower than others, interrupts, and all that jazz are things that you pretty much can't pick up from high level coding.. you have to get down and dirty.

    To learn better programming, for sure, learn lisp, learn to code beautiful, functional, streamlined code....

    but that's all for nothing if the application uses resources in such a way that the system in question bogs down.

  69. 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."
  70. 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?
  71. 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.

  72. 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.

    1. Re:Assembly vs. scripting by Anonymous Coward · · Score: 1, Insightful

      So you're saying that a utility written by an incompetent assembly programmer was slower than the shell script? Speed isn't an inherent property of assembly?

      Shocking!

    2. Re:Assembly vs. scripting by xyote · · Score: 1
      No, but isn't this like one of those "when did you stop being a troll" questions? Oh, right. You're AC.


      But to explain it in more detail to the comceptually challenged. The algorithm was a binary search and was O(log n) and was PDQ now matter how you did it. The thing you can get from assembly programming that the article strongly hints at is an O(n) improvement in code path lenghts. But in this case the linear improvement in for such a small execution time was not enough to outweight the startup overhead of the binary on this particular system (not unix). If the startup overhead of the binary is greater than the total runtime of the script, it doesn't matter how fast the assember program would have run. We had extensive performance profiling data so we knew where the system spent most of it's exection time.


      But if you are writing some kind of calculation that has a loop of a gazillion or so, than a linear improvment might be worth going to assembler for.


      I've probably been assembler programming longer than you've been alive but I rarely use it now. Just in C inline code where there is no C language facility available to do what is needed. I used to be a kernel developer for an OS written in millions of lines of assembler code but I maintained that less than 1% of that code was actually performance sensitive enough to justify writting assembler and even there more a compiler can't do it rather than a performance issue. Most of our performance bang for the buck was gotten from algorithmic improvements, not from code tweaking.


      Thanks for this opportunity to make some additional clarifying points.

  73. Assembly and flat files by Anonymous Coward · · Score: 0
    Very true. There is a chap at Kuro5hin who wrote a very compelling piece about the superiority of a simple flat text-file database with a custom written assembler search algorithm to other more modern database approaches.

    You can check it out here

  74. No need? by achurch · · Score: 1

    I've spent the last few years trying to UNLEARN this useless habit [of writing optimized code]. There is just no need.

    Tell that to my P166/48MB server.

    1. Re:No need? by i.r.id10t · · Score: 1

      i'll see your 166/48 and lower you to a p75/24m (praise debian stable!)

      --
      Don't blame me, I voted for Kodos
    2. Re:No need? by Anonymous Coward · · Score: 0

      > i'll see your 166/48 and lower you to a p75/24m (praise debian stable!)

      I call. 486 DX/4 100.

  75. 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

    1. Re:assembly as a game by rsmith-mac · · Score: 1

      But what would you use assembly for in the IFPC contest? Our Uni participated in it, and we used Java both for our compiler and interpreter, and there was no speed problem; we could compile nearly instantaneously(although I'll admit we never tried this on a brain > 1K states), and a 100K step run of an Ant brain was only a second or so. I can't see how assembly would be helpful in case, when it would seem to be more detrimental in writing the compiler, and probably just as detrimental in writing the interpreter.

    2. Re:assembly as a game by j1m+5n0w · · Score: 1

      I meant that the ant language itself is a sort of contrived assembly (although its really at a lower level - you can't save data in the normal sense of sticking numbers in memory locations like you can in assembly). Programming directly in the ant language is similar to programming in assembly (though I suspect most teams built a compiler or preprocessor of some sort).

      -jim

  76. 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?

    1. Re:It is this kind of bullsh*t attitude by Anonymous Coward · · Score: 0

      You pretty much missed the point.

  77. 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 Anonymous Coward · · Score: 1, Insightful

      Related to your bugs point, is security. With security, you really do want to only have to do something once, and then patch that if a problem occurrs. Think java. No buffer overflows in your code, just a central entity responsible for dealing with the stuff (the interpreter).

      Doing nothing but ASM is a) going to make security practices much harder to visualize and keep track of, b) make it much harder to understand code written a few weeks ago and present opportunities for security related bugs there, and c) make tracking down bugs harder.

      I personally value more advanced security over it going fast.

      In addition to this, programming is NOT about making stuff go fast. That, to me, is a secondary concern. It may be pertinent to games, but that's about it. Instead, we now value more complex functions. We don't WANT the same old word processor to go faster, we want the word processor to be able to do more things. We only have so much programming time, have it spent on features, not speed. There are obviously concerns about bloat, and there are tradeoffs.

      Keeping these tradeoffs in mind, ASM is one extreme of the scale, and all kinds of high level scripting languages the other end of the scale. You use the right tool for the right damn job.

      On another note, the main premise of the article, I think that it is indeed a valuable skill to know and learn, and that it will help visualize advanced function.

    2. 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#.

  78. 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.

    1. Re:Crappy programmers make crappy programs by Anonymous Coward · · Score: 0

      You forgot Perl. ;-)

  79. "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.
  80. 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
    1. Re:The Art Of Computer Programming by Percy_Blakeney · · Score: 1
      I can't believe that any developer could write and code without some knowlege of ASM.

      As unbelievable as it may seem, it happens. Go figure, huh?

      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".

      Actually, Knuth sums up the requirements for his book as, "the reader should have already written and tested at least, say, four programs for at least one computer." (Preface, AoCP Vol. 1) Though some assembler skills definitely help, I don't think that a strong background in it is an absolute necessity. Plus, just to be picky, I doubt that you really know machine language.

      Any developer worth his/her salt should have at least read and understood these books, and completed at least the simple exercises.

      That's odd, because Bill Gates thinks differently: "If you think you're a really good programmer... read AoCP... you should definitely send me a resume if you can read the whole thing." (back cover of AoCP) Assembly language may be important to know, but it isn't the Alpha and Omega of programming.

    2. Re:The Art Of Computer Programming by drew+crampsie · · Score: 1
      Actually, Knuth sums up the requirements for his book as, "the reader should have already written and tested at least, say, four programs for at least one computer." (Preface, AoCP Vol. 1) Though some assembler skills definitely help, I don't think that a strong background in it is an absolute necessity. Plus, just to be picky, I doubt that you really know machine language.

      Exactly my point. "the reader should have already written and tested at least, say, four programs for at least one computer.". what knuth means is to have written those programs _for_ the computer in assembler (or machine language). He didn't say 'for at least one compiler or runtime'.

      I spent a good three months with a pencil and paper and taocp vol. 1. Learning how asm translates to the machine's language help me a lot with regards to my conceptual understanding of stored program computing

      my first computer was a commodore PET. perhaps learning on such a simple architecture tainted me, but i still think that thinking 'close to the machine' has helped. with regards to machine language, if you know binary, you know machine language. but yes, i have written programs for MIX emulators in Octal. if that doesn't qualify knowing machine language, then i concede the point

      Bill Gates thinks differently: "If you think you're a really good programmer... read AoCP... you should definitely send me a resume if you can read the whole thing." (back cover of AoCP) Assembly language may be important to know, but it isn't the Alpha and Omega of programming.

      regardless of the wisdom behind posting a billg quote here (j/k), i fully agree with him on that issue. before reading AoCP, i thought i was good. now i know that i'm better then average, but by no means a genius. The chapter on memory allocation (best vs first fit) opened my eyes to an entire level of programming i never even thought existed.

      Rather then rehash the articles reasons why assembly is important, i'd just like to note that all programs eventually parse down to machine langauge. it may not be the Omega, but it sure is the Alpha. A computer doth not grok anything but it's machine language. ASM is a level above that, but close enough that one can see what the machine is doing.

      Drew Crampsie -- sending my resume to microsoft as we speak.
      --
      Drew Crampsie - Software Developer
      Open Source Business : The Tec
    3. Re:The Art Of Computer Programming by Percy_Blakeney · · Score: 1
      I spent a good three months with a pencil and paper and taocp vol. 1.

      I'm surprised it only took you that long. I figure that it is taking Knuth his entire life to write the series, so I should at least do him the honor of taking the same amount of time reading it. =)

      with regards to machine language, if you know binary, you know machine language.

      Well, no, not really. That's like saying that knowing the Greek letters means you can speak Greek.

      but yes, i have written programs for MIX emulators in Octal.

      Then I would say that, yes, you probably do know a machine language.

      ASM is a level above that, but close enough that one can see what the machine is doing.

      That's mostly true, but not as much as it used to be. On x86, the most prevalent PC architecture, you see a lot of instructions that do not reflect the true situation, due to its decidedly non-RISC approach -- in fact, you could consider x86 to be a more-or-less low-level language with some high-level concepts thrown in for convenience. Plus, the processor doesn't even directly execute the instructions any more: they are first translated to microcode instructions, which are then executed.

      Assembly is only half of the picture anymore, too. When writing a low-level piece of code, there are a hundred more things to worry about than there used to be, due to the increased complexity of the processor: L1 & L2 caches, pipelining and superscalar CPUs, branch prediction, virtual memory... it all makes it very hard to really, truly understand what is going on. I agree that knowing assembly language is beneficial, but I don't think that it gives as large of a boost as it used to; a computer architecture class is almost more useful/necessary.

      Drew Crampsie -- sending my resume to microsoft as we speak.

      Speaking of something that isn't wise to say on Slashdot... ;)

    4. Re:The Art Of Computer Programming by drew+crampsie · · Score: 1

      I spent a good three months with a pencil and paper and taocp vol. 1.

      I'm surprised it only took you that long. I figure that it is taking Knuth his entire life to write the series, so I should at least do him the honor of taking the same amount of time reading it. =)

      lol, perhaps i phrased that wrong. that three months was simply to wrap my head around MIX and how it operates. i'll never be done with tAoCP!

      I agree that knowing assembly language is beneficial, but I don't think that it gives as large of a boost as it used to; a computer architecture class is almost more useful/necessary.

      Perhaps that's where my personal bias shows up. Assembly programming _was_ my class in computer architecture. Perhaps this is the point i was trying to get across. I have to agree the it may not have practical uses anymore, but it's like ESR said about lisp "LISP is worth learning for a different reason -- the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot.

      --
      Drew Crampsie - Software Developer
      Open Source Business : The Tec
  81. 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 yeremein · · Score: 1
      I had an interesting experience regarding a bug in Visual C++ 6.0. I was working with this GPL'd TI 99/4A emulator, trying to figure out why it acted strangely when compiled with optimizations turned on. The author figured out which function was returning the wrong answer, so I had VC++ dump out an assembly listing and I looked it over.

      This particular function compared two numbers and set the flags in the ALU; one flag would be if the first is less than the second using an unsigned comparison, and another if the first is less than the second using a signed comparison. I found that VC++ incorrectly optimized away the second comparison. I came up with an ugly hack that would force the compiler to re-compare, but without knowledge of assembly language, I would have been stuck.

      The experience was a wake-up call for me; ever since then, I've been a little too quick to blame the compiler when something doesn't work. But this is only one of several Visual C++ bugs I've discovered--none of which have been fixed, by the way, even though they've been known about for years.

    2. 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.

    3. Re:Because you can't always trust compilers by Animats · · Score: 1

      This is a very real issue for numeric work. People who do engineering simulation applications often run compiler validation test suites, to make sure the different versions of compilers get the same answer. It's not at all uncommon to find bugs in compiler optimizations that way.

  82. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  83. 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.

    1. Re:Absolutely by vidnet · · Score: 1
      My preference is C, binary file formats, networking protocols, crafting elegant solutions for multiplexing IO.

      Be careful. Binary file formats are great for performance and compactness, but for extensions and conversions, a company can suffer greatly.

      Reserving 16 bits for some serialnumber might seem sufficient for the estimated five year life span, but then after 20 years of business you run out. Maybe you could convert the file into some other format? Oh wait, what does that fourth bit field that byte your C code calls 'CXXT7' signify again?

      Do you think ahead? Do you include ways of extension later? Do you document your formats so well that any idiot who has no experience with the system can write a clone of it? Even the little hacks that you include later? Do you make sure each company gets an updated, hard copy of this documentation, and explain to them that they should keep it archived so they can show it to a new generation of programmers long after you've retired?

      Terminal emulators for interfacing ancient systems isn't really rare as I'm sure you've encountered. I blame you if we in the future run Bochs with Windows with KidSockWare2k-clients.

  84. 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.

    2. Re:Schools not teaching assembly...Really? by Chouhada · · Score: 1

      I agree, I had the same experience (May '03 grad as well). My school also had classes on ASIC, SoC, Parallel Programming, Real-Time & Embedded, DSP, etc.

      Although my university had Comp. Eng. under the Elec. Eng. department, I noticed while doing some browsing that some colleges have the Comp Eng. curriculum as part of the Comp. Sci. department.
      I may be wrong but it seems like this is bound to cause problems in the future.

      I wonder if that is part of the reason I was constantly asked about the difference between Comp. Sci. and Comp. Eng. at job fairs. It didn't suprise me that much when I fielded the question from HR folks but I didn't expect it from mid-level management who were trained as engineers.

      --
      -- "Do you even know your daughter? There's no way she likes that song. Oop, is she in a coma?"
  85. I think it's better as an aid/filter... by Trillan · · Score: 1

    I wouldn't dream of programming an application today in assembly language.

    Yet at the same time, someone who has been exposed to assembly but can not code in it... well, they probably can't really code in any language.

    Being language agnostic is important. Sure, you can prefer to code in this language or that, but if you can't sit down at a new language and learn the basics in a few days you're not that talented, really.

    I see a meta-assembly being useful today; a simplified instruction set with emulator that needs to be coded using a very simple set (say, less than 16) instructions. This would be a great way to cut your teeth and learn how a computer "works." Does it matter that a modern computer has caches, instruction re-ordering and so forth? No. The basics are the idea of registers for working variables, and memory storage as mid-term storage, mathematic operations, and branching.

    I don't see learning a particular processor's assembly instructions as terribly useful. My 6809 knowledge is pretty low, and my 680x0 knowledge is even lower. About the only thing I know about x86 is that the byte order is hard to read. :) But I think I'm well served by the concepts I learned. And I think anyone who has programmed a virtual computer with an instruction set of 16 instructions is less likely to be unable to jump from, say, C to Pascal to Perl.

    Certainly, the ability to optimize a bottleneck for speed is nice, but I think that's less important than the grasp of the basics.

    To summarize that (I guess I went on too long), I see the ability to code in assembly as more important in learning to program (and evaluating someone's abilities) than in making or even optimizing working, non-trivial desktop applications.

    I've seen some pretty dumbass code in my day. And it probably would have been easier to spot the guy's lack of talent in a few hours at an assembly level than a month later in a high-level language.

  86. Yes it is. by Anonymous Coward · · Score: 0

    Assembly is still good. It taught me code optimization. If oyu learn assembly you learn to program using as little resources as possible. I think many of today's programs and games could run faster yet if sloppy code would be fixed up.

    1. Re:Yes it is. by TheRaven64 · · Score: 1
      If oyu learn assembly you learn to program using as little resources as possible.

      One syntactic and one semantic error in a short English sentence. Remind me not to use any code you write.

      --
      I am TheRaven on Soylent News
  87. 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().

    1. Re:Function calls and data buffering by julesh · · Score: 1

      the naive Windows SetPixel() command is slow compared to CreateDIBSection().

      Windows functions can behave slow in weird conditions. I was writing a program last week that generated an image in memory one scanline at a time and then stored it into a bitmap using SetDIBitsToDevice(). Let me tell you, that function is horrible, and badly documented. Because I didn't understand (and still don't) the meaning of one of the parameters, I was passing the y position of the scanline I wanted to store to it, rather than zero, resulting in the function taking about 50x as long as it should have done to execute. :(

  88. 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.

  89. Apples and oranges .... by taniwha · · Score: 1
    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.

    well so? - that proves nothing. To make any sort of usefull point you have to compare the same things.

    In reality carefully hand crafted assembly will usually beat compiler built code (not always there's always that superoptimised goodie you never thought of) .... but it's seldom worth doing the hard work ... the real trick is to have done enough of both to be able to decide when it's worth your time to tune something (and what to tune)

    1. Re:Apples and oranges .... by nacturation · · Score: 1

      well so? - that proves nothing. To make any sort of usefull point you have to compare the same things.

      Learn to read between the lines a little bit here. Sure, let's compare the exact same things. Writing the exact same algorithm will, as I said before, take less time, be less error prone, and have less security risks although the code may not be as tight as a perfect assembly writer. We're discussing efficiency here and I gave different algorithms as an example to prove a point which perhaps you missed. Why optimize everything in assembly when a better optimization is often found by using a better algorithm?

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
  90. BFD by Brandybuck · · Score: 1

    an efficient algorithm coded in an inefficient way will always beat out an inefficient algorithm coded by hand in 100% optimized assembly.

    Big fat hairy deal. An efficient Schwinn bicycle could outrace an inefficient Harley-Davidson motorcycle, given sufficient levels of efficiency, so what's your point?

    The fact remains that an efficient algorithm coded in 100% assembly will still beat the same efficient algorithm coded in Javascript.

    --
    Don't blame me, I didn't vote for either of them!
    1. Re:BFD by antoy · · Score: 1

      The fact remains that an efficient algorithm coded in 100% assembly will still beat the same efficient algorithm coded in Javascript.

      I think he's saying that having a good understanding/knowledge of algorithms is more important perfomance-wise than knowing how to optimize your code. He's not saying that assembly optimization is unimportant or nonexistent. I agree with him.

  91. This is like saying penmanship matters by Anonymous Coward · · Score: 0

    The author of the article is obviously biased, and completely wrong. Laboring to improve execution time by a (small) constant is the epitome of inefficiency -- more important is chooosing the correct algorithm and data structures. Nowadays, this often means using hashtables everywhere. Try doing this in assembly, supporting arbitrary data types -- I'd rather let the compiler do all the work.

    1. Re:This is like saying penmanship matters by andy314159pi · · Score: 1

      Compilers choke on really complex code all of the time.

  92. assembly still doesn't seem like the best choice by Trepidity · · Score: 1

    I agree some "under-the-hood" knowledge is often helpful, but assembly is only really useful for that sort of knowledge in limited areas, primarily low-level stuff. 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? is list concatenation faster from the front or back? etc.). Knowing assembly will do much less for your LISP code, for example, than knowing how your LISP compiler is implemented will.

  93. Merci by Anonymous Coward · · Score: 0

    ...

  94. 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.

  95. C'MON, it is not a troll !!! ;_) by PaulBu · · Score: 1

    Where are my mod points when I need 'em... It is actually FUNNY (+1)

    Paul B.

    1. Re:C'MON, it is not a troll !!! ;_) by Reziac · · Score: 1

      Crap, it was more than funny (it made me spit on my monitor!) -- it was bloody insightful. If kiddies these days knew ASM, it wouldn't take half an hour to download the day's trojan-bearing spam.

      I'm not a coder, but I've read chunks of Abrash's Zen of ASM, and some of the concepts were enlightening even to a mere interested bystander.
      And I've noticed a sad trend in the function to weight ratio (aka "bloat" :) in the apps of the past few years, which I suspect is partly due to more code coming from young programmers who know how to write programs all right, but don't really understand the machine under their code, or don't *care* in the way one had to back in the days when every byte was precious. Why clean up memory if WinNT can do it for you; why optimize when everyone has a 3GHz machine; etc, etc.

      --
      ~REZ~ #43301. Who'd fake being me anyway?
  96. Missing the point by neirboj · · Score: 1

    Sorry if I seem snarky but I feel that many of my fellow posters are missing the point of this discussion. At issue is not necessarily the question of exactly which things should be written in assembly code (or not) but rather that the experience of learning to program in assembly is a valuable one. I noticed an improvement in the overall quality of my code during and after taking the assembly programming class that is still required for computer science as well as electrical and computer engineering majors at CU Boulder (I am one of the latter).

    The debate about whether assembly code really provides an appreciable gain in performance in certain areas, or if the gains realized through assembly programming are worth the costs in time and flexibility, is an important and necessary debate. It is not the most useful discussion that could take place at this time however.

  97. Years of Effort for a Second by Bob+Munck · · Score: 1
    I once estimated that I had written 250,000 lines of assembly code for the IBM/360 mainframe, and that if all of those instructions could be executed just once, it would take about a second to run all of them on a System 360 mod 50. On today's machines, probably a few hundred microseconds. Doesn't seem like much of a result for several years of my life. (Ah, but quite a few of those LoC were something called Hypertext.)
    Rules for Optimization:
    #1. Don't do it.
    #2. (Experts only) Don't do it yet.
    1. Re:Years of Effort for a Second by Anonymous Coward · · Score: 0

      And how many hours would one of the nasty interpreted languages have taken to execute?

    2. Re:Years of Effort for a Second by Bob+Munck · · Score: 1
      In fact, one of the programs that constituted those 250K LoC was an interpreter for a language named BRUIN -- BRown University INterpreter -- that was used fairly extensively by institutions running CP-67/CMS on a 360 mod 67. It took about a hundred instructions to interpret a line of the source code, so the answer is about 2 minutes on the old mainframe or 20 ms on a modern micro. Of course, as I said the interpreter was written in assembler; that probably isn't true of PERL.

      As an old microcoder, my basic inclination is to think of machine instructions as interpreted. That's even true of RISC machines, though less so. You haven't lived until you've fixed a bug by weaving a wire through a row of tiny transformers to change the microcode.

  98. 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.
    1. Re:NIU does. by Methuseus · · Score: 1

      Holy shit, you went there too? Did you have Rannie? I understand he failed like 50% of the students he had. He didn't even teach, or help when I asked him, and he told the TA not to either. That is one of the many many reasons I hate that school.

      --
      Two things are infinite: the universe and human stupidity, though I'm not yet sure about the universe. - A Einstein
    2. Re:NIU does. by gillbates · · Score: 1

      I never liked the way they had such an adversarial attitude toward the students.

      I managed to avoid having Dr Rannie for assembler. However, he did sub for one day in my operating systems class. It was then that I understood why so many people spoke poorly of him.

      He's talking about the mainframe equivalent of interrupt vectors, and using some assembly code to demonstrate how the registers are saved, etc.... I'm looking at this code and thinking, "That won't work!". So I raised my hand and asked him, "Your last instruction saved all the registers, three of which you've already overwritten?" His eyes lit up - he deliberately made a mistake to see if anyone would catch it. I got it. I got the feeling that the rest of the class didn't - they could have cared less about assembler. And that was what I think Dr Rannie hated the most. I think he was passionate about assembler; I think he was tired of dealing with ignorant students who "just wanted to pass the class..." Though I didn't have him for assembler, I get the feeling that he would not have given me much trouble, because I actually chose NIU because it taught assembler.

      And 50% is a routine failure rate for that course, regardless of who teaches it.

      --
      The society for a thought-free internet welcomes you.
    3. Re:NIU does. by Tony-A · · Score: 1

      .... I'm looking at this code and thinking, "That won't work!". ... His eyes lit up

      One student catches it ... and his eyes light up.
      That says something about the normal state of things. I don't know what, but it ain't good.

      "Your last instruction saved all the registers, three of which you've already overwritten?"
      In assembler the error is hard and immediate. In a "higher" level language the effect is more sublte and possibly delayed, harder to find, but just as serious. That error should be screaming even if you've never seen the particular assembler op codes before.

  99. 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!
  100. Re:because.... by Jacked · · Score: 0

    Dude, get the fuck outta my head. No, seriously, I'm kreepin' me out. Get outta there.

  101. Well of course! by Anonymous Coward · · Score: 0
    How else would you save the current environment and stack pointers?

    _savu:
    bis $340,PS
    mov (sp)+,r1
    mov (sp),r0
    mov sp,(r0)+
    mov r5,(r0)+
    bic $340,PS
    jmp (r1)
  102. take a class in compilers by Anonymous Coward · · Score: 0

    This whole "no one's teachin assembly like they did in the good ol' days when men programmed in assembly and panzies toyed with compilers" is overblown. Assembly programming in the university setting has been losing ground, but only in the way of dedicated assembly classes. Students in a good program will undoubtedly encounter assembly during their education as there is still no way to teach a topic like computer architeure or compilers without covering assembly. If a person could do anything to increase his/her coding effiency it is take a few compilers classes. The optimization algorithms in these classes are the basis for essentially all the smart coding tricks you can find as optmization was the main focus of compilers research up until late. For example, the generalized code motions alone cover a number of the these smart tricks. Moreover, learning these algorithms let's you quit wasting time hacking away at some of the optimizations, like some tail-recursions, that your compiler may already be able to do.

  103. A good entry-level hardware lesson by motorsabbath · · Score: 1

    A non-hardware type can learn alot about how their hardware works by programming a few short assembly language programs. Jumps, registers, memory layout, etc.. Great exercise.

    --
    The heat from below can burn your eyes out
  104. Use it where it fits. by Anonymous Coward · · Score: 0

    If you want to do ASM use it where it fits. Not programming an x86 box with a Gig of RAM and a hard disk. No, work with 8 bit micros with tiny amounts of RAM and ROM. On these guys with 4K ROM and 256 bytes of RAM using ASM is fun and it fits. Also both the architecture and instruction set fit in your head so you can and do truly think like the computer. There you see the purpose of special instructions like bit test or bit set and appreciate using the right branch instruction to save a byte. Also you get to see directly the consequences of the chip architecture. I remember going from a 6800 to a 68HC11 and being amazed what I could now do since I had two index registers.

    Also working with ASM gives the programmer a great appreciation of code and data structures. It still amazes me how many programmers can not see the connection between ASCII 'A' and 0x41, or that 0-9 in ASCII is just 0-9 + 0x30.

    Finally, optimization, small machines force it on you. Fill ROM but need more code, go back and optimize to get the space, rinse repeat... I found that you could usually get 15% on the first pass, maybe 5% on the second, then it became a matter of bytes after that.

    Ah, the good old days.....

  105. Assembly by AlgUSF · · Score: 1

    Why learn assembly?

    Because most people don't understand that a computer is a COMPUTING MACHINE. Many coders don't understand how a computer actually works.

    --


    I want my rights back. I was actually using them when our government stole them after 9/11.
  106. Several books... by Lodragandraoidh · · Score: 1

    Several books I have sitting on the shelf over my monitors - that I occaisionally peek into:

    Sparc Architecture, Assembly Language Programming & C - Paul - Prentice Hall

    Using Assembly Language 2nd Edition - Wyatt - QUE programming series

    Turbo Assembler 3.0 - User Guide - Borland

    Mastering Turbo Assembler - Swan - Hayden Books

    Peter Norton's Assembly Language Book for the IBM PC - Revised and Expanded - Norton & Socha - Prentice Hall

    Ahhh - reminds me of the good old days! Back when Real Programmers roamed the Earth...

    --

    Lodragan Draoidh
    The more you explain it, the more I don't understand it. - Mark Twain
    1. Re:Several books... by andy314159pi · · Score: 1

      This links says that fortran is a forgotten language.

      I don't think thats right.

      I use fortran and I like it alot. I also like potato salad and cold soda.

    2. Re:Several books... by Lodragandraoidh · · Score: 1

      I learned Fortran back in 1980. Back then it was seen as a general purpose language with a strong mathematical underpinning. However, today it is seen as useful mainly in scientific applications where it can leverage its number crunching abilities.

      Whether you use it as your general purpose language, or not, the fact is it has been eclipsed by other languages in popular use (C/C++, Java, Perl, Python). Fortran wouldn't be my first choice for many tasks that some of the newer languages make easy, systems programming, text manipulation, GUI integration, etc.

      While I disagree that it is a 'dead' language - I think you will agree with me that the number of people who are conversant in it are few and far between outside of Universities and research labs.

      --

      Lodragan Draoidh
      The more you explain it, the more I don't understand it. - Mark Twain
  107. *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.

    1. Re:*A* big ass computer??? by aflat362 · · Score: 1
      I was speaking from the perspective of an in-house corporate systems programmer. My company doesn't want me sitting on my ass for weeks being anal about a bit saved here and there, when instead I could turn it out quickly and start saving the company some real money in processing costs. The cost of a server is negligible when compared to the benefit of saving cents or dollars per transaction when millions of transactions per month are involved.

      last week I requested $28,000 worth of server hardware for a new application and hardly an eyebrow was raised.

      --

      Conserve Oil, Recycle, Boycott Walmart

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

    I write my code right the first time. :)

  109. 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.
  110. Assembly or Assembler ?? by Anonymous Coward · · Score: 0

    (Almost OT)
    Maybe someone can point out to me ignorant, why - when I learned Assembler on PDP11 25 years back, it was Assembler and today it is Assembly instead of Assembler ?

    Thanks !

    1. Re:Assembly or Assembler ?? by Anonymous Coward · · Score: 0

      I still see it being called both...
      Here's what I say: Assembly, the language; Assembler, the program you run your code through.

    2. 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
  111. 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.

  112. 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.
  113. Re:because.... by n4KdR4zr · · Score: 0

    No YOU get out of OUR head, it's crowded enough already in here. Don't make us get violent. Because that would be painful. And I know how we love pain. And assembly. And naked chicks with large breasts. And star trek. And periods.

    --
    "... drowning in information, ... starving for knowledge." --John Naisbitt
  114. excellent argument, man! by PaulBu · · Score: 1

    The As I've said before, a good mechanic can tear down and reassemble an internal combustion engine, and that my argument is that a good programmer can do the same on an ASM level should the need arise.!

    but, OTOH, you do have a 4-digit /. uid, after all... ;-)

  115. 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!

  116. 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.

  117. Embedded development? ;-) Hmmm... by PaulBu · · Score: 1

    Mastery of assembly is completely pointless for anyone outside of OS kernel, compiler construcution and embedded development...which probably means you.

    And why do you think that in a year or two the Si wafer real estate (or, more realistically FPGA real estate, which it is probably right now) will NOT become cheap enough that one who thinks of himself as a 'programmer' now would have to actually write VHDL for the processor part, then assembly glue, and only then port Linux to the "ultra-optimized to track your eye movements while simultaneously scanning your brain waves for the tune you'd like to listen to now" car-dashboard computer?

    The line between hardware and software is disappearing, and producing way too many "programmers" who can only code Java is a sure way to the next economic disaster in this country (way worse than .com collapse).

    Are you sure it is not happening?

    Paul B.

    1. Re:Embedded development? ;-) Hmmm... by Ars-Fartsica · · Score: 1
      And why do you think that in a year or two the Si wafer real estate (or, more realistically FPGA real estate, which it is probably right now) will NOT become cheap enough that one who thinks of himself as a 'programmer' now would have to actually write VHDL for the processor part,

      Maybe because you have been able to do this for a decade and no one does??

      Systollic array research has been happening since the 70s. See any in use by application programmers? In fact the opposite is happening, custom functionality is being virtualized. See: VirtualPC, VMWare, Winmodems.

    2. Re:Embedded development? ;-) Hmmm... by PaulBu · · Score: 1

      Maybe because in the past decade people (ones with $$, as in "VCs" ;-) ) were interested more in running data around those, you know, strings which they called "Internet"? ;-) And now they have to run data in that thing which the old guy Maxwell discussed, you know, the "Waves"? And the latter one takes some extra effort in doing DSP? ;-)

      On a more serious note, businesses want to differentiate themselves from each other (who needs another plain old stand-alone 2 megapixel camera if one can have a 5 MP one in their cellphone?), and plain Si is actually becoming cheaper (if you do not think about the top-of-the-line, 90nm one, of course, you do not need anything like that for your better-than-average consumer appliance).

      And, of course, classic systolic arrays research has almost nothing to do with modern FPGAs, we will not see it re-emerging until speed-of-light signal propagation delays on chip become dominant (I have something to say about that too, but will not now...).

      Paul B.

  118. 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.

  119. Recommended books? by Anonymous Coward · · Score: 0

    Can anyone recommend some good Assembly books? x86 please. The Art Of Assembly seems too high-level.

  120. Love self-promotion @ $41.96 a pop by niteware · · Score: 1

    Its not that I do not agree with Randall's comments, as I started out writing assy on 4 bit cpus (don't laugh, 20 years later they still make millions of them a year), but the 'article' is nothing but a sell pitch for his book. Hopefully OnLamp.com charged him to 'post' that 'article'.

  121. Re:This guy clearly doesn't work in the real world by Anonymous Coward · · Score: 0

    Well, the real world I work in, OS development, I write or read assembly every day.

  122. 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 the+quick+brown+fox · · Score: 1
      Good post!

      I would like to take it a little further, and point out that you can't even always know what is costly for your language--you can only know what's costly for the specific VM's you're using.

      Over the years, many operations that were extremely slow in Java have become very fast, and (to a lesser extent) vice versa. The HotSpot JIT compiler and generational garbage collection, for two examples, turned the rules upside down from one version of the JVM to the next. In some versions of JRE 1.4, reusing StringBuffers is incredibly expensive, for other versions it's cheaper than creating new ones. Entering a synchronized block was once expensive, even without contention, and now is cheap. It used to improve performance to mark your methods "final", now it supposedly makes no difference at all. The examples go on and on.

      Then there are differences between operating systems, or even different versions of operating systems--isn't Linux's new threads implementation like a thousand times faster than the old one?

      I agree with your mantra "write simple code and optimize when needed", but would also like to add some wise person's first rule of optimization: "Forget everything you know."

    2. Re:To some extent you are missing the point by TheRaven64 · · Score: 1
      I have never really bothered to learn a real assembly language (I almost got around to learning PPC assembly to play with AltiVec, until I found that Apple provide a C library that has a 1:1 correspondence with the assembly instructions and is a lot clearer to read). My undergraduate course contained a few modules which used some form of simplified RISC assembly to illustrate some points, and on of our algorithms modules used unlimited register machines as an example of a universal model of computation (and writing programs on a machine with only three instructions is almost as much `fun' as writing them for a Turing Machine).

      In my second year, we were expected to write an optimising compiler for a simple language that ran on a simple 5-register virtual machine. That was a lot of fun, and taught a lot.

      The serious problem with programmers who think in assembly is that they almost never think in assembly for every platform where their code will run. The difference in architecture between a G4 and a G5 are so great that optimisation for one will often harm the other if not thought out correctly. Optimisation for either is likely to make the code run slowly if run on an x86, unless you get into multiple execution paths (which are just messy, and I try to avoid for anything other than vector operations).

      --
      I am TheRaven on Soylent News
    3. 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!!!
  123. That was covered in the article. by khasim · · Score: 1

    If I may quote him:

    "Unfortunately, when software performance is less than optimal, these programmers generally don't know how to correct the problems with their software. They'll often spout things like "The 90-10 rule," or "I'll just use a profiler to correct the performance problems," but the truth is they don't really know how to improve the performance of their underperforming applications. 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."

    That's where he covers profilers.

    "Most of the time you can achieve very good performance boosts by simply improving the implementation of an existing algorithm. A computer scientist may argue that a constant improvement in performance isn't as good as, 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. And it is exactly this type of optimization with which most modern programmers have little experience."

    That's where he claims that his concept is better.

  124. 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.

  125. Learning assembler twice and bytecode once by ya_steve · · Score: 1

    In my undergraduate computer science course, I managed to learn assembler twice and bytecode once: Assembler for a simple simulated processor (1988) This was the first module in one of the two first-year courses. Pascal was the first module in the other first-year course. 68000 assembler (1989) "Eventually, all languages are reduced to assembler. And sometimes you will use it for speed." EM, an intermediate language - the bytecode (1989) Part of a compiler course. I haven't worked on compilers, but it was incredibly useful when Java came along. I'd recommend this to anyone studying computer science, or anyone designing the course programme.

  126. 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.

  127. I thought that was a given by DigitalCrackPipe · · Score: 1

    I thought it was understood that knowing a little assembly makes you a better programmer. Not that I know as much as I should, but it's been useful.

    On the other hand, it's important to distinguish between software engineers and code monkeys. Cobbling a bunch of keywords together that can compile (heh, if your language even compiles) does not constitute crafting software. A lot of people who think of themselves as programmers are much closer to "power users" than programmers. Not to bash those folks, but the industry should understand that difference well enough as to not try to write realtime life-critical code in visual basic ;) You shouldn't use the "engineering" tagline on things that don't actually use the principles of engineering.

  128. Often the Right Way is almost fastest... by r6144 · · Score: 1
    Today quite a lot of code is still written in C or C++-like C, especially for software running by an ordinary user on a PC. Compiling such mostly low-level languages is not very difficult, and if you do things in the cleanest way (don't pass huge structs as function arguments, use g_strdup_printf() or snprintf() or memcpy() instead of slow and unsafe strcat(), have clear distinction between integer and floating-point variables to avoid unnecessary conversion, use unsigned types when it is a good idea, etc.), the compiler knows exactly what the machine should do, and produces reasonably fast code. Of course it may be a bit slower than carefully hand-optimized assembly, but the difference is very CPU-dependent and also not usually high given current compiler technologies.

    In short, in C you should be able to produce good and clean code that tells the compiler how the machine should perform the job, rather than saying only the "what" part (which is hard to express well, precluding many optimizations) vaguely and rely on the compiler (which does routine jobs such as register allocation well, but is not that clever) to figure out your exact purpose.

    High level languages (such as Lisp/Haskell) are currently different. Since they are so high-level, and the compiler isn't clever enough for it (so that it can optimize away some type-checking, lazy evaluation and do some function inline which is essential for acceptable performance sometimes), you often have to write code in a not-so-beautiful way if the speed matters a little. That's my pet peeve against such languages which makes me reluctant to use them if the resulting code is going to take more than a few seconds of CPU-time, although I love them dearly otherwise.

  129. 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.

  130. 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 Fizzl · · Score: 0

      JIT is a fuckinng fad.
      Don't you people understand that the overhead of JIT always outweights the advantages. The fucking JIT compiler has to be on look ALWAYS for any code it could optimize. However, very rarely it can actually find anything that makes a difference.
      Just drop it please. Now.

      Learn some assembler. Learn some programming.
      You will eventually understand what an idiot you have been.
      I don't even understand how theoretically smart people can even vouch for scripting languages such as php, perl or java for any performance critical applications.

      Check out how lex and yacc work. Create your application with those and compare it to your god damn JIT'ed java application. Guess once which on wins.

    2. 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.

    3. Re:JIT? by ryepup · · Score: 1

      I don't even understand how theoretically smart people can even vouch for scripting languages such as php, perl or java for any performance critical applications.

      How do you define a performance critical application? Are web sites performance critical, or are they going to be waiting on resources for so long that it doesn't matter? And I think the definition of a performance-critical app changes as the hardware improve. Doom was performance-critical when it came out, and could never have been written in something interpreted because there wasn't the speed to support it. Today's machines can run something like doom without any difficulty.

      The article argues that we shouldn't allow ourselves to rationalize writing inefficient code based on the speed of the hardware, but we all have to eat, and that means asking the old question: Which is more expensive? Programmer time or CPU time?

      In something like a RDBMS, I'd say CPU time, because no one will use it if its slow as ass. For something like a web or desktop business app, its still programmer time.

    4. Re:JIT? by Anonymous Coward · · Score: 0

      HP sucks and so does everything they come up with, including this.

      Philips is a lot better.

      -- You know who I am ;)

  131. 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 ztwilight · · Score: 1
      ...or a painter who has made his own paint, or a musician who crafted his own instrument

      Sorry, but there aren't any musicians or painters anymore who do this. Bad example!

      --
      Who moved my sig?
    2. Re:Duh. by gsasha · · Score: 1

      BS!
      Imagine a mechanic that has no idea on how an engine works, or a painter who has no idea in color theory, or a musician that only knows the note and never played anything by himself... you get the idea.
      Well, that mechanic will probably know how to change oil, the painter will be able to produce some abstract art, and the musician will do some trance compositions by C&P. But nothing genuinely novel and good will come out of it.

    3. Re:Duh. by Hideyoshi · · Score: 1

      Yes, because the likes of Glenn Gould, Yo Yo Ma and Franz Liszt were to be found crafting their own instruments, right? This is a silly argument, and I don't understand how anyone could have found it "insightful".

    4. 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.

    5. Re:Duh. by deadlinegrunt · · Score: 1

      There seems to be a big hole in your analogy.

      Hence the saying, "Proof by analogy is fraud"

      --
      BSD is designed. Linux is grown. C++ libs
    6. Re:Duh. by kraut · · Score: 1

      Imagine a world where all engines are built from scratch... most of us wouldn't be able to afford cars.

      That said, intimate knowlege of your medium is useful in many ways, but I don't think the analogy works for painters or musicians. I can't see how you'd become a better violinist by practising woodwork for ten years instead of the violin and music ;)

      --
      no taxation without representation!
    7. Re:Duh. by humankind · · Score: 1

      Definitely not true of musicians who think in radically different terms from insturment builders.

      Speaking as a musician, who has built his own instruments and played in front of crowds as large as 50,000 people, I respectfully disagree.

    8. Re:Duh. by humankind · · Score: 1

      Imagine a world where all engines are built from scratch...

      Those would be some great engines... much better than what we have now.

      Imagine a world where children are built from scratch.

    9. Re:Duh. by kirkjobsluder · · Score: 1

      But is this generally true? Growing up near a world-class music school, I've never heard musicians talk about music in terms of Herz, refraction, interference or resonance. (With the exception of the frequency associated with a standard European scale.) And I've not heard anyone worth listening to claim that the non-trivial task of learning to build a violin worth playing provides any deeper insight into musical performance than practice.

  132. laziness by cheese_wallet · · Score: 1, Interesting

    I think coders are more efficient in assembly because they don't want to have to write 54 lines of code to do something when if they consider the problem they are solving, they could write it in 10 lines.

    1. Re:laziness by andy314159pi · · Score: 1

      I think coders are more efficient in assembly because they don't want to have to write 54 lines of code to do something when if they consider the problem they are solving, they could write it in 10 lines.

      Isn't that because assembly doesn't have new lines?

  133. Pointless in some reguards, but useful in others by xenocide2 · · Score: 1

    Yes, if you're programming for popular UNIX or PC platforms, ASM really can't gain you much. Many free compilers already come with a strong set of optimization rules that can pretty much match handwritten code. And really, you have to go out of your way to write horrible code that translates poorly. I mean, compilers these days are pretty good about caching expression evaluatoins and inlining function calls. Where assembly language really counts is those instruction extensions. Especially with older compilers that maybe you haven't bought the new version of (why you're paying for one, got me). Fortunately, most people who need instruction set optimized code often turn to libraries written with that specific purpose in mind. There's a couple MD5 libraries for sale that have mmx, sse, or sse2 optimizations, for example. So learning ASM probably won't help you write faster code for your desktop, nessecarily.

    On the other hand, a large quantity of high paying software engineering jobs don't use the UNIX or PC platforms. PowerPC's often have specialized hardware that you want to access, as do several other kinds of boards and microcontrollers. Furthermore, you might not even have a C compiler target available. And even if you do, it's almost certainly not as dependable as gcc. In this arena, knowing how to write and read assembly code is vital. Hell, when I wrote the code for my selective weed sprayer, it read pretty much like ASM would. Set a few register values, read some other ones, then reset a timer to do it again later. And when it doesn't work, its often helpful to check the ASM output to see if perhaps something's going wrong either in your mind or the compiler's mind =).

    --
    I Browse at +4 Flamebait

    Open Source Sysadmin

  134. In the UCK language. by LightningBolt! · · Score: 1

    In the UCK language, you can have filenames like d.uck

    Well, you could if there were such a language.

    --
    Old people fall. Young people spring. Rich people summer and winter.
  135. 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 ...
  136. 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 Tony-A · · Score: 1

      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.

      Well put. Efficient systems are more the result of the absense of inefficiencies than the presence of efficiencies.

    2. 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
    3. Re:I agree... and disagree... by Otto · · Score: 1

      you spent all that time optimizing

      If writing "decently optimized" code takes you any extra time at all , then you have other issues.

      I'm not saying to go and make everything run as fast as freakin' possible. I'm saying to not be stupid and write code that is easy to read and understand but is also just plain slow as hell. You *can* write both readable and "fast enough" code in one pass. Any good programmer does it on a regular basis.

      if that bottleneck was clearly written it will likely be much easier to refactor/optimize

      If you have to come back to code a year down the road to optimize it because it's more performance critical than you thought, you already fucked up. This stuff should be visible in the design phase, if you're doing any forward thinking at all. You should always ask yourself "how will this scale?" when writing anything that has the possibility of getting larger down the road, that's all I'm saying here.

      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.

      Where did I say that was a good idea anyway? I'm *NOT* saying to make every program as fast as it can be. I'm just saying to not make programs as slow as they can be, all in the name of "readability". Too often have I seen good coding practices sacrificed because somebody thinks that this or that *OBVIOUSLY* bad code is easier to understand or read.

      Readability of code is a matter of opinion, because different people have different skill levels of reading code. It's just a fact. For any given chunk of code, there's a hell of a lot of ways to do it, and all I'm asking is to not pick the stupid ones simply because they are easier to read. Pick the smarter ones that are almost as easy to read instead.

      --
      - 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.
    4. Re:I agree... and disagree... by Kenbo · · Score: 1
      You *can* write both readable and "fast enough" code in one pass. Any good programmer does it on a regular basis.

      I agree completely. Unfortunately not all of the programmers I deal with are experienced enough to do this well. I want them to err on the side of readability but I don't want them to do stupid excruciatingly slow things for absolute readability.

      I should have indicated in my post that only the first paragraph was in response to your post. The rest of it was a small mini-rant based on my experience in maintaining production apps. Perhaps I'm overly sensitive as I've just been through a pretty disasterous production outage due to someones attempt to speed up code that didn't need speeding up. When the usage pattern changed from what was originally specced it brought down the whole app (java GC thrashing).

  137. Agreed...it's the thoght process by mveloso · · Score: 1

    Learning assembly, even if it's not on your platform, is good mainly because it imparts discipline. That doesn't mean you have to hand-tweak and optimize every freaking line of code.

    But what it might get you is the ability to make those little decisions with a bias towards effciency. When you write a function, there are hundreds, if not thousands, of little decisions you make. Inline it or break it out? Put it in a loop, or break it out of the loop? How many calls might that be?

    All these little things add up. If you understand how the compiler optmizes (for example, hoisting or CSE) you can do it yourself and save a little time. A little time here & there add up.

    For example, positive loop tests should be first because almost every CPU branch-predicts on the positive case. Doh!

    Hoist constant expressions out of a loop. Why not? Your Java compiler is usually too dumb, it might save a lot of time.

    You can also do stuff in Java, too. Check the output - did you know references to an object's instance variable is more expensive than copying it locally to the function? Save a million cycles in a big loop.

    It's not like thinking like this is hard, once you've done assembly. It's kind of automatic. It's also hard, because you have to do only as much as necessary, not more.

  138. 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
  139. People who were raised on Java... by callipygian-showsyst · · Score: 1
    People raised on Java or other pedophilic programming languages don't have a CLUE as to what really goes on inside their computers!

    Shipping software is all about where the rubber meets the road. It's important, especially when it comes to debugging and handling bizarre crash conditions, to know what happens at the most elemental level.

  140. 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.

  141. 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.

  142. 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.

  143. You should know it, but not use it by be-fan · · Score: 1

    Knowing assembly is useful. Assembly itself, as a general purpose language, is pretty much useless. A programmer should intimately know his compiler, and what sorts of machine code it generates, and then just write in the high-level language, confident that his low-level knowledge will allow him to coerce his compiler into generating good code.

    --
    A deep unwavering belief is a sure sign you're missing something...
  144. Office bloat by nander25 · · Score: 1

    If 640k was really enough then why need 128mb just to type a damn paper in Word?

  145. 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.

  146. Re: No, really, don't bother. by Anonymous Coward · · Score: 0

    I have seen this attitude destroy companies while their competitors were able to implements features based on advanced algorithms, data structures, and knowledge of the underlying hardware. I think the only reason it manages to persevere is that so many companies do not need to rely on advanced technology for a competitive edge. It's probably also the reason that I can't manage to find a single bank that I would consider competent with regards to their computing infrastructure.

  147. 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.

  148. Or just maybe... by Anonymous Coward · · Score: 0

    Maybe your algorithms suck, since that's a difference of 2x. Could it be so?

  149. Optimization vs. Algorithms by Anonymous Coward · · Score: 1, Insightful

    Some people say you need to optimize. Other people say you need a better algorithm. So who's right? Both.

    If there's a better algorithm, you need to use it.

    If optimizing your code can make it 10 times faster, you need to optimize it.

    Now if optimizing your code will yeild less than a 2x increase (with less than simple changes), then perhaps you shouldn't bother, especially if it makes the code a lot harder to work with, but the same applies to algorithms as well. There's no need to implement a complicated sorting algorithm to sort five items, even if it will double the speed.

    The problem is people usually don't know that their code can be optimized anymore than they know that a better algorithm exists.

    People don't intentionally write slow code, they write slow code for the same reason they use slow algorithms, because they don't know any better.

    Just as you should research algorithms for whatever you're doing, you should also learn how to write fast code in whatever language you are using. The only reason assembly language does well here is because more code equals more work for the processor, whereas in high level languages fifty lines code may execute very quickly while one single line elsewhere takes twenty times as long as those 50 lines.

    Learning assembly isn't necessary. All that necessary is knowing what the difference between "($one, $two, $three) = $things =~ /(.+)\s(.+)\s(.+)/" and "($one, $two, $three) = split ' ', $things". However, knowing assembly does help. Since I know assembly, I know that the latter results in some executions of "scasb" to find spaces, and seperating the string, whereas matching a regular expression is pretty complicated, despite the fact that someone has really optimized it and it doesn't do as bad as it could.

    BTW, a compiler being "optimizing" doesn't mean it creates the best code, it just means it doesn't create as bad of code as it could. You can create a compiler that always turns certain C statements into certain code, then you can make an optimizing one that eliminates some code since it knows that this followed by that doesn't need a few of those instructions, but you can't replace someone who knows what they're doing.

    After all, isn't the reason you're supposed to use C's strcat instead of copying the string yourself because the strcat uses the movsb instruction which is faster than any loop the compiler would create on it's own?

    Of course, even so, you could still do better using assembly, depending on what you're doing. If you implemented pascal type strings you would remove the requirement of doing an scasb on the strings to find their lengths which you need to do the movsb. This could be a major optimization depending on the size of your strings and how often you're using strcat.

  150. Profiling with what? by Gldm · · Score: 1

    I tried finding a way to profile my code recently. I found AMD's profiler was totally incomprehensible. So I tried to download Intel's, even though I'm using an AMD CPU. Well it was so hard to figure out how to use that the trial expired before I ever got to use it once, and they want some hideous amount of money for a version that doesn't expire.

    --

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

  151. Of course it's good! by jaghatarjankare · · Score: 1

    When is it going to be bad to understand computers when you work with them?

    What a dumb discussion. What a bunch of pussies.

  152. Applications and hardware by Anonymous Coward · · Score: 0

    The real problem is that the guys who are using the heavy duty numerics aren't the same guys who can write in assembly or even have much understanding of machine architecture. /n We manage ~2 million lines of fortran code for computation. I compile with various modes of optimization often to get hanging compilers and hanging IPA processes for even moderately aggressive optimization. To give you an idea of how much computation our machines are asked to do, a single pass can require 400,000,000,000,000 double precision multiplications. So put that in your pipe and smoke it.

  153. So many are missing the point by Anonymous Coward · · Score: 0

    The point of learning assembly is not that everthing should be coded in assembly. Learning assembly will give people skills that they often would not have otherwise.

    The efficiency of people who have learned assembly is not just thinking about the machine inetnals and pure execution speed. It also the skills they have learned to handle complexity. If you write anything of decent complexity in assembly, you damn well better learn how to write clean code, otherwise, along with all the other details you now have to keep in mind, it will bite you in the ass. You learn to structure data appropriately, or you waste time (programmer effort) now handling memory at a much lower level than with a higher level language. You learn to modualarize, or have painfully long (source-code wise) obscure code that really isn't fun to debug. And you also learn to comment (or you get damn good at reading code).

  154. Development time is king. by raehl · · Score: 1

    If I'm writing a program in Perl in 10 minutes that is executed in 10 seconds....

    But I can write the same program in C in 20 minutes and it takes only 1 second to execute...

    I would have to execute the program 66 times to break even. If perl was 10x as slow as C, which isn't true. More realistically, perl is .1x as slow as C, in which case I'd have to execute the program 6600 times to break even.

    *IF* you assume computational time is equal to human time. I cost $60/hr, or $10 per 10 minutes. A $1k computer, appreciated over a year, costs $0.02 per 10 minutes. At those rates, I'd have to execute the program 3300000 times to break even.

    Even on a computer that cost $1 million, the program would have to be executed 3,300 times to break even.

    Perl is better than C, for the vast majority of cases programs are written for.

    1. Re:Development time is king. by KnacTheMife · · Score: 0

      "If perl was 10x as slow as C, which isn't true. More realistically, perl is .1x as slow as C,"

      Any proof for this?

      "in which case I'd have to execute the program 6600 times to break even."

      even if I accepted the premise as true, if dev time in Perl was less and exectution time is faster (".1x as slow"), then how can there be a break even point?

      "Perl is better than C, for the vast majority of cases programs are written for."

      Any proof to offer? Hypotheticals are not proof.

      --
      -- "Someone's gotta go back for a shit-load of dimes."
    2. Re:Development time is king. by Anonymous Coward · · Score: 0

      ..except in the case where you code is not a one-time shot to do something and then throw it away.

      your Perl program that too 10 minutes to write and executed in 10 seconds is great for a one time shot deal.. do it myself all the time..

      If that program is going to run every hour for the next year, the 20 minutes it takes to write in C to get it to run in 1 second each time becomes more favorable. 8760 seconds/year instead of 10 times that. You presume that the computer in question, with your numbers, is doing nothing else besides your program. If that computer is executing other things, and your 10 seconds slows *them* down, your numbers are shot-to-shit. What if that computer is supporting 600 users at $30/hr, and by coding in Perl instead of C you slow them down by even a second every time they run? Thats 600 users, 1 second each, per hour.. 600 seconds (10 minutes) per hour - or $5/hr lost because of your inefficiency. Even presuming weekends/vacations, and 8 hours/workday, 200 days/year, thats $8000/year *lost* to you saving them $10 in development time.

    3. Re:Development time is king. by Anonymous Coward · · Score: 1, Interesting

      I would have to execute the program 66 times to break even. If perl was 10x as slow as C, which isn't true.

      You're right. According to Bagley's famous Great Shootout, perl is only twice as slow as C - for operations for which perl is optimised, such as accessing elements in associative arrays. For numerical operations, like matrix multiplication, the sort of thing where runtime optimisations have been shown to let Java perform as well as C, perl runs... 500 times slower than C.

      If you want to champion high-level languages, pick a high-level language like Lisp or ML which can be compiled to native code. Ocaml programs regularly perform as well as C, despite being written in a language that's nearly as quick to program in as perl.

    4. Re:Development time is king. by sjames · · Score: 1

      *IF* you assume computational time is equal to human time. I cost $60/hr, or $10 per 10 minutes. A $1k computer, appreciated over a year, costs $0.02 per 10 minutes. At those rates, I'd have to execute the program 3300000 times to break even.

      The problem is, you assume a single instance of the program. Let's take another case.

      Let's say that a productivity package can be written quick and dirty in 1 man year. It can be written to be twice as fast in 10 man years. It will be used by 100,000 office workers full time. Let's further stipulate that the developers cost 10 times as much per hour as the office workers. Given these generous assumptions, choosing the slower version wastes 50,000/10 equivilant cost man-years per year or 5000 developer years in cost. In other words for the cost in lost productivity for going with the slow version, you could have afforded to do it right 500 times over.

      To over prove the point, if the office workers are only paid minimum wage, and the useful life of the app is 3 years, doing it right will provide breakeven even if you pay the developers 15,000,000/year.

      We all know developers don't get 15 million a year, but it's not that hard to show that in a world of sane and informed economic decisions it would be well worth paying top dollar for developers that do understand performance issues and then spending copious amounts of their time improving application performance.

      You gave an example of one extreme end of the spectrum, my counterexample is on the other.

      What this really says is that there is a place for both approaches, and part of the job is determining the use patterns of the application so that appropriate optomizations can be done.

      I think it isn't so much that newer programmers don't know assembly language per se. it's that they have never had to program on a machine with very limited power while still having to provide a decent 'user experience'. Without that, they have no idea about where to start looking for speedups, and happily waste many meg of memory because "everyone has a gig of RAM these days".

      It goes beyond simply producing fast compact and eligant user apps. Without that knowlkedge, how will they do with kernel programming where the memory they waste can't be paged out at all, or embedded programming where the memory simply isn't there and there may not be any swap?

      People who needlessly bloat applications should be sentenced to a year of using their own app on a P200 with 32 Meg of RAM. I'll bet they start fixing the bloat in a hurry once they learn how.

    5. Re:Development time is king. by simonjester2424 · · Score: 1

      And what if the slower code you have written is too slow for your audience? Or is for real-time applications? Needs to be low-latency? I have no real opinion about the speed differences of the two, but I disagree when you say that most of the time a program that takes ten times longer to run is better if it takes half as long to write. I can see too many instances where that would be totally unrealistic. What happens when another programmer/team takes the extra time and has a much more responsive program and the perspective customer gets a look at this?

      --
      Beware of gifts bearing Greeks.
  155. 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!

  156. Learn BOTH ways by 12357bd · · Score: 1

    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.

    You need BOTH ways, the minimalist one goes for beauty and clarity (pleases the human reader), but the other is the realistic one and if you forget about it, you loose the game, after all is the register and page faults world that gets the work done, so I think its better to know both and choose whatever you want in any situation.
    But you are right, as the distance between the machine and the language increases, so it does the dificulty of learnning how to optimize the code.
    I've been waitting for a change in computer structure for years, where are those prolog machines, or java cpu's? lost in the bottom of logical computation ocean? :)

    What's in a sig?

    --
    What's in a sig?
    1. Re:Learn BOTH ways by Anonymous Coward · · Score: 0

      Please note that if you learn real, modern lisp, you kinda get both anyway- ANSI standard Common Lisp requires in-language integrated debugging facilities, including a tracer and a disassembler.

  157. 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?
  158. He hates Linux by Anonymous Coward · · Score: 0

    I wonder how you whining Slashdot Linux wannabes would react if you knew that Randy actually said this in class one day in the late 90s:

    "Windows is infinitely superior to Linux."

    1. Re:He hates Linux by Anonymous Coward · · Score: 0

      Here is my whining linux wannabe reaction to this quote from Randy:

      I immediately ran out and bought a windows box. Then I changed my line of work from academic computing to web development.

  159. 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 ;)

    1. Re:even better: learn to write a compiler by the_greywolf · · Score: 1
      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 my local community college, the CS course involves C, C++, Pascal, and Visual Basic. that's it. of course, it' s jsut a community college. so, i checked into several larger colleges in the US: i don't know of any in the northwestern or midwest US that offer systems programming ouside their Soft. Eng> courses or before the fourth year in CS.

      someone PLEASE tell me of a college in Washington state has a CS course that includes Assembly or systems programming! i'm moving there next month and i'd like to go back to college.

      --
      grey wolf
      LET FORTRAN DIE!
  160. 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
  161. 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
  162. assembler.. by alexhard · · Score: 0, Troll

    Assembly is for fags! Try brainfuck if youre out for a challenge *evil laughter*

    --
    Infinite time means everything that can happen, will. You being you is absolutely incidental. You do not exist.
    1. Re:assembler.. by Anonymous Coward · · Score: 0

      You really are a genius!

  163. 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"

  164. 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
  165. I think many, many people missed the point by Photo_Nut · · Score: 1

    "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."

    While I agree with much of what you are saying, you're 100% wrong here. Try as much as you want to, the engineers who wrote the optimizer for the compiler know far more about how to make its output efficient than you do. Most attempts to "hand-optimize" code actually make it worse. The only place you need to use assembly is when writing certain low-level parts of an Operating System or a Device Driver. Do you know which of the 15 different ways to zero a register executes the fastest on your CPU version? How about which one is the smallest instruction? Your compiler does. Also, it knows how to schedule the operation so that on the latest 5 CPUs, the execution happens in parallel with the previous set of instruction. Which variables should be in registers, and which should be left on the stack? Heap? Did you play the red-pebble, blue-pebble game? How does the scheduling improve if we unroll that loop? Can we improve the branch-prediction here? These questions are answered by the compiler to degrees you don't need to or want to know about. Are you optimizing for space or time? Do you understand why optimizing for space may improve the execution of your code more than optimizing for time?

    Your algorithm assertion about an O(n) vs O(lg n) only holds as n becomes very large, and is only relevant if the situation warrants it. It isn't bad design to choose an inferior algorithm which makes the code more maintainable. Your O(n) time algorithm may run within O(n) space that has been allocated locally and happens to be within the cache, whereas your O(lg n) time algorithm may run within O(x(n)) space already allocated, but outside the cached memory. Now your O(lg n) includes O(x) page switches at a painful C.

    The point is that knowledge of algorithms doesn't make you a good engineer. Engineering is about designing something, building it, and testing it.

    Assembly language is terribly important to understand when writing C and C++, because you learn the constraints of the system. You cannot dereference a NULL pointer and expect your program to behave correctly. If you don't allocate enough memory for your input, and you don't document it, and you don't check your assumptions then you deserve what happens to you when a customer exploits you by asking for x bytes and delivering x + exploit bytes.

    Granted, you do not need to completely understand all assembly language to get these concepts, but I wouldn't hire you as a developer on my team if you couldn't tell me what an Access Violation is, or why it happens when you dereference 0, I also think it's important that you understand interrupts and exceptions, and how to write code so that if an exception is thrown, you handle it correctly. Being sloppy because you are lazy or uninformed isn't acceptable when millions of people run your code. Just because your specific computer runs at 3GHz with the ability to retire instructions from separate threads simultaneously doesn't mean that your customer's battery-saving laptop running between 300 and 900MHz makes short work of it while they're running their MP3s and typing out their homework. If you need to spin up their HD to hit virtual memory because you're being lazy, you may have just cost them 10 minutes of battery life. Spinning up and spinning down a HD is expensive.

    "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 c

    1. Re:I think many, many people missed the point by Temporal · · Score: 1

      Most of the things you point out in your post are things I already know, and don't really change my argument. Of course the compiler can optimize better than most humans. That only supports my assertion that knowing assembly is useless. Of course O(n^2) algorithms are ok for small data sets, but for small data sets the question of efficiency is irrelevant anyway. Of course C programmers need to know what an access violation is. But, you don't need to know assembly for that, and it has nothing to do with efficiency anyway. 500MHz is still absurdly fast. Of course I/O is important to efficiency; in fact, it is far more important than CPU usage. I/O is very slow, and just about any time a real-life program seems to be acting "slow" theses days, I/O is the reason. However, this article was about how knowing assembly will help you write efficient code, and that has absolutely nothing to do with I/O. Knowing assembly won't improve your I/O rates or your I/O handling techniques. Battery lifetime is also outside the scope of this article, except that less CPU usage probably leads to longer battery life. But then, all of my points above (about how most programs use 0.1% CPU power anyway, so improving that is irrelevant) apply in that case. As for your last paragraph... again, the article was all about knowing assembly language so that you can understand efficiency better, which seems to have nothing to do with "saving the user's work when you're running out of memory".

  166. [OFFTOPIC AS HELL, NO NEED FOR MODDING DOWN] by LocalH · · Score: 1

    Holy shit, I know you. ^_^

    --
    FC Closer
  167. As another UC Riverside student. by ObiWonKanblomi · · Score: 1

    Totally agreeing with Mr. Jones on this.

    I, as well, went to UC Riverside, and studied under Hyde in two courses. CS-013, lower division course, but still tough, because it covered many many aspects of ASM which helped me understand in basic terms what the direct consequences of typing code can lead to.

    Very great teacher, and I'm glad I had him at UCR. Btw, Art of Assembly is a great book!

  168. 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.

  169. Assembler or Assembly ?? by Anonymous Coward · · Score: 0

    Please help an ignorant me.
    25 years ago when I learnt assembler on a PDP11, it was assembler. These days, it is assembly.

    Can someone enlighten me on this change ?

    Thanks !

  170. Still teach assemby at Adelaide Uni by shenki · · Score: 1

    Here at Adelaide Uni, Australia, where I'm currently in 2nd year Computer Systems Engineering, everyone who does CS or any of the Electrical Engineering degrees do a semester of DLX assembly... and I'm pretty sure there's more to come in later years.

    --
    It's not an optical illusion, it just looks like one!
  171. Yeah, in MY days... ;-) by PaulBu · · Score: 1

    ... viruses used to live in the boot sector of a 5" floppy disk, while keeping the whole bootloader there as well, AND in the worst cases there were a handful of those on a single disk (bootsector) ;-) I can understand the fun of writing something like this back then, but the "Hey, dude, click here for your document..." is just plain silly... ;-)

    Paul B.

    1. Re:Yeah, in MY days... ;-) by Reziac · · Score: 1

      Ah, filesharing in the good old days... they weren't really any better, but we were a lot younger :)

      Does anyone else still set boot order to C: A: to prevent the accidental loading of an undetected BSV?

      And now it's not just "Hey, dude, click here for your document..." it's "and then turn your back for half an hour while it invites all its friends!"

      --
      ~REZ~ #43301. Who'd fake being me anyway?
    2. Re:Yeah, in MY days... ;-) by PaulBu · · Score: 1

      Ah, filesharing in the good old days... they weren't really any better, but we were a lot younger :)

      Yeah, yeah... ;-)

      Does anyone else still set boot order to C: A: to prevent the accidental loading of an undetected BSV?

      As a matter of fact, YES! ;-) Actually the last time a BSV tried to bit me was a couple of months ago (!) when I picked up a floppy from the ground on a street corner in some relatively bad area of LA (do not ask me what brought me there, some cultural/artistic thing my GF participated in ;-) ), was just curious what was on it... Well, among other things a BSV, but fortunately it had no idea how to infect a Linux box, but I had to forget the floppy in the drive to find out... ;-)

      Paul B.

    3. Re:Yeah, in MY days... ;-) by Reziac · · Score: 1

      LOL! What did your mother tell you about eating files you find on the ground? :)

      Actually, there was one cross-platform BSV that could infect DOS or UNIX systems -- can't remember for sure if it was QUOX or something else.

      --
      ~REZ~ #43301. Who'd fake being me anyway?
  172. 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.

  173. Rediculous! by ztwilight · · Score: 1

    Assembly is for amateurs! Reel programmers program in AppleScript!

    --
    Who moved my sig?
  174. Great code uh? by Anonymous Coward · · Score: 0

    Randall is the author of Write Great Code (from No Starch Press).

    He should learn asseembly in order to get smaller binary code.

  175. Re:Counterpoint (OT) by anethema · · Score: 1

    Yeah, i agree, ultraedit is a fuckin great editor.

    Good for programming, hex editing, text editing.

    Great all around...very powerful.

    --


    It's easier to fight for one's principles than to live up to them.
  176. Points: by Anonymous Coward · · Score: 0

    1) Lex & yacc are fucking shit.

    2) Java is not a scripting language. Get over it.

    1. Re:Points: by Anonymous Coward · · Score: 0

      Yes, java is not a scripting language. But it combines the inconvenience and straightjacketing of a static C++ style language with the speed of a badly-implemented scripting language.

      Use Lisp. Use ML. Don't even try to pretend Java doesn't suck.

  177. Re:Counterpoint (OT) by anethema · · Score: 1

    Sorry to reply to my own post here...

    But infact, I just found a 350mb divx, right clicked..ultraedit..

    Took about 8-9 seconds(raid0 helps), but ultraedit opened it just fine...I'm now looking at all the hex and ascii, std hex editor.

    Give it a shot :)

    --


    It's easier to fight for one's principles than to live up to them.
  178. 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.
  179. To be able to write compilers by Sindri · · Score: 1

    I thought the reason one learns assembly language today is to be able to write compilers.

  180. 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.
    1. Re:IRTA but found it poor by Anonymous Coward · · Score: 0
      • Not wether you knew if a certain assemly instruction uses two cycles more
      Bullshit. Anytime you're in a loop, even a one or two cycle savings grows exponentially as the number of iterations increases.
  181. 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
  182. Proprietary Software by JuniorJack · · Score: 1

    Maybe learning assembly will be usefull to the programmers of those companies that make very expencive engineering packages sold for 5000+ USD, and they can be downloaded free on the wares sites in a matter of few days after release.

  183. 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.

  184. 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."
  185. 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"

  186. 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.
  187. 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

  188. Parrot by Pan+T.+Hose · · Score: 1

    For those who don't know Parrot, I forgot to mention that Parrot is a VM which will serve as a backend for such languages as Perl5, Perl6, Python, Ruby, Tcl, et al. IMCC is an intermediate language which will be a target of those high-level languages' compilers and Parrot itself will serve as a portable interpreter of compiled byte-code, with JIT support on many platforms.

    --
    Sincerely,
    Pan Tarhei Hosé, PhD.
    "Homo sum et cogito ergo odi profanum vulgus et libido."
  189. Impressing the ladies by rve · · Score: 1

    The skills I developed as a teenager in hand coding self modifying code written in 6502 assembly and writing DOS programs straight in microsofts debug still come in useful every day, even though the 6502 has long been defunct, and the Pentium 4 has ver little to do with the 8086 I learned to master. Oh my youth was spent so productively.

    It impresses the girls more than anything else, I tell you!

  190. 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.
  191. 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.

  192. 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.

  193. Re:Learning Asembly from Hyde made me a better cod by Vexar · · Score: 1
    I thought it was that pompous old jerk. God, I miss him. Reports from an old friend who still lives in Riverside say Randy was fired and never reached tenure. Reports also indicate that Gerardo Beni still has a job, so it sounds like business as usual in academia!

    To this day, the lessons he taught me remain indispensable. For those who haven't taken a course from him, I suggest at least reading his writing pertinent to the development of skills as a programmer. Do not, however, take any lessons from him on the art of social graces.

    I still think that the best course he ever taught was the one-shot CS 185, or commercial software development. There, we learned what it means to plan a project and be off by a country mile on how long it would take. Better there than in the real world.

    Randy was quite the stickler on commenting code. I think that, more than anything else, is a testament to his vision of churning out disciplined programmers, even if it meant they hated his guts. I am only too sorry he didn't figure out how to interact with others like a well-adjusted adult, or maybe he would have kept his job at UC Riverside. In addition to being a student, I had the distinct displeasure to regularly interact with him on his Mirage+ research program (Distributed Shared Memory).

    I wonder what he would have said about Java. Mr. Jones, you are right, he definitely made a great weeder course out of x86 Assembly. I was on a very short list of Art students to take the course. For me, the weeding worked the opposite direction. Six months after I took CS 13, I came back as a Computer Science student. I've met CS grads with master's degrees from a dozen supposedly more reputable who know less about operating systems, or programming in general than the average 2nd year CS student at UC Riverside. That is to say, someone who has passed CS 13!

    Treasure your experience with Randy Hyde, good or bad you learned from it.

  194. 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.

  195. Write a compiler by Nurgled · · Score: 1

    One time long ago I wrote a compiler for a simple little programming language which generated code for the 6502. It was the most useful personal project I ever did, even if the results weren't exactly brilliant. (the language was quite limited and the code not really optimised at all.)

    I think this would make a good project for CS undergrads. They'd see just what the code they've written in a high-level language is doing at the metal and get a new appreciation for why, for example, it is bad to pass fifteen large parameters by value.

    I guess in the US most universities actually do have a compilers class. Here in the UK, none of the universities attended by me or my friends offer anything like this. The closest my university came was some really trivial assembly programming on a PIC microprocessor to make some red LEDs blink on and off.

  196. 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.

  197. sure it might. by twitter · · Score: 1
    Optimising your code for one architecture can make it run more slowly than unoptimised code on another.

    That's true. The author's point was that you should be aware of the cost. I don't see a conflict.

    --

    Friends don't help friends install M$ junk.

  198. 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).

  199. Re: No, really, don't bother. by RGreene · · Score: 1

    I am in an industry-leading company. There is no reason to use assembly.

    Here's what I do for a living:
    * XML
    * Database
    * Multi-threading
    * Web-site design
    * Real-time processing
    * Data mapping
    * Minor calculations
    * Web services (straight XML or SOAP)
    Assembly isn't worth anything in this environment. I also expect that the bulk of developers are very similar. Remember that the bulk of business code used to be written in COBOL? That's the type of software I'm talking about. We happen to be a J2EE shop, so we're working in Java. Our code is deployed to multiple architectures (x86/W2K, x86/Linux, SunOS, AIX).

    I would be interested to hear how knowing assembly helps you with advanced algorithms and data structures. It seems to me that a higher-level language will help a lot more! Not to mention good OO design and component-based architectures.

    Now, a bit of back-tracking. I'm not saying that assembly is worthless. There will be areas that it makes sense - but I really doubt that the majority of software developers have any use for those skills. Most developers are not:
    * Writing low-level device drivers (graphic, network, etc)
    * OS Kernel hackers
    * Microcoders (I expect this to be the largest congingent in the list)

    Face the facts, most developers must concentrate on a business problem at hand and efficiency at the chip level isn't a concern. In general, if you're worried about the computer's efficiency you better check your algorithm and/or design - there is probably one with a better fit!

    In 14+ years of professional development, I haven't had to worry about assembly. In 20+ years of software development, the only place I worried about assembly language was on the trusty Apple IIe, my ONE class in assembly (not sure it helped), and now my hobbies with microcontrollers. That's it!

  200. 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.
  201. emacs by Anonymous Coward · · Score: 0

    Emacs will eat a 100MB file and ask for more. :-)

    Seriously, just yesterday I was editing a 80MB debug logfile in emacs. Loaded in a few seconds; once it was in operations were just as fast as normal, including macros/etc. This was on an 800MHz PIII.

  202. 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.

  203. WHa thwe FUCK CUNTs by Anonymous Coward · · Score: 0

    This is the first -1 post in this story! Waht a greats achivments for mee. HAHA. Linux losers fukof. hahahahahazzzzz.

  204. Urban legend? (not teaching assembly anymore) by Lawrence_Bird · · Score: 1

    Well I just checked my alma matter, Lehigh, to see whats
    required there these days. They appear to have merged a lot
    of the CS program with the CSE dept., probably a good thing.
    But even the BA program requires two classes requiring assembly. Even Lafayette College, the nearby arts and crafts school has courses that delve into assembly. So,
    being the totally un-PC person that I am, is the 'they don't teach assembly anymore' :

    a) urban legend
    b) dependent on the 'quality' of school you attend?'

  205. 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.

  206. ot by waspleg · · Score: 1

    bleh that's bs everyone knows al gore likes movies about gladiators

  207. Re: No, really, don't bother. by dolmen.fr · · Score: 1

    As you are working with Java, x86 assembly may not be the most insteresting thing to learn for you.

    However, I'm convinced that understanding JVM byte code and the garbage collector is required:
    - knowing how the garbage collector works helps to avoid memory leaks
    - exmaining the byte code of your own program will help you to learn how the compiler works. For example, how it uses StringBuffer for String concatenations.

  208. You by Anonymous Coward · · Score: 0

    Are all stupid.

    Forth is your master!

    BOW before the god of Forth you weak mortals!

    1. Re:You by Anonymous Coward · · Score: 0

      I actually LIKE postfix assembler as implemented in several Forth variants.

  209. A little different... by Dirk+Pitt · · Score: 1

    In CompE school we took intro programming courses and datastructures freshmen year, followed by a full year of Assembly/Machine Programming the following year. I thought this was a pretty good approach; define the basic abstractions of what you'll be doing, and then go learn exactly how they work. (and then moving on to silicon programming and digital design, progressing even further from there, you *really* get to understand how those little C programs work)

  210. Why it's usually not... by Anonymous+Brave+Guy · · Score: 1
    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.

    The curriculum should certainly include assembler, but only because learning assembly is a way to gain better insight. I've written my fair share of ASM code over the years, but today it's good for supporting higher level languages, and pretty much nothing else.

    Consider the effort to get optimisations right by hand on modern architectures when compilers are written to do it systematically, the lack of anything beyond the most primitive functionality compared to HLLs or archives like CPAN, and the complete lack of portability in an era where shifting your code on diverse platforms is becoming ever more important. All of these things are good enough reasons to opt for a higher level alternative in their own right, and all are near universal truths in today's development environments.

    That's not to say ASM isn't useful for the right things. It's just that those things are such a vanishingly small part of the software development world that I think ASM's value is now far greater as an aid to understanding higher level languages than it is as a development tool in its own right. If you need to write ASM code, sure, take a specialist course, but don't waste time with the details in a general programming or CS course; there are far more important concepts to teach in a limited amount of time.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  211. Gibson Research by bluyonder · · Score: 2, Informative

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

  212. 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.

  213. No! Go lower! by Anonymous Coward · · Score: 1, Funny

    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.

    I really think learning asm makes the most sense when using it on a cpu you've built from scratch. Though I think building a software simulation will do, as all the time spent debugging the hardware isn't really a skill a CS major needs anymore...

  214. TI C67x by Anonymous Coward · · Score: 0

    I agree, I get really confused sometimes when writing TI C67x code. But if you know how to take advantage of the delays slots and the parallell units you can do amazing thing. For some functions it is not to hard to cut the cycle count into half, and if you think about it for a while you can cut it into half again. For me it can take days to translate a few lines of C code into to optimized assembler, but it pays of if it makes your algorithm run in real time.

  215. 1% or 2% improvement by exp(pi*sqrt(163)) · · Score: 1

    I can see you have much to learn about assembly.

    --
    Doesn't it make you feel good to know that our freedoms are protected by politicans, lawyers and journalists.
    1. Re:1% or 2% improvement by arevos · · Score: 1

      I'm rather familiar with assembly, though the last time I fiddled with it was back two years ago when my CompSci degree covered a lengthy course on low-level hardware design and architecture (if I recall, we were using 68008 chips).

      I remember back in the days of 486s and such, that my father wrote several tests in both C and assembly. There was little difference between the speed of the resulting programs. It could be that the assembly was programmed badly, but my father has a background in hardware and low-level design-work, so I'm not so certain of that.

      Bear in mind that today's C compilers, especially the processor-specific ones, can optimise code considerably better than they used to do. So I don't think that assembly, nowadays, works very well. Sometimes, code-generators are more efficient than human hand. For instance, lexer-generators are generally more efficent than hand-written lexers. I'd imagine that your average C compiler today, wouldn't offer much slowdown over something programmed entirely in assembly.

      I think a 1% to 2% speed increase for a modern 3D game is generous, at best. If you have statistics to prove different, then be my guest and post them. However, whilst you claim that I do not know much about assembly, I'd contend that if you think pieces of assembly would have any significant effect on a 3D game, you don't know a lot about 3D graphics. The bottleneck is not in the code, but the algorithms.

      I'm fairly sure an professional game programmer could write a much faster 3D engine in, say, python or perl, than a less experienced programmer could write in C, or even in C/assembly.

  216. Re:Learning Asembly from Hyde made me a better cod by OcabJ · · Score: 1

    I took CS13 taught by Randall Hyde back in my Freshman year (Spring 1998 Quarter). It is one of my favorite courses that I ever took in my 4 years at UCR. Randall Hyde got trashed by a lot of the students, but I respected him. I thought his teaching was effective and sound.

    Not sure what happened to him after he stopped lecturing at UCR.

    He still has his website/webserver up: http://webster.cs.ucr.edu

    Did any of you guys participate in the 'computer shoot' he used to have every quarter or so? I guess he stopped holding them before I started college, but I remember he had a webpage about it on his site (no longer on the site).

  217. 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.

  218. a game to teach assembly concepts by jayster · · Score: 1

    A buddy of mine and I are working on a board game to help teach machine coding concepts. My friend is not a programmer, but he says just the little bit we've done on the game so far has greatly improved his understanding of how computers really work internally.

    My motivation is that the next generation of computer programmers (people growing up now and eventually my 6-year-old son and his contemporaries) should have only had exposure to OOPsy languages, GUI-screwy windowing environments and so forth, and won't have a clue about the many, many layers of abstraction that lie between those and the hardware.

    I see this as a potential major crisis in the making for the programming community in general.

    --
    "Anybody can change the world, but most people probably shouldn't." -- Marge Simpson
  219. Set permissions and privledges conservatively by gotr00t · · Score: 1
    There are a number of outstanding loopholes in almost all linux systems, or all *nix systems for that matter. Doing an infinite fork, or making a function recur indefinately will cause the system to mess around with swap memory, slowing it down to the point of inaccessibilty.

    For systems where the users can compile and execute their own programs, the users must have some level of trust, where any responsible admin would know their identity, etc. . On public access systems, for example, no compiling or usage of uploaded binaries is allowed (or shouldn't be, for any competent admin) Sure this is a big deal, but it won't cause as many problems as say, the sasser worm for Windows, or any remote exploit.

    1. Re:Set permissions and privledges conservatively by Anonymous Coward · · Score: 0

      There are a number of outstanding loopholes in almost all linux systems, or all *nix systems for that matter. Doing an infinite fork, or making a function recur indefinately will cause the system to mess around with swap memory, slowing it down to the point of inaccessibilty.

      The "loopholes" are in the heads of the admins that don't understand and use ulimit, not in the systems.

  220. And it can be fun! by Anonymous Coward · · Score: 0
    Maybe I've beem doing this too long (I wrote my first program in 1968 in PL/1), but everyone has ignored one important reason for knowing assembler:

    IT CAN BE FUN!!!!!!!!

    It is also true that knowing more programming paradigms makes you a better progammer in all ways. My personal experience is that I am a better C/C++ coder becasue I know both assembly and LISP, as I am a better LISP coder becasue I know C/C++, and so on.

    Being a better coder dosn't just mean writing faster code or more readable code. It means being able to write code in a style that matches the requirments of the project. Knowing how to go fast or clean or flexable or some combination is where the real skill lies.

    I look back fondly on my the time I spent assembly language programming on the Cray. It has been of great use when I have to write fast image processing code in C. Enjoying the work can be a big part of doing a good job.

  221. As a budding programmer by g0bshiTe · · Score: 1

    I have struggled with programming concepts for years. One day I happened upon The Art of Assembly by Randall Hyde. Up to this point I had spent countless hundress of dollars on various teach yourself books, even some texts that were used to train programmers at one time ( the Knuth series ). Yet the basic concepts of programming eluded me. I knew how to declare variables etc ... yet I couldnt grasp how to design my program. Enter AoA, of all things this free text opened the door and all the texts I had read previously clicked. Everything seemed to fall into place. After a year I am still learning to program, but have since begun on different languages and platforms. I sent Mr. Hyde an email thanking him. I was surprised when he replied. Needless to say his text had inspired me to learn ASM. Though with modern compilers it isn't necessary to know ASM, I have found it useful.

    --
    I am Bennett Haselton! I am Bennett Haselton!
  222. Bah humbug by betelgeuse68 · · Score: 1

    I don't buy either of these premises:

    1) That assembly has major relevance today
    2) The best implementations are written by those who've mastered assembly language

    On point #2, "best" is very subjective and subject to interpretation. Does this mean, minimum # of defects per X lines of code? Extensibility?

    As someone who learned assembly in the early 80's (when I got started on 8 bit microcomputers) I don't see much relevance for intimately assembly language today.

    It would be like me arguing that I should learn the power industry since one day I might need to build my own generators to run equipment.

    At some point we have to resist the urge to think we can "know it all" and simply stand on the shoulders of others.

    While learning assembly is fun, after 10+ years of being a software professional, it would be nice if people know f*cking high level languages. Back in '99 when I was with an Internet company and we were interviewing for "software engineers" I was amazed at how many people claimed they knew C and could not write a f*cking strcpy routine. I didn't care about the prototype (ANSI or not) I just want to see code that did this:

    while (*dest++ = *src++);

    Sure that's the super compact one line version with no C prototype but the prototype is NOT what I was interested in, e.g., "What's the ANSI C prototype for strcpy?" I simply wanted to see if a person knew C... and if you do not know basic pointers, you don't know C.

    As it turned out, not one person I asked this question answered it. In fact, an amazing number of people made no attempt at it. I guess the Internet boom created lots of a people who saw dollar signs and were applying for jobs way out of their league.

    That's C mind you. When you look at the fact that C++ was crazily popular I can add to my anecdotes. I used to inteview people on C++ and I often asked people to rate their C++ skills. I gave them a scale and qualified 7 through 10. Mind you the scale was arbitrary but the point was to clue people in as to what my expectation of a 7 might be. One of the points I would make about a 7 (out of 10) is "You should be able to tell me off the top of your head why you would want to write a copy constructor." An amazing number of people would rate themselves 7 or higher. Want to take a stab at what the first question I asked was? Yes, "When would you want to write a copy constructor?" And like strcpy in C, most "C++ developers" seemed to be clueless on just that one question.

    Thinking in assembly language is not something that happens overnight but once you do you definitely have an understanding that few people have. Problem is, the applicability of this skillset for most "developers" is incredibly niche. Unless you're writing a compiler, debugger, writing firmware directed at embedded systems or reverse engineering some piece of code (regardless of the source media), assembly is pretty much irrelevant given the rich number of abstractions the software development community has created.

    Some of it you can attribute to open source some of it is purely Moore's Law (computing doubles every 18 months). Today we don't think twice about having a virtual machine on top of our "real computer" running our code but back in the 80's, forget it, the IBM PC was running at a mere 4.77 MHz and the performance of Pascal code compiled with Borland's Turbo Pascal completely blew away performance coming from byte code Pascal compilers employing the University of California San Diego's P-Code system.

    If you've entered computing in just the last ten years it's hard to appreciate all this but back then it made all the difference in the world.

    However, today we are not obsessed with CPU performance since performance gains coming from CPU speed increases have become minor with respect to the applications most people use, e.g., Intel has decided to stop using "GHz" to rate its processors. Besides, anyone who understands computer architecture clearly knew it was Intel's way of

  223. Correct result by faulty reasoning by domestos · · Score: 1

    Indeed. Many people will agree that learning assembler is beneficial, but the reasoning given is spurious.

    The guy who drives the mechanical excavator keeps a spade in the cab. Why? Not because it will make him more efficient at driving the machine, but because just occasionally he might have to "debug" a buried pipe or cable, or get into the corners.

    In addition, rolling his sleeves up and shovelling some mud will give him a better intuitive relationship with the stuff he works with.

    You have to know how to do any job by hand before you are truly proficient at the mechanised version.

    I'm glad I learned some assembler, but I'm also glad that most of the time there are tools which will do it better than I could.