Thread: assembly language...the best tool for game programming?

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    167

    assembly language...the best tool for game programming?

    While reading some of the tricks andre lamothe suggests that we keep in mind when developing games it seemed like assembly language would be the ideal tool for developing games. For instance he suggests that c++ should be used sparingly I guess because of the performace loss of using a lot of objects with multiple inheritance etc. He also seems to be fond of using global variables instead of passing parameters on the stack. Assembly language would be useful in this case because function parameters can be passed through registers. Another trick he mentioned was using the left and right shift operators to do multiplication and division. It seems like he likes to use C as an assembly language of sorts and I guess thats why C is sometimes called a mid level or high level assembly language. I understand the usefulness of a high level assembly language when a program is being written with portablility in mind but if a game is being written for windows only or for one specific platform wouldn't it just be better to use assembly instead of trying to emulate it with a high level language.
    And in addition to this I think that having the instruction set of a particular processor at your disposal allows the programmer to be more expressive in the implementation of algorithms leading to sometimes a better implementation whether better means shorter or faster or both. A lot of people question whether or not assembly is a suitable development tool today but i think game programming may just be one area where it's a perfect fit. What do you guys think?
    silk.odyssey

  2. #2
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    I think you don't have much experience programming in assembly. Trying to code and entire game in pure assembly would be.... unimaginable. It's too many lines of code, and too complex a process.

    In modern game programming, the game is coded in a high level language such as C. However, they still revert to embedding assembly right into the code for situations where it is necessary to be fast and efficient as possible (graphic pipelines, hardware interaction, etc).
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    167
    Pure assembly may be too much but I think masm or HLA or any other "high level assembler" would be nice for game programming because especially with HLA the language it allows you to code as low or as high as you would like to. You can use high or low level features where appropriate.
    silk.odyssey

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    i dont think you understand, maybe you should read some assembler src code

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    high level assembly language
    No such monster except for HLA which I don't use.

    Assembly can be used for extremely fast copy operations - basically bitblt's from one surface to another. Multi-texturing can be done this way, and using MMX, can also be alpha blended as well if, and only if there are no hardware resources available to do this. Often times the resources are quite limited so this happens more than you think.

    But coding an entire DirectX or OpenGL game in assembly, well....................let's just say you and I wouldn't be playing any games developed in this century on our systems.

  6. #6
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by silk.odyssey
    For instance he suggests that c++ should be used sparingly I guess because of the performace loss of using a lot of objects with multiple inheritance etc.
    Neglible 99% of the time. The advantages more than outweigh that.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  7. #7
    Banned
    Join Date
    May 2004
    Posts
    129
    I agree with what Sang-Drax said.

    LaMothe is correct in saying that there is a performance loss with the mentioned C++ functionality (and it is definitely not negligible if you are trying to implement some 'real' 3D graphics stuff, such as an elegant shader system).

    However, why do you 'pay' for anything? You pay for stuff because you can get something out of it. Subsequently, you 'pay' for elegance and ease of implementation with a cost of a slight speed hit.

    The best example for C++ is using std::vectors instead of writing your own linked list...people use them all of the time because they're so easy if you just want to dynamically add objects to an array, and then access them later (although they have other problems).

  8. #8
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    The usage of basic assembler code in your program leads to alot of code readability/reusabilty problems. Basically, if you want to learn assembler, I totally support you, because it is a great way to understand the higher languages. However, if you want to use assembler in a game, use SSE/2 extensions for stuff where you need the extra speed of the faster instructions, but dont like how the compiler uses them(compilers as of yet from what I have seen still dont like to properly write assembler for SSE instructions), but dont use them for the entire game.

    P.S. I am not sure about my last clause, since IIRC it took people only around 2 years to code 1 mil+ assembler line games and I think that with the advent of full scale APIs for graphics/audio , 1 mil might be the most necessary today for most games.

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by vNvNation
    I agree with what Sang-Drax said.
    i agree too, although his numbers are a little off.... it's more like 99.99% of the time.

  10. #10
    Code Ripper
    Join Date
    Jun 2004
    Posts
    30

    100% asm game

    hi,

    there's a game being written 100% in asm. Hostile Encounter is called.

    Its a RTS game(a la starcraft) made using TASM.

    www.hostileencounter.com

    jmgk

  11. #11
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    well if you are going to make a game in complete asm, it's all about subroutines, subroutines, subroutines....use them freely...or else you would die...
    My Website

    "Circular logic is good because it is."

  12. #12
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I dont see how this is possible since TASM operates in real mode and can only use EMM386.EXE to access 32MB or XMS via int2Fh in pure DOS only.

    TASM is also not compatible with DJGPP or RHIDE (they claim it is but I've never had any success). TASM32 runs in 32-bit mode but TASM does not support newer opcodes for MMX/SSE(1/2) etc AFAIK.

    I could write a game in TASM but there is no point. The speed gained would be quite marginal compared to the structure lost. Anyone on this board can attest to the fact that I'm an avid x86 assembly language crusader so I'm not against assembly and I use it a lot in places where it might be needed

    Most code bogs down in about 10% of the entire program and yet most people try to optimize the the 90% that's not the bottleneck.

    Optimizing 90% of your code but leaving the 10% bottleneck will still result in slow code be it in:
    • assembly (x86 rocks!!)
    • C++ (bring it on!!!)
    • Java (omg i hope not)
    • Visual Basic (I just puked on myself)
    • BASIC (sorry can't insult my first love and first language ever)
    • COBOL (CO what?)
    • FORTRAN (fortunately no one has tried)
    • PHP (isn't that some kind of drug??)
    • Python (I don't even have to say it do I?).


    I included some of the scripting languages simply because there are some here who are under the false assumption that a real-time game can be programmed using them. Here's your sign.



    I could, however, see a game being programmed in C/C++ with core engine routines in NASM.....but on its best day it would still be 10 times slower than Direct3D or OpenGL.

    Hardware acceleration is here to stay. Live by it or die by it. Your choice.

    Just go learn DirectX or OpenGL....it makes life a lot easier.
    Last edited by VirtualAce; 06-17-2004 at 07:55 AM.

  13. #13
    ---
    Join Date
    May 2004
    Posts
    1,379
    >I included some of the scripting languages simply because there are some here who are under the false assumption that a real-time game can be programmed using them. Here's your sign.

    I KNEW IT!!
    people didnt believe me!

  14. #14
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    I could, however, see a game being programmed in C/C++ with core engine routines in NASM.....but on its best day it would still be 10 times slower than Direct3D or OpenGL.

    Hardware acceleration is here to stay. Live by it or die by it. Your choice.
    how do you feel about matrical and quaternion operations, which are infamous for being very slow when sent to the FPU instead of SSE(1/2) registers(I have seen code that is 10x-25x as fast as C equivalent from a few people over at www.gamedev.net)? Because unless I forgot a white paper, I didnt realize GPU's were being used for those kinds of math?

  15. #15
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Quote Originally Posted by Bubba
    I dont see how this is possible since TASM operates in real mode and can only use EMM386.EXE to access 32MB or XMS via int2Fh in pure DOS only.

    TASM is also not compatible with DJGPP or RHIDE (they claim it is but I've never had any success). TASM32 runs in 32-bit mode but TASM does not support newer opcodes for MMX/SSE(1/2) etc AFAIK.

    I could write a game in TASM but there is no point. The speed gained would be quite marginal compared to the structure lost. Anyone on this board can attest to the fact that I'm an avid x86 assembly language crusader so I'm not against assembly and I use it a lot in places where it might be needed

    Most code bogs down in about 10% of the entire program and yet most people try to optimize the the 90% that's not the bottleneck.

    Optimizing 90% of your code but leaving the 10% bottleneck will still result in slow code be it in:
    • assembly (x86 rocks!!)
    • C++ (bring it on!!!)
    • Java (omg i hope not)
    • Visual Basic (I just puked on myself)
    • BASIC (sorry can't insult my first love and first language ever)
    • COBOL (CO what?)
    • FORTRAN (fortunately no one has tried)
    • PHP (isn't that some kind of drug??)
    • Python (I don't even have to say it do I?).


    I included some of the scripting languages simply because there are some here who are under the false assumption that a real-time game can be programmed using them. Here's your sign.

    Sigh, bubba I really wish you hadn't said that.

    Because, and mainly for the reason, that you can code a real time game in scripting langauges. JavaScript is a scrippting language, and it is QUITE possible to do real time games with it. It wont be doom, but it will be a game, in real time. This is especially true when you consider browser plugins that interact with javascript. Such as wild tangent (www.wildtangent.com). Wild tangent is a 3d graphic api for browsers. It can be used in java, javascript, vb script, and c++.

    Any ways the point is, your conception is wrong here. If if I absolutely must, I will program a game in pure javascript (with out wild tangent or any other plugin) to prove the point. But you will owe me something.. Perhaps a very verbose humbling apolagy.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Learning Assembly
    By mrafcho001 in forum Tech Board
    Replies: 5
    Last Post: 03-12-2006, 05:00 PM
  2. Language of choice after C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 06-15-2004, 01:20 AM
  3. Assembly Help PLease!
    By Tleggo in forum C Programming
    Replies: 2
    Last Post: 05-24-2002, 03:29 PM
  4. C,C++,Perl,Java
    By brusli in forum C Programming
    Replies: 9
    Last Post: 12-31-2001, 03:35 AM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM