Jump to content

I totally disagree with Steve Gibson in that programming in asm runs circles around other langua...


G+_Joe C. Hecht
 Share

Recommended Posts

I totally disagree with Steve Gibson  in that programming in asm runs circles around other languages. If you know the compiler well, then you know what it will emit, and if you code with that in mind, you can work in a higher level language, get a lot more done, and still get the same performance. I call that "counting clocks as you code". For example, in Delphi, I know that inc(i) is faster then "i := 1+1". It is a good case for learning asm, a good case for looking at the compiled code, and a good case for not working in asm. Finally, some languages (such as pascal) may let you inline asm. It is a good case for using asm, but only where it counts. Performance is usually only important in tight situations... a great case for profiling (if you need to). And good coders don't need to.

Link to comment
Share on other sites

No one doubts that higher level languages are orders of magnitude more productive for 99% of applications. Even most down to the hardware bit-fiddling I do on tiny embedded chips is in C. But he's right that there isn't a compiler in existence that can outperform hand-optimized assembly, simply because the programmer knows things about the problem space that aren't expressed in high level code. The programmer knows things like which branches are more likely, what biases the input data may have, and so on. Some of that you might be able to express in C, but assembly, hand tuned by someone who knows it well--will always be better.

 

I agree that it's not the language to use for applications other than things like OS kernels, language runtimes, interrupt handlers, and such.?

Link to comment
Share on other sites

Lee Crocker I learned a lot a Borland, were we used take apart the compiled code just to see what was optimized, and it was usually pretty hard to beat it with hand coded asm.

 

Compilers are mostly limited to optimizing jumps, loops, and memory moves, and that code has been well optimized for many, many years.

 

At the end of the day, it's all machine code.

 

If you can get to know the compiler (study either the source or the output), you will know the machine code that will get generated, and if the compiler supports it, you can slip in assembly into higher level code where it is needed.

 

It pretty much comes down to "why reinvent the wheel"? Most code bloat is caused by silly programming and bad libraries, not compilers.

 

Assembler is a great thing to learn, and certainly has a place when you need to pull out all the stops to get something specialized done really fast, but unless you have a 30 years collection of well written code to call, (and you are stuck on one platform), your probably going to get more work done with a good optimizing compiler.

 

Personally, where possible, I use a mix of high level code, and small bits of asm where needed (and where it really counts). It is kinda hard to write something really significant in asm these days.

 

You also have to consider that cross platform code becoming very valuable, and reliance on many large libraries is the only way to get most projects done. Asm is not a skill you find on many job boards, although it is a great asset to have.

 

I must admit, I am very happy to see all the excitement generated in this group over the word "assembly". I still think the show need to teach a bit more about the basics (types and structures). A little more about pointers might be good timing.

 

Joe

Link to comment
Share on other sites

 Share

×
×
  • Create New...