LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A Good AMD64 Assembly Tutorial (https://www.linuxquestions.org/questions/programming-9/a-good-amd64-assembly-tutorial-941399/)

Zssfssz 04-23-2012 11:31 PM

A Good AMD64 Assembly Tutorial
 
I don't already know assembly (well I get the consepts not the code) so any syntax will be fine, although I want it to be ether Intel or At&T.
I read somewhere that 64-Bit assembly is easier than 32-Bit assembly.
I do want it to interface with C!

paulsm4 04-24-2012 02:37 AM

Strong recommendation: Programming from the Ground Up:

http://savannah.nongnu.org/projects/pgubook/

AMD64 is a superset of Intel x86. This book will absolutely get you going - satisfaction guaranteed!

IMHO...

johnsfine 04-24-2012 05:42 AM

Quote:

Originally Posted by paulsm4 (Post 4661416)
Strong recommendation: Programming from the Ground Up:

http://savannah.nongnu.org/projects/pgubook/

AMD64 is a superset of Intel x86.

I took a quick look. If I understood correctly, that book focuses on

32 bit x86
AT&T syntax
Whole programs in asm

If you want to learn 64 bit asm, some reference (not tutorial) documents you really should have are:
http://support.amd.com/us/Processor_...594_APM_v3.pdf
support.amd.com/us/Embedded_TechDocs/24592.pdf
and the newest ABI from
http://www.x86-64.org/documentation/

26568 covers SSE2, which is a nice next step after the basics.

For more advanced 64 bit programming you should also find 24593. To find any of these (they move around) I do a google search for AMD and the document number.

Those AMD documents use the operand sequence of Intel syntax. AT&T has the opposite sequence. But it isn't too hard to get used to remembering the document's operand sequence is backward. Armed with that knowledge, it should be easy to look at the asm code from a compiled C function (preferably in a GUI debugger, where you can step through and see register values as they change) and look up the instructions and addressing modes in those PDFs and understand what the code does.
Once you understand how a function compiled from C acts in asm, it is easy to write your own. No tutorial needed.

The ABI document can be confusing because it gives a lot of detail in order to put precision ahead of comprehensibility. There are two simple register lists whose meaning is almost all you ever need to know from the ABI:
passed: rdi, rsi, rdx, rcx, r8, r9
preserved: rbp, rbx, r12, r13, r14, r15
When passing parameters to functions, many parameter types are reasonable to pass in registers. The first six such parameters are passed in the registers listed.
A function is free to modify most registers, so when it returns those registers must be assumed to have lost whatever useful contents they might have had. But if a function uses registers in the preserved list, it must save the value each had before and restore it before returning.
Another important fact in the ABI is that function return values that can reasonably be in a general register are in rax.

For all the cases where you can't easily tell whether a parameter or return value should go in a register, the ABI ought to tell you, but I think it only yields that knowledge to ABI guru's. The easy way to answer all obscure ABI questions is to write a simple C function that has the same ABI issue, compile it, and see what gcc did.

NyteOwl 04-24-2012 11:50 AM

Another good basic book is "Assembly Language Step by Step: Programming with Linux" by Jeff Duntemann.

Garda 04-28-2012 10:26 PM

I don't know if this is going to be useful, but I thought I would post the link here anyway.


All times are GMT -5. The time now is 03:03 PM.