Sign in to follow this  
RedKMan

Assembly Programming - Where To Start

Recommended Posts

Hey, Decided to have a tinker with assembly programming. Just done a bit of googling and come up with all sorts. What is the best type of assembly to learn, X86, my processor is an AMD Athlon XP2200+? Also what is the best and easiest to use IDE/assembler to use for free download? Also can anyone recommend any useful resources /books? Any help much appreciated. Thanks,

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by RedKMan
Hey,

Decided to have a tinker with assembly programming. Just done a bit of googling and come up with all sorts. What is the best type of assembly to learn, X86, my processor is an AMD Athlon XP2200+? Also what is the best and easiest to use IDE/assembler to use for free download? Also can anyone recommend any useful resources /books?

Any help much appreciated.


Check out the following two forums that are dedicated to assembly language programming:

http://www.asmcommunity.net/board/
http://www.masmforum.com/simple/index.php

You will find that both forums feature FAQ threads and plenty of further resources (articles, links, free IDEs etc.).

Depending on your actual motivation for learning x86asm, as well as your long term development plans (platform, OS, type of applications), you will find that there are different IDEs and assembler that can be recommended. So, it is hard to recommend anything without knowing more about your goals.
If you are interested in doing primarily Win32 development in assembly language, you will probably want to check out MASM, that's the Microsoft assembler which is also used by VC++, alternatively there are also HLA and NASM and FASM. There are dozens of more assemblers, however basically these are the most powerful/widely-used ones.
If you are interested in possibly doing development for different platforms or OS, I would personally recommend to check out NASM, which can also be used as backend for gcc.
Nevertheless MASM and HLA are incredibly powerful solutions that can easily hide the dirty details from a beginner due to their powerful macros.

So, it really boils down to what exactly you want to do, and why you want to learn assembly language.



Share this post


Link to post
Share on other sites
Hey,

Thanks for the info, NASM looks the right way to go. I'll probably be crossing between Windows and Linux. I'm also going to have a look at MASM as I read it's a good idea to learn a couple. As for my goals, pretty much graphics programming initially.

Thanks,

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by RedKMan
Hey,

Thanks for the info, NASM looks the right way to go. I'll probably be crossing between Windows and Linux. I'm also going to have a look at MASM as I read it's a good idea to learn a couple. As for my goals, pretty much graphics programming initially.

Thanks,


Yes, NASM is definitely the right choice if you are not going to do merely Win32 development, much of your code can easily be portable across Win32/Linux if you keep things generic enough (i.e. OS depedencies).

Concerning MASM, well it's awesome-especially for programmers coming from a HLL background, it's really addicting-it's pretty much like MS's VC++ IDE: when you have used it for a while you are going to miss lots of (hand holding) stuff when you have to work without it (i.e. under Linux).
Nevertheless it's also very Win32-specific and -centric, so much of the high level macro stuff will be hardly applicable on non-Win32 platforms.
And it is definitely a good idea to look into different assemblers, this will be the only way to really pick your favorite one. Also, it really doesn't matter all that much what assembler you use initially, because most of the required low level knowledge (i.e. CPU instruction sets, registers etc.) is generally transferable between different assemblers.

Regarding graphics programming: it is important to keep in mind that most of the really "cool stuff" is nowadays handled using backends such as OpenGL or DirectX.
So, if you are hoping to do such graphics programming in assembly, DirectX would not be a feasible option if you are interested in running your stuff directly under Linux.
Also, many of the available graphics demos are in fact Win32-specific.

On the other hand, under Linux you can easily use an emulator to run assembled stuff for arbitrary architectures.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by RedKMan
Hey,

Thanks for the info, NASM looks the right way to go. I'll probably be crossing between Windows and Linux.


You may however find that the syntax between different assemblers may differ significantly, likewise there's Intel syntax and AT&T syntax for assembly language (check out google for further references), INTEL syntax seems initally less complex than AT&T, however the latter is usually perceived as much more intuitive. It's also the syntax that's natively used by the GNU assembler (gas) used by GCC.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Make sure to also check out GameDev.net's resource section about asm:
http://www.gamedev.net/reference/list.asp?categoryid=20#105

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by freenity
check this book out:
http://www.drpaulcarter.com/pcasm/


Yes, and this:

http://en.wikibooks.org/wiki/X86_Assembly

Syntax Comparisons:
http://en.wikibooks.org/wiki/X86_Assembly#Section_2:_Syntaxes_and_Assemblers

Lists of popular assemblers:
http://en.wikipedia.org/wiki/List_of_assemblers
http://en.wikibooks.org/wiki/X86_Assembly/x86_Assemblers
http://en.wikibooks.org/wiki/Reverse_Engineering/Assemblers


Details for various popular assemblers:
http://en.wikipedia.org/wiki/MASM
http://en.wikipedia.org/wiki/NASM
http://en.wikipedia.org/wiki/High_Level_Assembly
http://en.wikipedia.org/wiki/GNU_Assembler
http://en.wikipedia.org/wiki/FASM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Regarding the use of a macro/high level assembler to get started programming in assembly language:

Quote:
http://c2.com/cgi/wiki?LearningAssemblyLanguage
Does learning assembly language with one of the "high level assemblers" ( http://en.wikipedia.org/wiki/High-level_assembler ) teach a student everything he needs to know about modern assembly language programming (minus now-irrelevant historical cruft), or is there some reason to use traditional-style A86 or NASM or the GNU assembler ?

Quote:
http://c2.com/cgi/wiki?LearningAssemblyLanguageFor instruction, there is every reason (when possible) to use only traditional low-level assemblers, although high level assemblers are highly desirable for real world use.

The only reason to teach assembly language to students at all in this day and age, is as a part of the overall process of teaching them how CPUs actually get things done. If they don't need to understand the workings of CPUs, then they don't need to study any sort of assembly language at all. But if they do need to understand CPUs, then high level constructs will only obscure their understanding of what is happening at the low level.

For pedagogical purposes, at the low level, it is valuable to understand the cost of general purpose versus dedicated-purpose registers, the difficulty of allocating registers for data calculations and address references, the number of instructions required to do 128-bit arithmetic on a 32-bit CPU, what high level control constructs (IF/WHILE/FOR/SWITCH) look like when translated to assembler, etc.

For real world use, on the other hand, sometimes one needs to escape to assembly for performance reasons or to access hardware resources/capabilities not accessible from a high level language, in which case the entire purpose is different, and it's desirable to have as many high level constructs as possible, as options.

So to answer the original narrowly phrased question, "Does learning assembly language with one of the 'high level assemblers' teach a student everything he needs to know about modern assembly language programming", clearly the answer is "absolutely not, in the general case". But in other cases, it depends. A future Java programmer may not "need" to know as much on the same topic. It's a bit ambiguous.

The top universities world-wide have had a fairly general answer to all such things for a very long time, though; they will tell you they are not trade schools, and that understanding of underlying theory is what is important to them. They therefore tend to teach such things "the hard way", for the best of reasons, given their goals. -- DougMerritt


In other words, you will probably really want to make sure that you start out with the basics, rather than the high level stuff because you'll otherwise mainly be learning the specifics of the corresponding high level assembler. Unlike the high level support, the low level support is usually applicable 1:1 across different assemblers, often even on similar platforms/architectures.

In fact, under Win32 I would even recommend to also use an emulator for learning assembly language by default, too.

Mainly because Win32 is not a particularly forgiving OS when fooling around with low level stuff, meaning you are not that unlikely to possibly manage to crash your OS or seriously affect it when playing around with assembly language.

Thus, using an emulator such as "bochs" would enable you to safely try out all sorts of stuff that you probably wouldn't want to run directly on your system, i.e. out of fear to affect your system's performance or stability.

So, using an emulator is generally a pretty good idea and will also allow you to do things that you normally wouldn't want to do (in fact, about 10 yrs ago I actually managed to make my harddrive unusable by corrupting its FAT when writing in assembly language...).
Of course, an emulator may probably not really be an option if you really intend to get started in Win32 assembly programming directly, simply because this would otherwise entail installing and running Win32 within the emulator, too.

Also, there are plenty of x86 assembly tutorials out there that start out by illustrating various DOS- or even BIOS-based examples, i.e. in order to illustrate the processor architecture and familiarize with the various registers and their purpose. While you won't want to dig too deeply into this, if you mainly want to do Win32 programming in assembly, the background knowledge is nevertheless still useful and usually also directly applicable.

For example, check out the following site which provides a basic introduction to x86 assembly using MS DOS debug.com utility to create your utilities: http://www.oopweb.com/Assembly/Documents/asm/VolumeFrames.html
(you could be set up for this course within 5-10 minutes by simply getting bochs with a FreeDOS image, which includes a port of the debug.com utility).

Anyway, the folks over at the assembly forums will probably also have lots of useful feedback!

Share this post


Link to post
Share on other sites
Very insightful, I did not pause and think that I could frack up my system by messing around with asm. The emulation method sounds like the smart way to go about this.

Thanks,

Share this post


Link to post
Share on other sites
Quote:
I did not pause and think that I could frack up my system by messing around with asm


You can mess it up just as much as you could with say a C++ program, as it's still the same machine code running on the same machine. Modern operating system (such as windows) use the protection features of the x86 architecture so you won't be able to directly access hardware, write to memory however you want etc. The potential for screwing things up is pretty much exactly the same as it is for any other language. Using an emulator seems pretty pointless IMO.

Quote:
in fact, about 10 yrs ago I actually managed to make my harddrive unusable by corrupting its FAT when writing in assembly language...


You can play with the FAT in pretty much any language provided you have the API calls available, screwing up the FAT doesn't happen because you're using asm, it happens because you wrote your code wrong which you can do in any language.

Quote:
Mainly because Win32 is not a particularly forgiving OS when fooling around with low level stuff, meaning you are not that unlikely to possibly manage to crash your OS or seriously affect it when playing around with assembly language.


As I stated above programs written in assembly are subject to the same protection mechanisms programs written in any other language are, there's nothing special about asm that makes it easy to bring down your OS or screw it up in some way. If you can do it easily in asm, you can do it easily in another language as well.

Share this post


Link to post
Share on other sites
Thats calmed my nerves, thanks. I've done some pretty dumb stuff with C++ and my computer still lives.

One thing which came up, how do I avoid going HLA? I want to stay as low level asm as possible. Can I still use NASM and FASM and just turn off any macros which do the nitty gritty stuff for you?

Share this post


Link to post
Share on other sites
i would like to tinker around doing some programming for the NES. i have looked at the documentation for this and i believe they used a Motorola 68000 or something close to that.

looking through the code just to add a 8x8 pixel image in assembly really makes you appreciate high level languages and high end API's like OpenGL. i cant imagine what the code for a game like Mega Man for the NES, would look like. thousands upon thousands of code.. these were the hdefinition of the hard core programmers to me...no cutting corners there.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by RedKMan
Thats calmed my nerves, thanks. I've done some pretty dumb stuff with C++ and my computer still lives.

without trying to scare you, but it is definitely easier to do "dumb stuff" in asm than in C++, simply because it is much more low level and doesn't necessarily require any sort of explicit APIs to get access otherwise unavailable resources/functionality.

Quote:
Original post by RedKManOne thing which came up, how do I avoid going HLA? I want to stay as low level asm as possible. Can I still use NASM and FASM and just turn off any macros which do the nitty gritty stuff for you?


don't worry too much about HLL macros in NASM or FASM, if you don't use such macros you won't learn to depend on them. There are many good tutorials out there, and it will be made quite clear which assembly insructions are in fact low level INSTRUCTIONS, and which ones are assembler-specific macros/extensions. Likewise, if you check out an IA32 asm manual, there won't be any word about assembler-specific stuff!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by OpenGL_Guru
i would like to tinker around doing some programming for the NES. i have looked at the documentation for this and i believe they used a Motorola 68000 or something close to that.

Do you really want to to assembly programming, or are you generally looking for a way to run your stuff on the NES? If it's mainly the latter, why don't you simply use a cross compiler (such as i.e. gcc) to compile HLL sources to your specific platform/architecture?


Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
without trying to scare you, but it is definitely easier to do "dumb stuff" in asm than in C++, simply because it is much more low level and doesn't necessarily require any sort of explicit APIs to get access otherwise unavailable resources/functionality.


That's not true. If you're writing assembly programs to run under Windows, they will run with exactly the same protection mechanisms in place as with any C++ program. If you're writing assembly to run under DOS, however, it is certainly possible to mess up your system by doing "dumb stuff", but it is also possible in C++ under DOS.

In other words, don't worry about messing anything up, it's no more likely to happen in assembly than in C++.

Quote:

i would like to tinker around doing some programming for the NES. i have looked at the documentation for this and i believe they used a Motorola 68000 or something close to that.


The NES used a 6502. You can get lots of infomation on this chip at 6502.org. There also appears to be a C compiler here.

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