tags:

views:

330

answers:

10

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?

+5  A: 

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.

Tal Pressman
A: 

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.

aku
I would also recommend looking at NASM and GAS for cross platform use.
bcat
A: 

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.

TrueWill
+5  A: 

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 form 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.

greyfade
+1  A: 

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.

dwelch
I found x86 assembly not so easy to learn as a fifth or sixth assembler. There's something about the modes that makes my brain not want to get involved.
David Thornley
A: 

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.

Mark A. Nicolosi
A: 

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.

Dave Markle
A: 

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.

Dustin Getz
A: 

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.

Jim C
+2  A: 

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.

David Thornley