24
votes

I've always wanted to learn assembly, but there seems to be a jungle of assembly-related information out there that is difficult to interpret. I haven't just been able to google "learn assembly" and get going.

First, there are two types of syntax: Intel and AT&T. What's the difference? Why are there still two in use? When would I need to use one versus the other?

Second, there's a multitude of chips out there. Intel vs AMD, 32-bit versus 64-bit, x86 vs other architectures... even x86 is really a whole family of chips. So, how can I know whether the assembly I'm learning from a certain web page will work for my machine?

There exist even more variations (operating system even plays a role in determining how code will run.

So, the big question is, with all these variables, how can I know what type I should learn? What's most common? How is it possible for people to "know assembly" when there are all of these variations?

11
I suggest you learn one which is support by your CPU, so that you can practice it; so to start with, know what type of CPU you have. After you've done that, you may find more than one assembler which can emit assembly for your CPU; then choose the assembler in the same way that you might choose a compiler.ChrisW
Assembly language is an interesting thing: in concept, it's simple to learn since most instructions are very easy to understand. The trick is piecing it all together and making all code paths work correctly. You learn to be very careful when writing assembly, since debugging it requires a lot of effort.doug65536
Knowing assembly is knowing how to write a loop, an if statement and things like that. It is the same in all assembly languages (pretty much) just like it is the same in all high level languages (but is different from assembly to high level). The particular version of assembly needs a manual to get right!dave

11 Answers

14
votes

First, there are two types of syntax: Intel and AT&T. What's the difference?

The main differences are superficial: reversed operands, for example.

Why are there still two in use? When would I need to use one versus the other?

Intel uses a syntax that is a major departure from the syntax that virtually all other processor ISA documents use.

GNU as uses AT&T syntax for all platforms, and supports Intel syntax for x86 and x86_64.

Other assemblers (like NASM, MASM, etc.) use Intel syntax exclusively.

So, how can I know whether the assembly I'm learning from a certain web page will work for my machine?

It's documented in the processor manuals from Intel and AMD. Sandpile is also a good resource.

So, the big question is, with all these variables, how can I know what type I should learn? What's most common?

The most widely-supported would be Pentium-pro class, so-called 'i686', and K8-class (referred to as 'x86_64' or 'amd64' or 'EM64T'). The variations from there are whether MMX or SSE or its variations are supported. Look up the CPUID instruction - it will provide you with support information for the processor you're running on.

How is it possible for people to "know assembly" when there are all of these variations?

I don't think anyone "knows" x86. Everyone who needs to has a copy of the processor manuals.

8
votes

The whole point of assembly is that you're coding by directly using the CPUs basic instruction set. Since different CPUs have different instruction sets, they are all different. However, once you know one "assembly" and get the basic ideas, switching from one instruction set to another is relatively simple.

I would suggest starting with 80386 assembly - it's supported by pretty much any PC you can find but doesn't have too many extensions to confuse someone just starting out.

5
votes

What type should you learn? That depends on what you want to do with it. Are you interested in learning more about your PC? Are you interested in embedded programming? Make sure you've got some way of executing your code. You probably want to learn the x86 series, but it isn't the easiest to learn. Way back when, I thought the easiest to learn was the Radio Shack Color Computer with the manual they sold.

The most common depends on what you want to do. There's a lot of x86-based chips out there in general-purpose computers, but many more chips in more specialized roles, such as smart phones and embedded systems.

You don't know assembly by learning every assembly language in the world. You know it by knowing one or two well enough to get all the important ideas, and after that it's largely a manner of learning new computer architectures.

2
votes

Realistically, most developers don't need to know assembly language these days. However, it's useful to know the concepts behind assembly (machine architecture, registers, memory, etc.). For that, learn one CPU and that's all you need.

Check out http://www.grc.com/smgassembly.htm - Steve Gibson is one of the few developers actively writing applications in assembly these days, and he has a wealth of resources on his site.

2
votes

I remember reading an introductory book on x86 assembly by (I think) Peter Norton. The book walks a beginner through the process of creating a full screen hard disk editor for MS-DOS. This is the best way to learn, because you get the full experience of the low-level hardware that goes into the x86 architecture and can apply that knowledge to other CPUs as well. Less useful is the knowledge of DOS interrupts, but still interesting.

2
votes

I once read Jeff Duntenmann's excellent "Assembly Language - Step by Step" a long time ago. It's probably the only book on 80x86 assembler for beginners that I've ever seen, and it's a very good one. A lot of stuff in it is somewhat out of date, I suppose, but programming in assembler on x86 itself is pretty passe for most things nowadays. But if you're looking to get started and you want a foundation, I think his book is where you want to be.

2
votes

I found x86 assembly not so easy to learn as a first assembler. The msp430 is really easy. There are more ARM processors than 80x86 in the world so it is not a bad platform to start with and it is an easy one to learn, an okay number of registers and other than pc and stack no special registers they all perform the same tasks equally. I learned the lsi/pdp11 first (nope, not quite that old) and it was so simple and straight forward that it really did make learning any other easy. It was the assembler that the C language was derived from. Not sure where you would learn, the msp430 is not far removed and is available.

The question changed after I wrote this. The big answer is first learning to program, but this I suspect you already know and is not specific to assembler. Second learning to perform those programming steps by breaking it down into register loads and stores and alu type operations. Understanding interrupts and their impact, an interrupt can occur between any two instruction, you have to preserve the state of the machine, the registers and flags, etc. Some processors do most of this for you so you may need to try a few different ones to understand the complexity. Interrupts and interrupt services routines are advanced, just being able to break your task into small simple operations usually register based would qualify as programming in assembly.

2
votes

As has been mentioned, find an assembler you like that supports your hardware and learn it. There are many choices, not all of which are Intel or AMD. A number of embedded systems use other chips including the venerable 680x0 series.

As for knowing all of assembly, does any one know all of any programming language? Does anyone know all of the dot net API? You know a small core section of any programming language very well, a bit more you can use, but maybe don't fully comprehend, and much large selection you know a little bit about, but have to refer to the manual, and there is an unknown amount about which you know nothing at all.

Even the ancient 6502 had dozens of operands and addressing methods. You learn what you need to do the job. The more jobs you do the more you learn.

1
votes

It's quite hard to tell which assembly is "most useful" unless you choose platform you want to use.

If you go for PC (intel, amd) start with x86 assembly. There is a common instruction set for different CPUs + some technology specific instructions like SSE. If you want to develop for Windows have a look at MASM, for Unix FASM would be a good choice.

1
votes

do you wanna be a windows hacker? learn x86. do you wanna be an embedded guy? go buy a DSP trainer chip and learn that.

1
votes

FAsm

Comes as an executable for Windows ready to run out of the box; decompress its archive and have at it from the command line. Linux version is similar coming as a compiled ELF executable while the BSD/Unix version comes as an object file that you compile with your native C compiler and done -ready to rollout your assembler code. Currently, work is underway to develop an almost vm assembler evolving FAsm that will also include native support for ARM chips as well.

IDEs supporting FAsm include WinAsm Studio with FAsm plugins titled WAFasm by Shoorick packaged in an archive that, once decompressed, is ready to run immediately. There is also Fresh IDE built with and targeting FAsm by an independent developer and FAsm forum member (John Found) and many other alternatives.

FAsm supports COFF, 32 & 64bit PE as well as ELF for Linux and FreeBSD in both .exe & .dll/linked libraries file formats. It provides macro support as well as headers following its format. For a complete listing of executable file formats supported by FAsm check out the official web site because there are many.

FAsm is now just around 20 years old and it's still just over 1 megabyte in size.

FAsm has a pretty large user forum addressing topics regarding all the platforms it serves as well as topics ranging from openGL to developing homebrew PNG image transparency systems and GUI applications -pretty awesome stuff.

Highly recommended.

Remember that assembler, contrary to idiot speculation, will never die because every compiler has to do the same -just a friendly FYI --compile, link, assemble ... right?

Thread may be a bit aged, but the topic is still relevant and on this note in closing enjoy!