Should I learn assembly?

Started by
11 comments, last by Narciss 22 years, 6 months ago
How much benefit would one have in learning assembly language on top of C for 3D applications or games? I have done a few basic operations with IBM hex but that''s about it.. I understand that it is a very hard language to learn, but if it''s worth it I''m all for it.
Advertisement
If you have a very strong knowledge of c, I don''t believe that assembly would be terribly hard. It is worth it to learn assembly even if you don''t know if you will use it, because you will definitely change your mind once you know it. I would also check out the assembly for Pentiums 3 and 4 because visual c++6 was made before optimizations were made for these. After you learn assembly you may only use it as in-line or as linked in modules for your c programs. Assembly will always speed things up, but I don''t even know every bit about the knew architectures that would make significantly greater differences.

note: Always remember to look at your algorithms before going to assembly. You may be doing a step or an order of magnitude that wastes more time than all the garbage you see in compiled c programs.
I think asm will be choice for the fun and for smalls executables size.

Now there is too many instruction and too good compilator too know to make a code really faster than C++

Why English rules?? C pas très malin tout ça!
_______________
Jester, studient programmerThe Jester Home in French
I honestly think that every programmer should know the basics of assembly. Not only does it make you programs faster, but you begin to realize what goes into that if { } else { }, or for{;;} statement. Once you get to that point, you start to become a better HLL programmer too. You start seeing the difference between i++ and ++i, etc. Then, if you keep at it, you can go that extra step sometimes and write a few algorithms in ASM. Besides, it''s not all that hard to learn. Just try some stuff out in a sort of int main() { __asm { } return 0 } block. Have fun with it!

Z.
______________"Evil is Loud"
Oh, and just because we have good optimizing compilers doesnt make ASM obsolete. The computer can never optimize a compilcated algorithm to the fastest possible assembly, because it doesnt know what you are trying to do. Also, a compiler can only optimize for processors that were created before it was, so as stated above, MSVC cannot optimize for the best code on a P3 or 4. A good assembly programmer can almost always produce better code then the computer.

Z.
______________"Evil is Loud"
Assembly does have it benifits - SPEED. The first time I really noticed it was back in the days of DOS. At the time I was coding in Turbo Pascal writing fire routines (palette index 0-255 is nicely faded throug white-yellow-orange-black, the for each pixel on the screen take the average of all the pixels around it an write that value one pixel above the current pixel, then draw some random pixels at the bottom of the screen to fire it off ) Anyway I could only get a fire to burn about a 1/4 of the screen width (res was 320x200) and it was very slow!

Enter asm:
A friend of mine told me to write it in asm but I didn''t think I would be able to do it and I hadn''t written any asm before, but after thinking about it for a minute or two I realised it wasn''t that hard so I went to my computer. Result = blazing fullscreen fire with plenty of spare time for extras

Latest ASM project:
In the processing of building remote switch for a set of to computer which can decode messages on a serial line with out a UART using a 16F84 PIC (Obviously it PIC assembly not 8086 so the is less opcodes but the ideas pretty much the same)

The idea of assembly is simple but you have to write alot of it and one you have a fair bit of it it can get a bit hard to follow, I RECKON ITS WORTH LEARNING EVEN IF YOU NEVER USE IT because it give you a better understanding of whats going on

Hope you enjoyed my story
X2K
Just to make you even more confident in using asm (I''ve got nothing to do now either ), read:

extreme2K used that fire story in DOS and Turbo Pascal etc. I was in exactly the same position! Though no friend told me to use asm, I learnt it, rewrote my routine and *GEEZ*, the fire was burning like mad!

You also say that no compiler can optimize a code snippet as we humans can. They don''t care about compatibility either, only the current system.

Asm can speedup your programs A LOT! I wrote an X library in C and asm. C was used for the usual stuff, like keypress checking etc. But using C in convertion routines between color-depths and putpixels? No way! Sure, I should use OpenGL, that''s what I''m doing now...

You also learn much about the computer. Fun stuff like function names are really pointers to code-blocks in the memory. This can be used for the compatibility-issue (assignment between different code-blocks to suit a function, such as a putpixel).

Ah, that''s enough for you. My last words are:

LEARN ASM!!!
------------
Making a better effort than the compiler using hand optimized assembly code is not an easy task nowadays, and even if it was, saving a tiny amount of clock cycles here and there will probably not do any noticable speed gain.

First of, you have to be very careful with the order of instructions since the pentium processors and later has dual pipelined execution. You have to be as good as the compiler (or better which was the main idea) to follow the pairing rules or else the processor will suffer a 1-5 clock penalty for each miss.

However, I do encourage you to learn assembly since you at least will know what''s actually going in the system. Then you''ll know what the bottlenecks are and how you can avoid them (minimizing branch predictions, not blowing up the L1/L2 cache etc). And there are still some cases when hardcore assembly is the only way to go, like taking advantage of SSE/SSE2/3DNow instructions. (Altough, it''s possible to do it in plain C now that Microsoft has released their new processor pack).

/McFly

Years ago, I spent a lot of time learning assembly. So what happens? About a year and a half ago I got hired by a commercial game development house; my big break into the industry. And you know what? There isn''t a single line of asm in the whole codebase :-)

Still, I don''t at all consider learning the language wasted time. In the course of figuring out assembly you end up with a tremendous understanding of how it all really works, some of which you can apply even if you write everything in C++.

I think, for the most part, if you''re going to be writing games in OpenGL or DirectX, asm is not so useful. However, it''s definitely great for you to learn because it gives you not only a great appreciation for those wonderful compilers we have out there, but it also gives you a better understanding (as was previously stated) of what exactly happens in what seems like the most trivial operations. Plus, it''s great for debugging. At work we give programs to QA that are usually built in release mode since that''s how we''re going to ship it out. It''s nice to be able to go straight into the code''s disassembly and use it to figure out roughly where you are, with no debug symbols, and determine why your code has crashed
More importantly, however, I think learning how to write efficient algorithms is a better tool than simply using assembly. This, just like assembly, requires lots and lots of reading and practice
Good luck in your endeavors


-------------------
"Pointer?????"
-Anonymous

-=Xelius=-
-------------------"Pointer?" -Anonymous-=Xelius=-

This topic is closed to new replies.

Advertisement