7 ms·
Does anyone, (the author?), know the best reference for x86-64 assembly? I have been a loath to teach it to students because there I haven't found great materia
by timtadh 12y ago
Does anyone, (the author?), know the best reference for x86-64 assembly? I have been a loath to teach it to students because there I haven't found great material for it. I use "Programming from the Ground Up"* as my main text for 32 x86 but haven't found anything comparable for 64 bit. I also use:
* http://download.savannah.gnu.org/releases/pgubook/ProgrammingGroundUp-1-0-lettersize.pdf http://download.savannah.gnu.org/releases/pgubook/Programmin...
http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in-memory/ http://duartes.org/gustavo/blog/post/anatomy-of-a-program-in...
Sun Microsystem Assembler Reference http://docs.oracle.com/cd/E19455-01/806-3773/index.html http://docs.oracle.com/cd/E19455-01/806-3773/index.html (not because we use that assembler, we use gas for gcc compat, but it very clearly describes all of the usual 32 bit opcodes)
The Intel manuals http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html http://www.intel.com/content/www/us/en/processors/architectu...
Another Intel manual http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf http://www.intel.com/content/dam/www/public/us/en/documents/...
EDIT: I agree with everyone one, I also learned via doing, decompiling small C programs, gdb, and manuals. However, I am looking for something a bit gentler. That process will work for the top 10% but the rest will struggle and at the end of the day they need to write an x86 code generator so without knowing how to write assembly they are in trouble.
- stephencanon 12y agoI learned x86_64 by (a) reading assembly other people wrote, (b) disassembling compiled code, (c) the Intel architecture manuals, and (d) writing a ton of assembly and fixing my mistakes. This is something of the sink-or-swim approach, but I find it works really well; at the end of the day, assembly is really, really simple--the key thing is to just start writing it. Of course, it's hard to do this sort of immersion in a course where some of the students aren't really interested and just want to know what they need to complete the assignments, so the efficacy depends a lot on the nature of the class.
- Cyph0n 12y agoMay I ask why one would learn x86-64 assembly other than for extreme use cases like compiler design and reverse engineering? Modern languages and their compilers can usually produce the best possible machine code most of the time. Further, embedded systems run on ARM nowadays which is a bit simpler to deal with due to the smaller instruction set.
- 0xAX 12y agoMaybe for understanding how computer works? What occurs when you launch program, what occurs between turning on computer and that moment when you see login screen, what is it printf("Hello world") and etc... Many interesting questions. Of corse assembly is not answer on all questions but the way to it
- psykotic 12y agoIf you care about optimizing your C/C++ code, you need to be reading the assembly language output from the compiler on a regular basis. You will constantly stumble over cases where the compiler isn't doing what you expected. For example, it might be reloading memory in an inner loop instead of caching its value in a register outside the loop because its alias analysis was inconclusive. Or not enough inlining is happening where you expected it. Or there's too much inlining like when a side exit to a cold function is inlined within an inner loop. This last case exemplifies a general issue that ahead-of-time compilers have with identifying code paths as hot or cold. You can sometimes give hints to the compiler, but you must verify that the hints were actually taken in the way you expected. Obviously you only dive into this level of detail with a piece of code once you have reason to believe it's warranted (e.g. profiler information).
- blt 12y agoYes. Sampling profiler + reading generated assembly are the two prongs of my optimization approach. Sometimes the compiler does something really stupid and inefficient, but other times it does something really clever that I (who never wrote any serious assembly by hand) would never think of.
- mattgodbolt 12y agoIf you're using the compiler as a learning tool (and it's great for that!) may I suggest giving GCC Explorer a go: http://gcc.godbolt.org/ http://gcc.godbolt.org/ The name is deceptive; many compilers other than GCC are available. The turn around time of seeing how small snippets of code translate to assembly makes it pretty well suited to exploring assembly. Though it's my site, so usual author disclaimer here too! Also I find compiling small tests and then single stepping in assembly mode another way to really 'get' what instructions do.
- deleted 12y ago[deleted]
- timtadh 12y agoMyself as well. However, my experience is that undergrads who are getting there first experience in x86 need their hands held quite a bit. It doesn't help that there are two competing syntaxes for x86 so I have to be careful to make sure all of the resources use the same syntax (I use AT&T so that it compatible with gcc as I said before). The gas manual is slightly frustrating because they simply say "consult intel" for the opcode and remember to mostly reverse except for most of the floating point instructions. See: https://sourceware.org/binutils/docs/as/i386_002dDependent.html#i386_002dDependent https://sourceware.org/binutils/docs/as/i386_002dDependent.h... So I mostly don't point students there because it isn't that helpful when you are just starting out.
- 0xAX 12y ago[author :)] I'm not sure that i can recomend somethig for you, but for things that i use for learning low-level programming are following. 1. Nasm manual 2. Intel manuals 3. gdb 4. Source code written by other peoples, like bootloaders, simple 64 bit operating systems and etc...
- a1a 12y agoNot really answering you. But I feel like sharing the method our lecturer had. We learned MIPS first and then when people had a grasp of the basics we had lectures (along with intel manuals, abi reference, and some minor internal documents) explaining x64, partly in a "compared to mips" perspective. I believe this method served us pretty good and most had no problem picking up on x64.
- nova 12y agoThere is "Introduction to 64 Bit Intel Assembly Language Programming for Linux", 2nd Ed, by Ray Seyfarth. It's pretty good for beginners with some C experience, I think.
- timtadh 12y agoThanks I will check that out!
- fnordfnordfnord 12y agoProbably not what you're looking for but Randall Hyde has put up a second edition of The Art of Assembly which is available for free download or at no starch. http://webster.cs.ucr.edu http://webster.cs.ucr.edu I don't know if he addresses x86_64 much, if at all though.
- ANTSANTS 12y ago"Average" programmers had much more practical reason to learn assembly in the days of 16 and 32 bit x86, of DOS, Win32, and software rendered games, than today when the average programmer writes Javascript or some other dynamic language and is several levels removed from the machine code being executed, so I don't think material written about x86-64 will ever be on the level of the stuff written back then. IMO it makes more sense to stick to the high quality 32 bit texts and let students figure out the 64 bit additions on their own if they want to. x86 is conceptually simpler anyway.