Live data from Hacker News

Ask HN: What's the best resource for learning modern x64 assembly?

news.ycombinator.com

41–50 of 112 posts

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#41
post #17

Have you looked at the official docs? Back in 386 days that's all we had. https://software.intel.com/en-us/articles/intel-sdm

In 1993, as a broke high-school student pre-cell-phone and pre-search-engine, we didn't even have that (although we did have BBS phone-number/speeds/protocols/login lists). I had to take the nascent VTA Lightrail (when it was even more uncool) to Computer Literacy bookstore (when programming was also less cool) to find decent technical references... and I promptly dropped a few hundred bucks on dead tree carcasses wh…

In 1993 I was trying to learn c64 assembly still

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#42

Earlier quoted context omitted.

> The old floating point stuff is gone. Do you mean x87? I’m not sure it’s true that it’s gone is it? The instructions are still documented? Do they not work?

I guess I stand corrected. I was under the impression that C compilers don't tend to use it anymore when compiling for amd64. (Because you can assume SSE support on amd64, unlike a binary that might run on an old Pentium.) Then I misread that situation as it not working. It does take effort for an OS kernel to save and restore x87 state, so I could imagine somebody dropping support.

> It does take effort for an OS kernel to save and restore x87 state, so I could imagine somebody dropping support.

FXSAVE saves the x87 state with the SSE state, and XSAVE generalizes that to add several optional components, depending on what your processor support (as of right now, AVX state, MPX state, 3 for AVX-512, PT state, and SGX state, IIRC).

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#43
Especially if you need x64 assembly for performance optimization or during profiling a combination of godbolt (https://godbolt.org/) and Agner Fog's incredible PDFs at https://agner.org/optimize/ (especially parts 2, 3 and 4) are helpful.

The other useful step has been to write C functions and compile the code with a good compiler (good experiences with Intel, gcc and llvm) first at -O0 and later at -O2 or -O3 to understand how high level concepts can be translated to assembly.

This requires to have at least a basic understanding of registers and basic assembly concepts but at least has helped me apply the concepts to real code.

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#44
It looks intimidating, but there's not actually much to learn. You need to memorize a couple dozen common opcodes. Keep the Intel manual open and flip to the page of the opcode. Also the first few sections go into detail about paging, data types, CPUs, etc. if you don't already know about it.

https://software.intel.com/en-us/articles/intel-sdm

Try to reverse engineer something you don't have the debug symbols for. One of the big pain points was figuring out the calling convention i.e. what registers correspond to which function arguments on different platforms:

https://en.wikipedia.org/wiki/X86_calling_conventions

For reverse engineering in particular, this was a good resource:

https://beginners.re/

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#45

There's no magic anywhere and 99.1% of it is documented. IA-32e/AMD64 is basically an extension of IA-32/x86. What you're looking for is to understand the difference between real mode, 386 protected mode, PAE, paging and long mode because the registers, instructions, addressing and sizes of structures differ. You can learn all of this by reading the Intel software manuals and digging into it yourself. Tools you need…

In addition to IDA, I highly recommend looking into ghidra. It's open source, so you can peak under the hood and see how it does things. https://github.com/NationalSecurityAgency/ghidra

It's way better than IDA Pro. I have used the Pro version with the Hex-Rays decompiler. Ghidra is legitimately better. I wouldn't recommend IDA to anyone at this point because I don't see it having much of a future (sorry not sorry).

It's worth learning the Ghidra Scripting API because you can write ad-hoc scripts with Jython syntax to automate tasks/do custom analysis.

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#46
post #26

For practice and user-mode stuffs https://godbolt.org/ is a valueless tool to help you view the output of any C program. Simply write any C program on the left, and add "-O1" in flag inputs. Assembly with color representing line-mappings would appear on the right.

It's worth noting that the same thing can be had by doing objdump or stepping through code in gdb. Godbolt is very convenient though.

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#47

It really depends on your starting point. If you know how to write low-level C (i.e. with direct Win32/POSIX API calls), that's a good start. If you don't know what that means, you need to master this first. So much of assembly is built to support higher-level programming, things like segments, indirect references, system calls, etc., so it pays to know the WHY of all of it (e.g. do you know what a frame pointer is?…

How can I get started on learning the low level c stuff with direct system calls and such. I learned about assembly, pipelining, cache, and memory allocation during a systems architecture course, so I'm really interested in the low level of the machine. The problem is I don't really have an idea of a project that I could do to learn the level right above. Of course I learned a bit during the course, but I really want to get a solid grasp.

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#48

It really depends on your starting point. If you know how to write low-level C (i.e. with direct Win32/POSIX API calls), that's a good start. If you don't know what that means, you need to master this first. So much of assembly is built to support higher-level programming, things like segments, indirect references, system calls, etc., so it pays to know the WHY of all of it (e.g. do you know what a frame pointer is?…

How can I get started on learning the low level c stuff with direct system calls and such. I learned about assembly, pipelining, cache, and memory allocation during a systems architecture course, so I'm really interested in the low level of the machine. The problem is I don't really have an idea of a project that I could do to learn the level right above. Of course I learned a bit during the course, but I really want…

If you really want to understand modern x64 or other ASM, write a simplified compiler for C. I would recommend starting with a tiny subset of the language focused on whatever aspects you want to understand. You can then compare your output with a modern compiler to get a better understanding of the intricacies involved.

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#49
post #26

For practice and user-mode stuffs https://godbolt.org/ is a valueless tool to help you view the output of any C program. Simply write any C program on the left, and add "-O1" in flag inputs. Assembly with color representing line-mappings would appear on the right.

> valueless

You mean "invaluable" here (cannot be given a value, as it's too important). "valueless" is the opposite (worthless)! https://en.wiktionary.org/wiki/valueless

Re: Ask HN: What's the best resource for learning modern x64 assembly?

#50

It really depends on your starting point. If you know how to write low-level C (i.e. with direct Win32/POSIX API calls), that's a good start. If you don't know what that means, you need to master this first. So much of assembly is built to support higher-level programming, things like segments, indirect references, system calls, etc., so it pays to know the WHY of all of it (e.g. do you know what a frame pointer is?…

Your comment about compilers is most likely true. The exception being if he needs to vectorize or if he had the opportunity use these special-purpose instructions that are seemingly built to accelerate particular algorithms.
Post reply on HN