views:

945

answers:

10

I've been using Python for quite some time now, and I absolutely love the ease of use and flexibility, but I really want to get closer to the hardware for some iter mathematics that I'm working on. I'm also intrigued by being so close to the hardware, with absolutely nothing holding you back from using everything it has.

I've researched for introductions to Assembly and to me they go much faster than they should. They jump straight into registers and operations without explaining what exactly they are, and why they matter.

I'd love to see an in-depth introduction to Assembly, to make sure you understand the concepts before proceeding to any kind of programming with it.

+10  A: 

As others have said, starting with a lower level language like C/C++ is a good start. Familiarize yourself with their features, like pointers, references, bitmasks, etc., and then attempt assembly.

One tutorial I really like is the PC Assembly Tutorial (the zipper PDF can be found here) found here. Until you create and run a simple program, and debug it, it will be difficult to understand assembly.

More importantly, knowing your Von Neumann computer architecture and other background information is extremely important: processor design, memory design, bus architecture, various caches, the binary number system and operations, etc. It is impossible to understand assembly without a solid understanding of the math you are using and the hardware you are programming on, because you are so close to the hardware when programming at that level.

In many cases it's easier to learn on a simpler processor. I learned first on a Java simulator which used a simpler derivative of the x86 instruction set, with fewer registers, then moved up to programming on a Motorola MC68HC12 project board.

Chris
wouldn't C/C++ be a higher level language 0.o?
Ziplin
It is not as high as an interpreted language such as Java or C#. In C/C++ one can even use inline assembly statements. Additionally, sometimes when debugging C/C++ one must look at the disassembly of their own code (either the hex representation of their compiled code, or an assembly interpretation of that hex). All of this makes C/C++ a good first, and then intermediate, step to learning assembler.
Chris
+2  A: 

Personally, I think it's fun to work with assembly on retro computers such as the c64 or Apple II. It's about as bare bones yet functional as you can go. Once you feel comfortable there, you should be able to hop up to x86 assembly.

Daniel Auger
+2  A: 

Aside from the tutorials and references mentioned, I'd suggest getting familiar with C first, as that won't be as big a leap as Python to assembler. C is also as close as you'll get (in performance and hardware proximity) to assembler, with less of a learning curve.

Once you're comfortable with C, get a basic understanding of instructions and registers for your architecture, then run a debugger (GDB on Linux and WinDbg or OllyDebug on Windows) over some basic C apps to see how they run at that level.

The benefits you mention from coding in assembler are somewhat true, but you will experience a lot less pain doing it in C. Like most things, if you code badly in assembly (and no offence, but you probably will as a beginner), it will run slower than a well written C app.

And.. you can always inline assembly in C.

Steve M
+1  A: 

Personally, I think it's fun to work with assembly on retro computers such as the c64 or Apple II.

These architectures also have the advantage of being designed back in the days when assembler was intended for human beings, rather than exclusively for compilers.

Chris Upchurch
+2  A: 

I've attended a course at my university where we wrote MIPS assembly. It's a RISC processor, which makes the human effort a bit more humane. And, truth to be told, it's kind of fun and not all that difficult, once you get the hang of it.

Unfortunately, I can't remember the books we used in that course, but I'm sure Amazon has some good proposals.

Try SPIM as a simulation platform.

Henrik Paul
A: 

@Chris Fournier provided a great answer on how to learn Assembly. I cannot provide anything better that he already did, but some more references:

  • Art of Assembly - this is a great resource for learning assembly
  • Steve Gibson - The man has skills with assembly. He wrote his tool SpinRite in nothing but Assembly. This is a link to some resources he recommends and also some sample programs he wrote in assembly.
Dale Ragan
+1  A: 

Daniel Auger is right.

Depending on your inclination, finding a CP/M Z80 emulator or 6502 Apple ][ emulator is a good bet.

"Back in the day" we all learned assembler, coz it was actually a practical language to use. No cache, no predictive execution, etc. You have a handful of registers, a couple dozen instructions, etc. And a big program (by my standards!) was 8 or 10 kilobytes.

Mark Harrison
+1  A: 

As others have said, starting with a lower level language like C/C++ is a good start. Familiarize yourself with their features, like pointers, references, bitmasks, etc., and then attempt assembly.

This should be the first step. After that you could use a book like Write Great Code, Volume 2: Thinking Low-Level, Writing High-Level. It shows you how high level code is translated by the compiler into assembly.

+1  A: 

Another vote for retrocomputing. My machine code is z80 on the ZX Spectrum.

sparkes
A: 

MIPS, MIPS, MIPS, MIPS, MIPS. That's what I say.

MIPS is the simplest, cleanest, and most elegant instruction set ever devised in my opinion. It's basically "the original RISC." If you have a MIPS-based router or other hackable device, write some code for it.

Another very clean and even simpler architecture is AVR which is an 8-bit architecture used in microcontrollers from Atmel. Very orthogonal and simple to learn and use.

Obviously, if you need to do some specific work in assembly (such as optimizing time-critical code), learn the assembly language for whatever architecture you're using... most likely x86. x86 assembly is powerful, but rather messy.

Dan