Sign in to follow this  
Mech_Master

C++ or ASSEMBLY?

Recommended Posts

JOL    160
For what ?
A a lot of IO and networking maybe Java.
For a large reusable and fast app C++.
For a embedded system maybe ASM or C
and so forth ...

Share this post


Link to post
Share on other sites
nmi    978
Which is the problem you want to solve ??

Anyways, if you can you should stick with C++, use assembly only in cases where it is necessary (i.e. if you write a boot sector).

If speed matters, optimize your algorithm first and MEASURE the time.

Share this post


Link to post
Share on other sites
Mech_Master    109
Oh so sorry.Im in the planing for a computer game and was wondering if we make a game in C++ or Assembly,wish one would give us more performance?Or we should use them both or C++ alone or Assembly alone?For the best performance.


Thanx alot

Share this post


Link to post
Share on other sites
darookie    1441
No programming language will give you more performance just by preferring it over another one. Most of the game performance comes from good data structures and algorithms. Selecting a programming language is merely a matter of personal taste and experience. If you are good at assembly programming - go ahead and code your game in it. Otherwise you should use the language that you know best.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Pure assembly should give you higher performance if you know what your doing.

Most modern C++ compilers will optimise just as well as a assembly programmer in the majority of cases.

I wouldn't even bother with assembly programming unless it was something so low level that you absolutely had to use it (i.e. bootstrap code), or having to access video interrupts etc (even then I'd just have inline asm).

Share this post


Link to post
Share on other sites
Andrew Russell    1394
Not assembly. Use C++.

Unless you are a very, very tallented assembly coder, you won't be faster than C++ And talented or not, development will take 10 times as long if you use assembly.

If you need to have a small section of code in assembly, you'll know this when you come to it, and you'll be able to insert the assembly into the C++ program.

And as was said - don't start with assembly. Write it all in C++ first, and then use assembly if you've profiled your application and you know you absolutly need it (and then profile again, so you know if your assembly is faster or slower).

Share this post


Link to post
Share on other sites
cignox1    735
From your post I suppose that you don't know them, and want to know the differences to be able to choose what language to study. Well, I don't know assembly very well, but I really suggest you to study C++ for the following reasons (supposing that you are going to make common apps, no drivers-embedded-...):

Speed- ASM is potentially faster, because it let you to have control over every single instruction and memory usage. In addition, most compilers aren't able to take full advantage from the lastest CPU intructions (SSE/SSE2 and so on) because, IIRC some of them need a special setup of the code to be fully used (i.e. an instruction can be executed on many vars at the same time). But, and that is very important, compilers generate in most cases a code faster than what everyone but very experts can do, so the only way one can obtain ASM code faster than C++ one is to know ASM (and algorithms) very, very, very well.

Portability- C++ is, as a language, portable. ASM doesn't. That is, plain c++ code can be sucefully compiled on each system whit a standard compliant c++ compiler. Assembly instructions are different from a CPU to another and even from a OS to another there are differences in the programming rules (I mean interface with the OS and other, but I'm not an expert).

Easy to study- ASM is not difficult to study. Some people think that it is actually easer than C++.

Easy to use- Once you know the languages, I think that programming in C++ is a lot easer (and faster) than ASM, expecially for todays applications (like GUIs, net based applications, databases).

C/C++ is in my opinion a must for every programmer. There aren't, always IMHO, other languages as important as C/C++, aven if you will use other languages at work (or for yourself). So my suggestion is: learn C++ anyway, and then go into ASM, if you like.

edit: oh, I waited too much to anwer: others have already said that. So you're gonig to make games: well C++ is what you need (unless you want to spend months for even the simplest one). Quake was made in C (something in QuakeC and something in ASM), quake 2 in C++ (or C? don't remember), so Half Life 1/2 and, actually, most games. The only game made entirely in ASM I'm aware of is Roller Coster (don't know wich one) according to what said on another post in this forum.

Share this post


Link to post
Share on other sites
achi-gaki    122
between C++ and assembly well both are important but i'd say c++. reason beign assembly is platform dependent and we know how new hardware is always beign churned at an alarming rate each with new features.

well if you go assembly, think you may have to work extra hard to be update(keeping in mind that assembly is not programmer friendly especially to a novice). c++ on the other hand will just provide you with api's to access the new feature without much effort but only understanding.

in the end, the choice is yours.

Share this post


Link to post
Share on other sites
Thanx alot all.

Can you recommend me some Assembly and C++ books and ill need to know DX too right?So it would be helpful to know wish books to learn from for my goal.

You are right i wanted to see was better to study them cause of what i want to do.I dont know anykind of programming but im willing to learm!

Share this post


Link to post
Share on other sites
Roboguy    794
Quote:
Original post by The3DGameEngineNoob
Thanx alot all.

Can you recommend me some Assembly and C++ books and ill need to know DX too right?
You'll need to know either DX or OpenGL

Share this post


Link to post
Share on other sites
Miserable    606
If you don't know any kind of programming language, I wouldn't even recommend C++. Python (official tutorial, lots of documentation, free book) is a good place to start—it's easier, cleaner, and more elegant, and you will be able to get something interesting running much faster. If you want to use it for games, there is the PyGame library (and when you've come far enough that the speed of the language is an issue, which, I assure you, is at a distant point in the future, you can learn C++ and rewrite parts of a Python program in it.

Share this post


Link to post
Share on other sites
Anri    972
Personally, I would learn C, then C++, and then finally Assembly. Though, I never use Assembly due to its portability issues...keeping C++ in check is bad enough!

Share this post


Link to post
Share on other sites
Ademan555    361
I'd personally opt for c++ over c as a first language just because thats the way i did it and i turned out fine, but c++ (or c) is definitely not the best choice for everyone for their first language, you could even try VB.NET or c#, but i think im going to have to second the vote for python.

hope that helps
-Dan

Share this post


Link to post
Share on other sites
ZedFx    176
assembler! assmebler! go for it. hahaha!

well you could learn c first, to find out about addressing etc, and how your compiler works, then go about optimising the most-used-parts of your program code into asm. (get the reference manuals off the Intel / AMD websites).

Make sure you read: "IA-32 Intel(R) Architecture Software Developer's Manual Volume 1 Basic Architecture" it is the most useful documentation ever on assembler.

and yes, assembler is easier than c++, If you know what your doing.

Best of luck.

Share this post


Link to post
Share on other sites
qazlop    229
only go and learn assembly if you dont want to finish making your first game. Save assembly when you fully understand all the basic algorithms and can code games (yes plural) in c++. You can then think about using assembly for crucial portions of code that might benifit using SSE, SSE2, MMX, 3dNow, etc.

Believe it or not, most games are not too limited by the cpu to the point that assembly would help. Doom3 was written using C++ with very little if any assembly code. Using good algorithms is the key to speed. The same with half-life 2, farcry, and pretty much all modern games since the use of 3d cards.

Most assembly was used for the renderer, not the actual game.

Personally I would go with C++ and directx. I only suggest directx over opengl because directx has consistent interfaces for graphics, sound, and input. opengl only supports graphics. SDL is another alternative that support sound, graphics, and input. You can easily learn any of the 3d apis once you learn one of them.

Assembler is not easier then c++, even if you know what you are doing. Much more time is spent worrying about clean, the stack, registers, etc. In c++, there is less pressure about putting the instructions in the best order to optimize register use, and more on just getting the algorithm right. Assembly is much more diffiuclt for begginers because they tend not to comment code. Code looks very obscure without comments. Higher level languages at least allow varible names that can document the code. Also its easier to see program flow since code takes up much less space on the screen. The code is simply easier to read when you start.

And the best reason to learn c++ instead of assembly. You will get something that works many times faster then assembly. even if you dont care about difficulty, your frustration of finding any information on writing 100% assembly programs for winxp dealing with games will be great. Without any programming background you wont have the expierence to take high level code and write into low level code. Many ppl have trouble writing simple collision detection in c++, now add onto it having to write even more code for it to work in assembly. More code equals graeter chance of typos/errors causing bugs.

Personally i dont see any reason to write any game in assembly. Its only use now would be for speeding up physics, matrix math or other "low level" stuff that coudl take advantage of SSE2, SSE, etc. Though directx has SSE2 optimized code and most video drivers do as well. You use the video card to do the transformations of the vertices, so matrix math is very limited to concatinated a few transformations (and even then directx will combine them using its own optimized code if you use its functions).

in short, c++ if you want to actually create a game. Assembly if you are very curious how computers work, and dont care that you probably wont make a game. Its not to say assembly is bad, its just a poor choice for game development. Especially if you are new to programming. Learning to program can be difficult enough, removing simple constructs like if, switch, etc makes it even harder.

Which seems better to you?

x = x+dx*timeConstant;
y = y+dy*timeConstant;

or

// x = x+dx*timeConstant;
mov ebx, x
mov eax, dx
mov ecx, timeConstant
mul eax, ecx
add eax, ecx
mov x, eax

//y = y+dy*timeConstant;
mov ebx, y
mov eax, dy
mul eax, ecx
add eax, ecx
mov y, eax

Objects and OOP are very good things in game development, trust me on this. Learn C++ first, if you still enjoying making games then go learn assembly. most likly you are young enough you can learn them both and still have time to learn other languages as well.

Share this post


Link to post
Share on other sites
relsoft    255
Unless you'd wan't to do things in pure software, I'd recommend all high level langs(c/c++, basic, pascal) over assembly. Graphics these days are mostly handled in hardware via APIs like GL and DX so making a rotating cube using ASM vs. C++ wouldn't make a difference when it comes to speed. But if you want your game to use something like TinyPTC, go ahead, use ASM. Then again, C/C++ supports inline ASM. :*)

Share this post


Link to post
Share on other sites
Brandon N    354
Quote:
Original post by Mech_Master
Wish one of them is better?I dont mind being harder.And why.
Yes, you will mind which is harder.

I did this in x86 Assembly over the course of about two weeks or so. This was while learning Assembly, but I have significant experience with other languages, so don't expect the same results in such a small period of time. That was an intense two weeks. (Unfortunately no outside libraries were allowed.)

I've done something far superior with networking in Python in 2.5 days, spending about .25 times as many hours per day as when working on the Assembly example (and with frequent breaks).

Also, the Python one runs in both Linux and Windows without alteration, and thanks to its "everything included" ways, things like networking, file i/o etc really feel like a natural part of the language.

Share this post


Link to post
Share on other sites
Hahaha I love threads like these.

Ok ... ok ... Ok I got it. Heres me:

I don't use anything other than assembly language because anything else is just slowing me down. I am currently writing my own OS for my game because I dont want windows to share my resources with other processes. I'll just put my OS on the boot sector of a floppy disk (not CD, because those arent as good as floppy just trust me on this) and then it can execute my game.

Right now I am getting like 900 fps with assembly language, but thats because I haven't been able to code anything. But once I get done I will be at least 750 fps, no way I could do that with a "modern" language like C++ or a shitty timesharing operating system.

Share this post


Link to post
Share on other sites
H_o_p_s    877
You may be getting 900 fps, but how long has it taken you to be able to get this? How many platforms does it support? And you say that there is no way that a language like C++ could compare, but how many people are willing to not have a game boot up in windows? Most people want the system to be the "shitty timesharing operating system" because it is easier for them to use. Increased development time caused by programming in assembly slows me down. And it is just as important to get the project done as it is making it go really fast.

For me the huge amount of time that was spent learning assembly could have been more successfully used in furthering my abilities in the shitty modern languages that you apparently despise so much.

Share this post


Link to post
Share on other sites
Brandon N    354
Quote:
Original post by H_o_p_s
You may be getting 900 fps, but how long has it taken you to be able to get this? How many platforms does it support? And you say that there is no way that a language like C++ could compare, but how many people are willing to not have a game boot up in windows? Most people want the system to be the "shitty timesharing operating system" because it is easier for them to use. Increased development time caused by programming in assembly slows me down. And it is just as important to get the project done as it is making it go really fast.

For me the huge amount of time that was spent learning assembly could have been more successfully used in furthering my abilities in the shitty modern languages that you apparently despise so much.
Ah, a fellow Bostonian.

Anyway, you need to reread his post, specifically:
Quote:
Right now I am getting like 900 fps with assembly language, but thats because I haven't been able to code anything.

[wink]

Share this post


Link to post
Share on other sites
H_o_p_s    877
Quote:
I am currently writing my own OS

This usually means that he has been actually coding. Now, he might not have any game programming done, but this does not negate any of my previous arguments. Assembly has its uses, but those uses do not include complex applications like a 3D game.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this