views:

850

answers:

6

I am looking for some good resources on x64 assembly on a linux system, in order to write code myself. I am also looking for some introductory notions like memory spaces (stack, heap, etc.). I found a good free book online, Programming From the Ground UP, the trouble is, it is targeted at x32 linux systems. I also played a lot with gcc -S, however it creates some weird symbols like .LAndhwateverstuff Can anyone point me in the right direction? I may be an awfull webseeker, but I could not find many resources on the matter.

+1  A: 

The best way to learn assembly is to look at existing, working assembly (actual assembly, not intrinsics or whatever) and learn how it works. And of course ask questions to those who wrote it. Once you understand how it works, write something similar yourself and keep working on it until its output matches the C code.

My project, x264, for example, has a few tens of thousands of lines of x64 assembly which you can view online through the gitweb interface.

Dark Shikari
Thanks for the link. So you suggest finding an easy assembly project, and writing it from scratch, so that it matches it's brother. I looked at your project, I was looking at something more intro-level, stuff that goes gently into concepts like stack, heap, virtual memory, address modes, etc.
+1  A: 

Some of the stuff you want is called the ABI (Application Binary Interface), which defines function call and system call conventions. You need this in order to write ASM that interfaces with C code or OS system calls.

The other stuff you want to know is the machine instruction set and registers.

AMD has some PDF documents that describe these things for x86_64.

Zan Lynx
I looked at the documents, also checked those at intel's site. I was looking though for something more intro-level. Like that Programming from the ground up book, but optimised for x64.
+1  A: 

I've read Professional Assembly Language and 32/64bit 80x86 Assembly. Both of which would teach you the basics of x86/x86-64, and one of them would at least mention how a C function call is made, and returned, so that could be helpful.

But as Zan mentioned, you probably want to really learn about ABI if you want to write the function in assembly, and have it interface well with C.

Calyth
+1  A: 

http://www.intel.com/products/processor/manuals

nak
+1  A: 

Here you go. http://heather.cs.ucdavis.edu/~matloff/50/LinuxAssembly.html

Oh, and if you need to keep any temporary values or function arguments on the stack† then, except for when you call C functions, you should put them your own stack and not the one in rsp; rbp makes a good data stack pointer. That way you never have to build or destroy a stack frame. Local variables should still go on top of your return address.

Virtually,
Michael Morris.

PS. The auto-preview on this wiki is awesome.

†Which you mostly shouldn't since you have eight extra registers to play with.

Michael Morris
The assembler there seems to be for 32-bit assembler, not 64-bit; am I misunderstanding something?
Jonathan Leffler
My fault, your right. However, it should still be helpful if you combine it with the x64 ABI docs. http://www.x86-64.org/documentation/abi.pdf
Michael Morris
+1  A: 

I don't know if you are familiar with x86 (32bits) assembly. But if you are not, since x86_64 in an extension of x86, you should start with x86. Any x86 assembly code will run x86_64 machine since the instruction set has been design to be compatible. x86 is complicated enough, and you won't be able to make interesting use of x86_64 instruction if you are not ok with x86.

There is nothing much to learn about assembly. You just need the instruction set reference and enough focusing to understand what you are reading.

First read simple C functions you wrote yourself.

Ben