Live data from Hacker News

An Introduction to x86_64 Assembly Language

hackeradam17.com

41–50 of 56 posts

Re: An Introduction to x86_64 Assembly Language

#41
post #30

Sure, there are some applications in which we may need to squeeze every ounce of efficiency out of our programs, but in this day and age you’ll be hard pressed to come any where close to the code optimizations made by modern compilers. Does anyone who regularly writes assembly really believe that it's difficult to write better code than a modern compiler? This isn't my experience at all. Instead, I'd say that with ju…

I think the same thing too; I've seen a lot of horrible compiler output, far more than good or even "novice Asm programmer" level. Maybe the fact that compilers default to optimisations disabled (and generate horribly redundant code), and a lot of binaries that are released seem to get compiled this way, has something to do with it.

> It's almost as if there is some compiler-writers-protection-racket out there that threatens anyone who doesn't bow to the powers of the modern compiler.

A lot of it seems to come from the "religious belief in abstraction" that is prevalent among academics; the belief that somehow, a "higher level" solution is always better.

> The wonder isn't that they generate perfect code (by and large, they don't), but that they can optimize as well as they do without introducing bugs left and right.

It's not so surprising when you consider that compilers are just following patterns/transformations when they generate or optimise code, and these patterns are designed to be very general so they work for all cases, even when they're not the most efficient way to do it in some of these cases. When a human is writing the Asm there is (or should be - otherwise you'd be better off just using a compiler) a higher level of thought, a different process, one that may be more prone to errors but one that also shows some form of creativity - thinking about the specific application and, understanding that, applying a transformation/pattern that is only applicable in that case to improve the generated code.

Size optimisation is also another area where even a novice Asm programmer can very easily beat a compiler due to this general/specific pattern-ness divide. From what I've seen, compilers start with often overly-general code-generating patterns to produce initially unoptimised output, and then attempt to remove unnecessary instructions; while a human would not have this generality - because the human knows more about the specific problem - and the "first-cut" of code he/she writes is already more specific than the compiler's.

(Not that I'm against compilers in general - I would very much like them to generate better code, but for that to happen there is likely going to have to be large changes in how they're written and how the whole process of compilation is thought of. Trying to make a compiler "think" like a human is a good first step...)

Re: An Introduction to x86_64 Assembly Language

#43

It's nice to see the "correct" order of the registers being used. (The reason for this ordering is in the realm of trivia questions.)

Do you mean "correct" as in that's the absolute right order (as in math) or as in that's the original intel syntax?

My first programming language was mc68k assembler where the "correct" order of registers is the opposite.

Re: An Introduction to x86_64 Assembly Language

#44
post #29
post #13

This seems like a great start, but it's lacking something that every assembly programming resource that I've ever come across lacks too: How can I experiment? How do I go from instructions in a text file, to compiling, to getting input in some form? What programs do I use (on Linux)? What commands do I run? What are fun projects that are worthwhile doing with assembly? Beyond that, what are good applications of assem…

On Linux, you can use 'as', the gnu assembler, or you can also use nasm, which most people prefer over 'as'. I've used both, and I got used to 'as' syntax after a while. I long time ago I wrote a threaded/fiber system for DOS. It was mostly C, but the task switching and interrupt stuff was all assembly. It's basically an implementation of setjmp/longjmp hooked up with timer interrupts. You might use it in your day to…

you can use the intel syntax with gas too (see -masm=intel or .intel_syntax noprefix).

Re: An Introduction to x86_64 Assembly Language

#45
Read this book, it's basically only hacking C code with assembly. http://www.amazon.com/Hacking-The-Art-Exploitation-Edition/d... It also covers topics such as TCP sockets and the likes. If you ever want to become a real hacker it's your best starting point.

And the world was never the same again.

Re: An Introduction to x86_64 Assembly Language

#46
post #43

It's nice to see the "correct" order of the registers being used. (The reason for this ordering is in the realm of trivia questions.)

Do you mean "correct" as in that's the absolute right order (as in math) or as in that's the original intel syntax? My first programming language was mc68k assembler where the "correct" order of registers is the opposite.

It's the order they occur in the encoding: A, C, D, B.

68k has numerical, not named registers, and they're in the same order as the encoding.

Re: An Introduction to x86_64 Assembly Language

#47
post #39
post #15

Learning Assembly language has been on my list of "want to do" for a long time now but as I have never had a need for it professionally I kept putting it off. I actually have time for myself now and outside of learning to cook properly and cycle a lot I would really like to finally tick this off my bucket list. The problem is I am not too sure where to actually start. I want something that starts from the bottom and…

"Programming from the Ground Up" (linked from a couple of other posts) has exactly what you want. There's no need to learn C first - it becomes obvious how memory and pointers work when you're actually doing it. It's a lot easier than people make out, just give it a go.

Many thanks! Checking it out now.

Re: An Introduction to x86_64 Assembly Language

#48
post #32
post #15

Learning Assembly language has been on my list of "want to do" for a long time now but as I have never had a need for it professionally I kept putting it off. I actually have time for myself now and outside of learning to cook properly and cycle a lot I would really like to finally tick this off my bucket list. The problem is I am not too sure where to actually start. I want something that starts from the bottom and…

Might be a good idea to brush up your C first. Make sure you really understand memory and pointers.

Yeah I think I will pick up Modern C by King and/or Head First C. Book seem pretty good. I have a copy of K&R somewhere already.

Re: An Introduction to x86_64 Assembly Language

#49
post #22
post #16

Earlier quoted context omitted.

You might like the assembly tutorial I am writing: https://plus.google.com/111794994501300143213/posts/9gxSUZMJ... It's focused on actually doing rather than how stuff works. In order to succinctly be able to present this, I had to choose a target platform, which unfortunately seems not to be the one that you prefer. My tutorial targets OS X, and there is great similarity between coding assembly on OS X and Linux. Th…

It would be cool if someone made a VM for development only, on which you could run x86_64 assembly, and get sensible error messages.

Qemu comes pretty close. You can dump register and memory values, crashes outputs useful dumps, etc.

Re: An Introduction to x86_64 Assembly Language

#50

This is a great resource, and the following is not a criticism, but an observation. What I've found with most assembly language textbooks and online resources is that while the basics get covered well enough, the fundamental knowledge base is often skimmed over, as are the many assumptions and conventions that are made in how the CPU is supposed to work. I first learned 8086 assembler from Peter Norton's book ( http:…

I recommend Computer Systems: A Programmer's Perspective. It sounds like what you're looking for, although it uses a mix of C and IA32.

I came in here to say just this! A fantastic book in so many ways. I read a lot of it on my own and learned more than in many of my classes on similar subjects. It taught me a huge amount about C, systems, architecture, memory and more. Very cool stuff. It starts with x86 but goes over at least the basic differences between it and x64.
Post reply on HN