
Say hello to x64 Assembly, part 1 - nkurz
http://0xax.blogspot.com/2014/08/say-hello-to-x64-assembly-part-1.html
======
robert_tweed
Does anyone know what's a good macro-assembler these days? The article
recommends NASM, but I don't know if it's comparable to MASM for larger, more
complex projects.

I rather fancy getting back into writing asm, just to sharpen that skill. I
haven't really written any since MASM 6.x on DOS, 20-ish years ago. I actually
found it quite enjoyable and it's surprising how complex an application you
can write from scratch in assembly without it becoming unmanageable, so long
as you get into the right mindset and make effective use of macros.

Of course, any significant piece of assembly code is likely to contain
considerably more bugs than just about anything else of the same complexity.
You'll also experience a lot more segfaults during development than perhaps
most are comfortable with, but there's something rewarding about controlling
precisely what the machine is doing at that level. This is especially true if
you manage to find a novel solution that just wouldn't exist when the hardware
capabilities are abstracted away by a high level language.

In the same way that everyone should learn a Lisp to think in terms of ASTs
and code-as-data, everyone should write at least one whole application in
assembly just to appreciate how the hardware really works. Also to see how
often there are _many_ ways to solve the same problem (especially with an x86
instruction set), sometimes with _wildly_ different performance
characteristics.

~~~
DanWaterworth
_everyone should write at least one whole application in assembly just to
appreciate how the hardware really works_

Unfortunately, with out-of-order execution and instruction-level parallelism,
I doubt learning assembly teaches you much about how the hardware really
works.

Edit: To the downvoter, care to comment?

~~~
userbinator
Microarchitecture doesn't change the fact that the instructions in your
program - the ones that you can work with - still have the same programmer-
visible behaviour (except perhaps being a little faster.)

~~~
DanWaterworth
I don't dispute that. I'm saying the model that you learn from learning
assembly is very different to what the hardware is doing.

Concretely, learning assembly, you might assume each core has a set of
physical registers that correspond to the registers you see and that isn't the
case.

------
e12e
I came across Intel's intro to x64 assembly when I was looking for some
information on working with wide characters on 64bit (I seem to recall there
were some new instructions introduced for that, I'm guessing one would
probably be better off using libicu to parse eg: utf-8 into some form of
16-bit characters first, though?). Anyway, nothing on wide characters, but
essentially a work-a-like hello-world for Microsoft Windows and MASM:

[https://software.intel.com/en-us/articles/introduction-
to-x6...](https://software.intel.com/en-us/articles/introduction-
to-x64-assembly)

------
jpgvm
Being able to read x64 assembler even if you can't write it is great for
debugging strange issues.

~~~
NaNNaNNaNNaN
Javascript is the assembly language of today. For debugging purposes you're
better off with Javascript.

~~~
ThatOtherPerson
Not everybody targets all their code for the web.

~~~
rev_bird
You mean there's code... not on the web?!

------
lovelearning
Excellent! Just 2 days ago, somebody here was complaining about shortage of
asm programmers, and I suggested them that I'd personally be interested in a
hello world x86_64 tutorial to rekindle my interest in asm...and today I see
this posted! Exactly what I wanted, thank you.

~~~
innocenat
I still don't understand why people who want to learn amd64 assembly won't
read x86 tutorial. I write both x86 and amd64 assembly from time to time, and
I don't think there are anything that make x86 tutorial/manual not applicable
to amd64.

Sure, there are differences: register name, C ABI convention, system calls,
memory modes, etc. But those information can be find easily in references. And
you need reference for x86 anyway. Otherwise all mechanisms are the same.

~~~
ANTSANTS
It's a bit of a catch-22: you can't know that there's not much different
between x86 and x86-64 until you understand both. I guess asm newbies have
some kind of mistaken idea that x86 is irrelevant and not worth their time
learning (even if it were completely dead in the wild, which it absolutely
isn't, you still need to know it truly understand the architecture); I've
tried to post older x86 and ARM assembly language guides, much better written
and more in-depth than this article (no offense intended to the author), and
the only comments I get are along the lines of "this is old, it doesn't even
cover x86-64/ARM64."

------
theoutlander
Thanks for the writeup. I'm going to try it one of these days when I get a
break from work/startup. I ordered a few books recently and have been
tinkering with writing an OS....got as far as writing a bootloader and then
switched gears into learning ASM.

I bought Peter Norton's Assembly Language Book for the IBM PC. This book is
pretty awesome and so relevant even 25 years later!! It covers the basics
really well and stops at 386 (the latest proc then) so I don't feel inundated
with hundreds of CPU architectures. Yes, I'll eventually get to those.

The other two books (in case anyone else is interested): X86 Assembly Language
and C Fundamentals by Joseph Cavanagh. Operating Systems Design and
Implementation (3rd Edition).

Also, while tinkering with ASM I decided to install MSDOS since the ASM book
uses Debug.exe and I couldn't seem to find it for newer OS's. While looking to
download MSDOS, I discovered the source code for MSDOS 1.1 & 2.0 @
[http://www.computerhistory.org/atchm/microsoft-research-
lice...](http://www.computerhistory.org/atchm/microsoft-research-license-
agreement-msdos-v1-1-v2-0/).

------
okasaki
The code doesn't render with links2. Does it rely on javascript?

~~~
krakensden
Yup- they're gists. I'm pretty sympathetic, setting up pygments, etc., is sort
of a pain.

------
DigitalJack
desertmonad has a gist with 32bit and 64bit hello world's for osx.
[https://gist.github.com/desertmonad/36da2e83569bc8b120e0](https://gist.github.com/desertmonad/36da2e83569bc8b120e0)

------
CraigJPerry
Another great resource, albeit for x86 rather than 64
[http://savannah.nongnu.org/projects/pgubook/](http://savannah.nongnu.org/projects/pgubook/)

~~~
pekk
It isn't nearly as hard to find x86 guides as x86-64 guides.

~~~
0xAX
That's why i started to write it :)

------
infoseckid
You guys might enjoy this
[http://www.pentesteracademy.com/course?id=7](http://www.pentesteracademy.com/course?id=7)

------
31reasons
Its funny after so many years Code is still called Text in assembly.

~~~
robert_tweed
That's not the way I remember it in MASM/DOS. I think it's a Unix-specific
thing.

