views:

677

answers:

3

Does anyone have documentation pertaining to learning the fundamentals of Linux x86-64 assembly? I'm not sure whether or not to learn it as is, or to learn x86 first, and learn it later, but being as I have an x86-64 computer and not an x86, I was thinking of learning x86-64 instead ;)

Maybe someone could give me some incentive, and direction as to learning what, how, and with what documentation.

Kindly give me your most favoured documentation titles, I code a little Python, this is my first attempt at a lower level language, and I'm more than ready to dedicate to it.

Thanks all

+1  A: 

Take a look here it's the best place for Linux Assembly development, you will find resources, docs and links.

Nathan Campos
A: 

The canonical reference to x86 is probably the Intel® 64 and IA-32 Architectures Software Developer's Manual. I've still got a couple volumes of this series, back from when the PIII was new. There's an AMD64 Architecture Programmer’s Manual too, which might be interesting because Intel did not completely follow AMD's lead in x86-64 design, but I haven't read it.

X86 Opcode and Instruction Reference is exactly as advertised: x86(-64) opcodes and instructions and nothing else. Handy if you want to search for some particular instruction real quick.

ephemient
The Intel documentation is a bad place to start learning assembler.
drhirsch
I think it's an excellent place to start learning assembler. It's very, very thorough.
ephemient
drhirsch
It's where I started. Granted, I had a little experience with 68000 assembly before, and knew how to use `gcc`, and I puzzled out the differences between AT-)
ephemient
"Looking at objectcode" is actually a good advice for learning assembler ;-) Having some real world code for comparison teaches you a lot. Code examples are really lacking in the Intel reference. And even with assembler coding practice I had trouble figuring out what the more obscure sse instructions are good for, because they only make sense in conjunction with other sse instructions. And of course there is no mentioning which ones. The AMD documentation is better in this regard.
drhirsch
+1  A: 

General advice:

It isn't just "x86 assembler". Each assembler is a bit different and they are not generally compatible with each other. I recommend the NASM assembler because it is widely used, easy to install, and supports 64bit assembly.

Read a good book on x86 assembler to get a feel for the basics (registers, conditional jumps, arithmetic, etc). I read Art of Assembly by Randall Hyde when I was starting out.

http://asm.sourceforge.net looks like it has some good tutorials that you might want to work through. But if you are assembling in 64bit mode, beware that the calling convention for C functions and syscalls is different.

You will need the CPU reference manuals. Personally, I prefer the AMD ones. You want volumes 1 and 3 of the CPU manual. The other volumes might be of interest as well.

64bit specific advice

64bit x86 assembly is almost the same as 32bit x86 assembly, since 64bit x86 is mostly backwards compatible with 32bit. You get access to the 64bit registers and a few other features, some obscure instructions are no longer valid, and the rest is the same as 32bit.

However, the syscall convention is completely different on 64bit Linux. Depending on your kernel, the 32bit syscalls may or may not be available. What's worse is that the 64bit calling convention is poorly documented. I only figured it out by examining the depths of the glibc source code.

To save you the hassle of finding this out the hard way, The syscall numbers are in the Linux source code under arch/x86/include/asm/unistd_64.h. The syscall number is passed in the rax register. The parameters are in rdi, rsi, rdx, r10, r8, r9. The call is invoked with the "syscall" instruction. The syscall overwrites the rcx register. The return is in rax.

Callum
Another possible basic assembly book is _Assembly Lanuage: Step by Step, 3rd ed._ by Jeff Duntemann which focuses on x86-32 on Linux using NASM, and this 3rd edition was published in 2010. Randall Hyde also has a very informative web site _Art of Assembly_ http://www.ArtOfAssembly.com/
mctylr