Examples of DirectX/OpenGL in assembler?

04e602bef725ed5f82d95a00d16aa57c
0
Unknown 101 Nov 22, 2005 at 22:03

Hello anybody. I am from Ukraine, please, forgive me for mistakes. Who can to give me some links with tutorials: DirectX or OpenGL in assembler. I trying to write small 3D game in assembler, but can’t find real perfectly tutorial. Who understand that, please answer. Thank you.:worthy:

19 Replies

Please log in or register to post a reply.

6f0a333c785da81d479a0f58c2ccb203
0
monjardin 102 Nov 22, 2005 at 22:22

Good luck finding one! Since you mentioned DirectX, I’ll take it you are using Windows on an x86?

Here is a good starter that gets you through making a window:

http://www.acm.uiuc.edu/sigwin/old/workshops/winasmtut.pdf
http://webster.cs.ucr.edu/

If you are that far, then you can figure out how to call the OpenGL C API from assembly. Just follow any C/C++ language tutorials. I’m sure calling DirectX is an even bigger mess.

6f0a333c785da81d479a0f58c2ccb203
0
monjardin 102 Nov 22, 2005 at 22:28

Well I’ll be a monkey’s uncle! I found one:

http://www.cfxweb.net/modules.php?name=News&file=article&sid=1922

They even show you how to push the parameters onto the call stack.

04e602bef725ed5f82d95a00d16aa57c
0
Unknown 101 Nov 23, 2005 at 10:58

Thank you for links. Where you are find this? I’m finding in http://www.rambler.ru and in http://www.google.ru but it’s no result! I told ya, that find it in ru-net no real :(
And, do you have an ICQ number? I want to talk with you.

6f0a333c785da81d479a0f58c2ccb203
0
monjardin 102 Nov 23, 2005 at 13:25

I found those links with www.google.com, but I’ve seen the first two before and knew where to look. The link in the second post was found with this query:

http://www.google.com/search?hl=en&q=OpenGL-assembly-programming
I didn’t search for DirectX examples.
I don’t use ICQ, but you can private message me on this forum.

6aa952514ff4e5439df1e9e6d337b864
0
roel 101 Nov 23, 2005 at 17:11

Do you have a good reason for programming in assembler? I used to code in assembler too, just because i thought that it was cool, but later i realized that coding things fully in assembler is a real waste of time. So maybe you can reconsider your choice :) (and save some time)

2b97deded6213469bcd87b65cce5d014
0
Mihail121 102 Nov 23, 2005 at 17:14

I believe the most nehe tutorials have ASM ports. Go and check ‘em out:

nehe

04e602bef725ed5f82d95a00d16aa57c
0
Unknown 101 Nov 23, 2005 at 21:41

I do not want to change my choose, because I realized half of my engine in assembler (it’s working!). I know C, I know Visual Basic, I know Pascal, I know many languages and some years ago I write my programs in one, but assembler is most quickly and most easy for me. I created my personal site in ru-net for this theme ( http://justasm.narod.ru ) and don’t want to change my programming language. It’s just too few examples with source code using OpenGL and DirectX. Also interesting how to work with OpenAL library (to play .ogg songs)

D07934a90668e88866d5ac8b3529f686
0
Luminion 101 Nov 25, 2005 at 04:10

I don’t think nehe has anything on assembly.

46462f88a1670d7e9cbbfa360aa20134
0
juhnu 101 Nov 25, 2005 at 04:34

@Unknown

I do not want to change my choose, because I realized half of my engine in assembler (it’s working!). I know C, I know Visual Basic, I know Pascal, I know many languages and some years ago I write my programs in one, but assembler is most quickly and most easy for me.

Can’t really believe this!

..but I guess its a better reason than the usual “I get better performance by writing in asm”-type of comments ;)

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Nov 25, 2005 at 12:54

@Unknown

I do not want to change my choose, because I realized half of my engine in assembler (it’s working!). I know C, I know Visual Basic, I know Pascal, I know many languages and some years ago I write my programs in one, but assembler is most quickly and most easy for me. I created my personal site in ru-net for this theme ( http://justasm.narod.ru ) and don’t want to change my programming language. It’s just too few examples with source code using OpenGL and DirectX. Also interesting how to work with OpenAL library (to play .ogg songs)

With all due respect, if you really knew assembly you would have no problem using OpenGL and/or DirectX. :blush:

Knowing assembly is very useful in game development, but actually writing whole modules in it is pointless. I highly recommend you to learn an object-oriented language like C++. It allows to better structure your software, write readable complex algorithms, and it helps you greatly to write correct code.

E0613df9e198a3ebbad23b02b714eb42
0
ikk 101 Nov 25, 2005 at 14:11

@Nick

[…]but actually writing whole modules in it is pointless. […]

sorry, but i dont agree. it would be very good for performance if some of critical application sections be written in assembly (sorting for example).
writing in asm gives direct access to registers, thus while sorting single registers could be used as pointers and resource usage could be totally minimized.
im myself consider to create few modules in asm for my app and then call its functions from c code (modules in termns of .dll, .lib)
However, i agree with rest of your post Nick. some time ago I also moved fom asm to c and it was very easy :)

A9102969e779768e6f0b8cb87e864c94
0
dave_ 101 Nov 25, 2005 at 15:55

@ikk

sorry, but i dont agree. it would be very good for performance if some of critical application sections be written in assembly (sorting for example).
writing in asm gives direct access to registers, thus while sorting single registers could be used as pointers and resource usage could be totally minimized.
im myself consider to create few modules in asm for my app and then call its functions from c code (modules in termns of .dll, .lib)
However, i agree with rest of your post Nick. some time ago I also moved fom asm to c and it was very easy :)

At the risk of starting a flame war, I disagree with you and agree with nick. If you know assembly and C++ you should be able to write C++ to produce the desired instructions. The only time I’d ever write assembly stuff is if I was doing bytecode level stuff or OS boot-strapping/device interface.

Access to the low level details is a bad thing IMO. The hardware is quite different to the x86 architecture, an opitmising compiler can do it better than you in 90% of the cases. Do you know how the CPU will resequence instructions to achieve parallelism? There are far more than 8 registers in a p4.

Appart from the trivial case of I write code to work on my machine, architectures can vary and asm reduces portability and compatability.

Back to the original subject
If you can do asm, surely its just a simple matter of calling the DX/OpenGL functions? :wacko:

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Nov 25, 2005 at 17:06

@ikk

sorry, but i dont agree. it would be very good for performance if some of critical application sections be written in assembly (sorting for example).

Sure, but I don’t really consider that a ‘module’, as in a real building block of an application. It would be more like writing independent utility functions and grouping them in a library. For this coding in assembly certainly has advantages. But even then, most of these utility libraries already exist, and there’s hardly any need to write them again (except maybe as an excercise).

Other functions can be worth writing in assembly as well, if they are performance critical and can make use of MMX or SSE (all multimedia applications in general). But that’s again just a couple functions and it can be inlined in C++ (no need for a .asm file). Hardly worth calling a module.

I hope that clarified my point of view. :happy:

99f6aeec9715bb034bba93ba2a7eb360
0
Nick 102 Nov 25, 2005 at 17:36

@dave_

At the risk of starting a flame war, I disagree with you and agree with nick. If you know assembly and C++ you should be able to write C++ to produce the desired instructions. The only time I’d ever write assembly stuff is if I was doing bytecode level stuff or OS boot-strapping/device interface.

Actually I disagree a bit. :lol: Even the best compiler is not capable of always generating the optimized assembly code you desire. The problem is that optimizations are almost always done on the entire code. A super optimizing compiler would take forever to create the fastest code, and your executable could be much bigger. Only the programmer knows which functions need special attention for optimal performance, and with assembly it’s easy to guarantee the results.

Access to the low level details is a bad thing IMO. The hardware is quite different to the x86 architecture, an opitmising compiler can do it better than you in 90% of the cases. Do you know how the CPU will resequence instructions to achieve parallelism? There are far more than 8 registers in a p4.

This is not true for multimedia applications. You wouldn’t be able to play a DVD on your computer if it didn’t use hand-optimized MMX routines (except with hardware acceleration). Sometimes it’s simply necessary to use assembly to access architecture specific features. It has to be rewritten for other architectures, but that’s only a small amount of work if you only optimize the few functions that really need these low-level optimizations.

Furthermore, a bit of knowledge on CPU architectures helps a lot to write faster code than a compiler, even for plain 32-bit integer code. It’s true that the Pentium 4 has more than 8 registers, but it’s the C++ compiler that is much more limited in using them to the fullest than most experienced assembly programmers. Almost no compiler uses MMX or SSE, and if they do, they are very bad at it.

Appart from the trivial case of I write code to work on my machine, architectures can vary and asm reduces portability and compatability.

Absolutely true, but it’s often quite manageable if you’re careful. Many applications are only written for one platform. I for one have never worked on anything but x86 systems (except some exotic machines at university). So if you let your C++ compiler only generate x86 assembly, there’s nothing wrong with having a few x86 assembly routines. For multimedia applications, only a couple functions are really performance critical, so it pays off to write them in assembly even if you have to do it for a few architectures.

Anyway, writing logic modules in assembly, that’s a waste of time. Every language, from 1st generation to 5th generation, has its purpose. Just use them wisely.

E0613df9e198a3ebbad23b02b714eb42
0
ikk 101 Nov 25, 2005 at 19:04

there is this saying: “if u want something to be done good, do it yourself!”.
i dont always believe that something what is said to be optimized, is optimized good enough for some special case. sure, it can be optimized for hundred cases simultaneously and for mine too, but its not optimized enough when i need only two 32-bit registers and 1KB of memory.

A9102969e779768e6f0b8cb87e864c94
0
dave_ 101 Nov 26, 2005 at 00:31

@Nick
I agree with what you’re saying. I just wasnt quite consise enough with my post, I didnt make exceptions for architecture extensions, SIMD, etc. Although personally I’m happy to use instrinsics in my code (as long as I can see the code generated).

I’m just trying to say that you really only need to use assembler in less than 1%* of your code. And for those less than expert**, writing code better than well written C++ and the compiler (excluding architecture extensions) is nearly impossible.

*number plucked from my posterior

**looking at your work, you might just be one of that type

2b97deded6213469bcd87b65cce5d014
0
Mihail121 102 Nov 26, 2005 at 10:37

You may need assembler in only 1% of your actual code but that’s no reason not to use it in the other 99%. My work for example is maily done using C and ASM and I feel great. I always liked the simplicity of the code and I find it great to know what is actually going on. For the things I do (mobile and system programming) that’s even the most important thing.

Anyway people are different and therefore they like different things. We can’t judge them for their choice, as long as they’re happy with it!

04e602bef725ed5f82d95a00d16aa57c
0
Unknown 101 Nov 26, 2005 at 17:19

Ok, I maybe will write in C. But, one second, where I can download this? My computer has attack by hackers and was injured by viruses. I decided to format all local disks, and now I haven’t anything. Help me, please. I have no money to buy that from official site… :(

6f0a333c785da81d479a0f58c2ccb203
0
monjardin 102 Nov 26, 2005 at 19:12

There are plenty of free compilers. If you are using Windows, MS just released VC++ 2005 Express for free.