Welcome to the Shroomery Message Board! You are experiencing a small sample of what the site has to offer. Please login or register to post messages and view our exclusive members-only content. You'll gain access to additional forums, file attachments, board customizations, encrypted private messages, and much more!
Why is optimized assembly language code the fastest programming language? Anyone know? I'm thinking it's because the code is simple and directly related to how the computer functions. Furthermore, the language doesn't hog memory and executed quickly and efficiently. Anymore guesses?
Do you want a guess, or do you want to know the real reason? I will assume the later.
A computer executes machine code. Machine code is simply a sequence of numbers. These numbers mean something to the machine (hence the name). They tell the machine to load values into memory, or to move stuff around, or to add things, etc. Regardless of what language is used to write a program, in order for the computer to execute the program, the program must be translated into machine code.
Assembly language is a human readable form of machine code. On the x86, the machine code instructions "0xCD 0x20" are the exact same as the assembly instructions "int 20h" (call interrupt 20 hex). An assembler is used to translate assembly into machine code.
Higher level languages, such as C++, use a compiler to translate the C++ code into assembly, then use the assembly to translate the assembly into machine code. A handful of lines of C++ can result in hundreds of lines of assembly.
The compiler does the best job it can to optimize the assembly it generates. This is a very complex procedure. The compiler has to map the needs of the program into the limited resources of the computer.
The reason hand written assembly is often faster than compiler generated assembly is because humans are better at mapping the needs of the program into the limited resources of the computer than a compiler is. We have a better picture of what the program is doing, how it will behave, etc.
Modern compilers have gotten very good at optimizing and CPU designs have gotten much better as well. It is very difficult to write assembly code that out performs a compiler on most modern systems. In the old days, the benefit of hand coded assembly could be massive, but today it is mostly a waste of time.
One particular place where hand coded assembly still pays off is when working with specialized instruction sets, such as SSE on the x86. The SSE instructions are used to do common mathmatical operations seen in video (and audio) compression. If you write a program to decode mpeg, the compiler is going to use regular ALU instructions rather than the special SSE instructions. If you want to use the SSE instructions, you will have to write the assembly by hand.
-------------------- Just another spore in the wind.
You cannot start new topics / You cannot reply to topics HTML is disabled / BBCode is enabled
Moderator: Lana, trendal, automan 456 topic views. 0 members, 5 guests and 2 web crawlers are browsing this forum.
[ Toggle Favorite | Print Topic | Stats ]