when do you use assembly?

Started by
25 comments, last by ValMan 16 years, 11 months ago
Hi, after spending much time writing my game in c++, I decided to learn how to write in assembly, since many books/sites said it would be a helpful co-language. I was wondering where and how often does assembly comes into play in game development. I've seen a few example where chunks are thrown in c++ code within _asm{} and even that only used standard mov, push, pop to get the job done. Is it always limited to that in game dev community or is there a broader range where it's used. It would be nice to hear from someone who is professionally involved in the game dev business and how they use assembly in their jobs, Thanks, Tim.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Advertisement
Almost always only to optimize super low level things: matrix multiply, vector operations, etc. It's basically the last ditch optimization effort when all algorithmic options have been exhausted.

It's also very helpful for debugging in release. In release the debugger always lies, but the assembly never does. So jumping to assembly mode can tell you where you actually are in the callstack, show you which variables are in which registers so you can debug them in the watch window, etc.

-me
The most ASM I've ever used on a project was a GBC game, so I didn't have much choice. Day to day, I use it very rarely. I use it in a release-mode assert macro to cause an interupt, and I read it when debugging release-mode only bugs, but that's about it.

[Edited by - Driv3MeFar on May 4, 2007 4:22:55 PM]
You almost never write code in assembly on PC. The closest you tend to get is using intrinsics for things like SSE.

However, knowing assembly to the extent that you can read it can be helpful. It gives you a better knowledge of what's happening under the hood, and it can occasionally be useful when solving some problems. I've faced bugs before that only appear when the optimizer is turned on, and being able to look at the optimized code and see how it corresponds to my original source was instrumental in figuring out what was happening.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Assembly should only be used when neccessary, and no more.

Assembly may be used for checking processor-specific features (SSE,SSE2,
3dNow!,etc), and for some optomizing. Note that if you use assembly, you should
always, if possible, provide a C++ alternitave as not to break portability.

Assembly is useually used in systems programming, not as much in game
development.

I second learning how to read assembly, as it can be very usefull in debugging.
in the days of the first 3D games, ASM was used quite often especially for the renderer, i belive the source for quake uses it extensivly. but now a days compilers are usually good enough at optimizing code on their own.
-----------------------------------------------The ZoloProject
Quote:Original post by speedie
in the days of the first 3D games, ASM was used quite often especially for the renderer, i belive the source for quake uses it extensivly. but now a days compilers are usually good enough at optimizing code on their own.


The reason it isn't used for the renderer is not that compilers are better at optimizing (which they probably are), but that we don't use software renderers anymore now that we have GPUs
Best regards, Omid
We use assembly to extend the C++ programming language. We've stolen a few concepts from LISP and integrated it in a post-build step to patch the executable. This allows us to use concepts that aren't easily or effeciently done using the language natively.

Most simulation systems and rendering systems at our company are optimized in assembly. We've always pushed the console to its max so we typically don't have any spare cpu cycles.
Graphics Programmer - Ready At Dawn Studios
Quote:I second learning how to read assembly, as it can be very usefull in debugging.

I'll 'third' that one. It's a rare debugging session when I don't have to drop into assembly. Visual Studio seems to be horrible about debugging release code. It's also useful for determing exactly what if statements are doing, and which call is returning which value. I've several large scenarios that I can't run in debug mode because it's way too slow, and debugging them in release mode can be 'interesting.'

--
Ralph Trickey
TOAW III Programmer

Thanks for the replies, so basically everyone is saying that assembly is almost dead in games, except for debuggin purposes. I think that overall, the language is becoming extinct as a main production language, the only places it seems to be usefull is in boot-sectors for OSs and console games. I still plan on learning it though, for me it seems so much easier than high-level langauges, mainly because i now know about everything that the computer does and how it does it. I don't know why schools don't teach this as a first and primary langauge. When students know that processesor takes a certain amount of commands, and these command are represented with 1s and 0s, so when a prossessor sees 1001 coming at it knows it needs to ADD the next two varibales, I think that explains it so much better than the way high level langs are teaching us.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

This topic is closed to new replies.

Advertisement