#### Archived

This topic is now archived and is closed to further replies.

# ASM Question

This topic is 5709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, when I asked some people about learning ASM for optimizing games they told me it wasn't worth it since most compilers will optimize it alot better anyway, however they also said that it would be good to know to give a better understanding of how the CPU works. Now, i've decided to learn it but the problem is, there are different versions for each CPU isn't there? So how do you write ASM code which is portable? i.e. would work on both Intel and AMD processors. Also, which version of ASM is best to learn and why? [edited by - notme on November 22, 2002 3:25:38 AM]

##### Share on other sites
good compilers (vc++,cygwin etc) can do such good job, that it is not neccessary to optimise it with asm. on the other hand sometimes (at the "time-critical" parts of the program) asm routine would be very helpful.
and according to assembly language itself, it''s not so "confusable" as you thing. intel and amd CPUs (of a same platform, of course) are in fact [backward] compatible everything but some hi-end areas (like 3dNow! @ amd, not implementable on intel cpus or so). there are some norms and standards of how x86 architecture should look like i strongly hope ;]
but - first you need to learn the basics

quote:
Original post by notme
Hi, when I asked some people about learning ASM for optimizing games they told me it wasn''t worth it since most compilers will optimize it alot better anyway, however they also said that it would be good to know to give a better understanding of how the CPU works.

Now, i''ve decided to learn it but the problem is, there are different versions for each CPU isn''t there? So how do you write ASM code which is portable? i.e. would work on both Intel and AMD processors.

Also, which version of ASM is best to learn and why?

[edited by - notme on November 22, 2002 3:25:38 AM]

##### Share on other sites
For the most part, if you’re making games for windows, you''ll want to learn x86 assembly. These are the instructions that been around pretty much ever since Intel came about.

As for writing portable code, assembly is by its very nature very platform specific. However, if it''s just Intel/AMD compatibility your concerned about it''s not hard. AMD''s chips are Intel-compatible meaning that understand (almost) all of the Intel instruction set. Just avoid anything that both don''t support (mostly new extensions like MMX and 3Dnow); thankfully both Intel and AMD have very good documentation so it’s pretty easy to see how well a given instruction is.

There are more complex ways to make the code portable, but if your just starting out this works fine.

- Zhypoh!

##### Share on other sites
I''ve been asking these kinds of questions for the past week and I''ve got some pretty good answers from people on this forum and at experts exchange.

AMD and Intel processors both have the same 8086 instruction set, the FPU and MMX instruction set. They differ when it comes to the packed floating point extensions. So you don''t need to worry about portability if you are just working with the basic instruction set (that''s the instruction set as it was before the Pentium with MMX and the Pentium 2 came out)

According to a guy on experts-exchange, the use of these extensions is only a concern for driver and OS developers. And that if you want to use them in your games, you''re better off with C++ libraries.

I''ve been told the same thing a number of times now: Learning assembler is becoming rarer and rarer and you are better off getting your program performance by learning how to write better C++ and learning good program design.

But like you, I am being told that it is useful to understand assembler just for the bit of underlying theory. If that''s the case, they mean just get to the stage where you can write a simple assembly algorithm with the 8086 basic instruction set, just so you can appreciate how your program is executed.

The best assembly book I found was Kip R Irvine''s "Assembly for Intel based computers" and that really got me sorted with being able to write assembly programs in Windows. But after that I would recommend getting Intel''s Software Developer''s manuals from their website. Manual 1 gives you a lot of descriptions on the architecture of the Pentium 4 which should cover a lot of theory that you are being recommended to know.

##### Share on other sites
Just revised a few more things.

I''ve been told that since the majority of the 3D graphics workload is on the hardware nowadays, the need for efficient assembly is much less.

If you plan to go into AI, you should NOT be learning assembler because it is difficult enough as it is.

It will be useful to learn an assembly language to be able to use the assembly languages of the new graphics cards (I don''t know if these are the same as the shader languages). You will be able to learn them quicker if you are already familiar with general assembly language, but again, that should mean that once you can get a basic algorithm written in assembler, you probably know enough. And learning these shader languages is something you only want to look into once you''re proficient with DX or OpenGL.

Probably best not to take anything you hear as gospel, because I''ve been getting a huge mix of opinions on this subject.

And I thought I knew just about all I needed of C++ and programming till I started reading posts on this board and looking at other people''s code. Now I''ve got a better idea of how far I''ve got to go and so that is my focus at the moment. Learning everything there is to know of assembler is only something I would be prepared to start if I''m being told it is very important to do so.

##### Share on other sites
Hi ... I'm an Assembler programmer ...

Very interesting subject ... this is the first time I've been to this community and this is the first thread I've ever read!

I'm a member of a community of Assembler programmers much like this community ...
http://board.win32asmcommunity.net/
if any of you are interested to see ... ask any questions ... they will help you !!!

I'm not here to "convert the heathens" as some Assembler programmers would say ... but I'd like to give you some constructive advice/information and a few good links if you are interested to see what assembler is all about!

I would like to start of by clearing some misconceptions about 32bit Assembler programming for Windows OS:
1) We can do ANYTHING a C/C++ programmer can do. Including creating an EXE or DLL, COM, ODBC, DirectX, WinSock, in fact ANY API call in Windows etc.
2) I have NEVER written Assembler code that runs slower than a C compiler ever since I started with Assembler ... to me ... the notion that a C compiler can produce faster code is a lie! For example, I have converted a few C string manipulation functions to assembler and gained an average of 15% speed increase ... and those are supposed to be "optimized" and I had only known Assembler for 1 month!
3) "Assembler is dead" is a lie Micro$oft and others want most programmers to believe! The truth is that Assembler will never die ... it cannot! To justify my statement, did you know if you have Visual C 6/.NET etc. ... you also have Assembler (Not only inline assembler but full Assembler). VC now has more support and documentation than ever on inline Assembler in MSDN. The "full" Assembler files are ML.EXE and LINK.EXE. The assembler that ships with .NET is the latest version of Assembler for 95->XP. 4) Amazing that the most powerful compiler (VB/VC etc.) from Micro$oft is available for free ... immagine that! You can download Assembler for free from Micro$oft! 5) If you can read Assembler, you can disassemble other people's EXE's and DLL's to find out how they did something or do what I do ... dissassemble my C programs to see how the compiler assembled it ... then change my C source code and recompile For the ultimate speed results from a C compiler !!! 6) You will find ways of doing things unthought of to C programmers ... when you start thinking Assember ... you will start think binary Some awesome optimizations can be made when working like this ... 7) If you understand Assembler ... C and all other languages will be a piece of cake ... and you will start understanding what's happening "behind the scenes" !!! You can do so much more in Assembler ! Now with that out the way ... I would like to give you some links to the Assembler community! A MUST read HTML tutorial on Assembler basics ... http://www.madwizard.org/view.php?page=tutorials.contents This is a MUST have for every Assembler programmer! Download and install ... plenty of examples, ML.EXE and LINK.EXE, DisAssembler and a few good tutorials! Run QEdit (Basic Editor) to Disassemble EXE's and DLL's http://www.masm32.com/ The best ASM RAD environment for you to program in with color coded ASM syntax, relies on the above package ... http://radasm.sonshinesoftware.com/ Loads of excellect tutorials and example code! http://win32asm.cjb.net/ DirectX tutors and examples http://www.scrontsoft.com/win32asmdefault.asp If you wanna see what a 100% Assembler game is made of ! http://hostileencounter.com/ I wish you all the best of luck and hope this helps if you want to get started on Assembler ... remember ... it's never too late In the assembler community we talk of HOP (Hardware orientated programming) ... the best programs will be written by those who understand the hardware ... and contratry to popular belief ... it ISN'T hard !!! Do not fear or judge what you do not understand ... Let me end of with this, you may have thought from my post that I've been working in Assembler all my life ... ain't so ... only 6 months ... and you too could be doing things a C programmer can only dream of ... ask a professional C & VB programmer like me ! We hide in the shadows ... [edited by - SubEvil on November 22, 2002 6:30:46 AM] #### Share this post ##### Link to post ##### Share on other sites Freak ... sorry ... just wanted to add something ... My friend just bought a P4 1.7Ghz with a GeForce4 and 256MB RAM. He also just bought the new Unreal Tournament ... and his PC jerks ??? What the heck is that all about ??? What's going to happen when Doom3 comes out ??? And now you guys want to rely on the C compilers to do your job ... a C compiler will never replace Assembler ... even inline Assembler is better people ... you have the best of both world here ... you can have inline Assembler which is exactly the same syntax and everything as we have ... in Assembler we don't get inline C ... Do yourselve's a favour ... spend a month or 2 fiddling around with Assembler ... you won't regret it and you can only make the world a better place ! Oh ... and I just want to remind you ... my recomendation is to learn Assembler with C ... for spead of writing source code ... use C ... for speed of source code execution ... use Assembler ! We hide in the shadows ... [edited by - SubEvil on November 22, 2002 6:34:41 AM] #### Share this post ##### Link to post ##### Share on other sites quote: I''ve been told the same thing a number of times now: Learning assembler is becoming rarer and rarer and you are better off getting your program performance by learning how to write better C++ and learning good program design. That''s hard to do without a good grasp of how the underlying hardware works. Reading some blurbs on computer architecture and "optimization tips" isn''t going to help much. To really learn what''s going on, you have to learn assembly language and know it well. --- Bart #### Share this post ##### Link to post ##### Share on other sites I''ve neither got a good grasp of programming design or assembler. But I''m trying to direct my studying towards what''s being recommended, and I''m being told that that is C++. They''re saying that efficiency is best gotten at the high levels. I might be interpreting that completely the wrong way. Maybe they are just saying that a crap overall program design is going to cause far more of a performance loss than not using assembler. But at the moment my program design is pretty piss poor and so I think that needs to be my main focus. Question is then, how feasible is it to be a proficient C++ programmer, a proficient assembly language programmer, a proficient DirectX programmer and keep up with all the latest theory on your chosen specialisation all at once? People are posting lots of stuff and not backing it up very well, I guess because it isn''t very easy to explain these things in a single post. And I get the feeling that a lot of posts are coming from people who aren''t, as yet, game''s developers (if I''m wrong, sorry). But, to back up your point, can you give us an example of a situation where, to produce the best C code, you need to know the assembler that it is going to be compiled to? Cheers #### Share this post ##### Link to post ##### Share on other sites quote: Original post by SubEvil I would like to start of by clearing some misconceptions about 32bit Assembler programming for Windows OS: 1) We can do ANYTHING a C/C++ programmer can do. Including creating an EXE or DLL, COM, ODBC, DirectX, WinSock, in fact ANY API call in Windows etc. I'm not aware of such a misconception. Everyone knows that asm allows you to achieve the same ends as other languages, albeit via a different set of syntactic constructs. For instance, all you have to do to call an API function is stuff the function arguments onto the stack (or into registers, or some combination thereof) according to the exported linkage protocol, and invoke the function. Amazingly, the APIs you're talking about are mostly written using C. quote: 2) I have NEVER written Assembler code that runs slower than a C compiler ever since I started with Assembler ... to me ... the notion that a C compiler can produce faster code is a lie! Can produce faster code than what? quote: For example, I have converted a few C string manipulation functions to assembler and gained an average of 15% speed increase ... and those are supposed to be "optimized" and I had only known Assembler for 1 month! The benefit of using tools is not apparent for trivialities. It's a bit like OO design heuristics. When you sit in your bedroom writing programs of 1,000 lines, design technique has little impact. However, when you have to develop s/w that ends up being a million lines of code, it makes a difference. The claim that you have never written an assembly program that runs slower than a C equivalent doesn't imply what you think it does. quote: 3) "Assembler is dead" is a lie Micro$oft and others want most programmers to believe! The truth is that Assembler will never die ... it cannot!

That's true. The bit will never die, either. By the way, why do you spell "Microsoft" with a dollar sign? Do you also refer to Bill Gates as "Mister Big Poopy Pants"? It's incredibly childish.
quote:

To justify my statement, did you know if you have Visual C 6/.NET etc. ... you also have Assembler (Not only inline assembler but full Assembler).

Yup. You get a lot of bits for free with it too.
quote:

If you can read Assembler, you can disassemble other people's EXE's and DLL's to find out how they did something

No you can't. Compilation is a lossy transformation. You can see the end result, but won't have a clue how they achieved it. It's a bit like listening to Beethoven. Sure, Symphony 7 sounds great, but you'll never know *how* he wrote it.
quote:

6) You will find ways of doing things unthought of to C programmers ... when you start thinking Assember ... you will start think binary

Why stop there? I think about sub-atomic physics when I write my programs.
quote:

If you understand Assembler ... C and all other languages will be a piece of cake ...

That's either a lie or an amazing piece of ignorance.
quote:

Let me end of with this, you may have thought from my post that I've been working in Assembler all my life ... ain't so ... only 6 months ... and you too could be doing things a C programmer can only dream of ...

Like hanging around the office all weekend to get your string manipulation functions working?

[edited by - SabreMan on November 22, 2002 4:45:32 PM]

##### Share on other sites

This topic is 5709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

This topic is now closed to further replies.

1. 1
Rutin
25
2. 2
JoeJ
20
3. 3
4. 4
5. 5

• 9
• 9
• 46
• 41
• 23
• ### Forum Statistics

• Total Topics
631749
• Total Posts
3002054
×