any tutorials for x86-64 assembly under freebsd?

Lorenzo Salvadore phascolarctos at
Wed Dec 26 15:08:34 UTC 2018

> i am running freebsd-12 under x86-64.
> i have been pointed to 'as' and 'ld' for tools.
> i have also been pointed to the 'url' for intel
> documentation about x86-64 assembly.
> i also have a sample "hello world" program in
> x86-64 assembly language.
> may i know of any tutorials which can teach me
> to work with assembly using x86-64?
> i saw one book on, but that uses the
> assembler from microsoft ('masm') which i think
> only runs under windows-10+.
> any pointers and/or help would be appreciated.
> thank you.

For tools, I would suggest you nasm if you want to
write software fully in assembly, but it is definitely not
recommended nowadays for the following main reasons:

- It's hard. More precisely, it is not very intuitive and
writing even a simple hello world program requires some
knowledge to achieve. Debugging can be a real pain.

- There is no need for it most of the times. The main
reason for using assembly is to get maximal control
over the code executed by the computer, so that you
can optimize it (for speed, size, memory use...). But this
is a very difficult task and compilers generally ends up
with better code than programmers (altough
compilers code is far from optimal, I did some research in

Still, you might need assembly in some contexts, such as
writing drivers or optimizing code (as I said, it is hard, but
sometimes it is needed). In those cases, what you would
generally do is writing the software mainly in a higher level
language (tipically C or C++), then use inline assembly, so
that you can write in assembly only the parts that you can't
write in your higher level language (functions that requires low
level interactions with hardware, slow functions that need to
speed up).

If you want to use inline assembly, any x86-64 tutorial is as good
as any other: you could buy the book you saw, the ideas would be
just the same, only the syntax would be slightly different (there are
two main syntaxes you need to familiarize with: Intel and AT&T.
Unless you specify differently, default syntax for inline assembly
in gcc and clang is AT&T if I remember well).

Then, depending on what your needs are you will need some more
documentation. You can find most of what you might need here:

If you want to optimize some code, choose manuals 2, 3 and 4 (and 1
will not hurt). If you would rather interact with FreeBSD at a low level,
you need to know calling conventions, which you should find in manual 5
and at .

Finally, use a disassembler too, such as objdump: it can help you understand
calling conventions for low level interaction and it can gives you good starting
points for code optimizations.

Lorenzo Salvadore.

More information about the freebsd-questions mailing list