Getting prepared to write assembly language can be a bit confusing. There are a number of tools that can compile and link assembly. It may not be obvious right away which tool works on your particular operating system, supports compiling to a machine binary that is compatible with your processor, and is compatible with a debugger.
I tried a number of options around compiling, linking and debugging before finding a solution that worked well
I started with clang but had trouble getting the the linked executable to run.
Next I tried a combination of nasm
to compile and ld
for linking. For example,
nasm -f macho64 -o hello_world.o hello_world.asm
ld hello_world.o -o hw
./hw
This works well on a Mac until you need to debug. gdb
is not able to step through a file linked from a macho64 object file. This blog post details a similar ordeal here. nasm
does not support the macho debug format yet.
The blog linked above suggested using a virtual machine to run Linux whose supported assembly language formats have support for debugging via nasm
. However, I did not want to run a heavy VM when a lighter docker container could do the job.
I am going to use this example image for guidance here.
My goal is to use a live docker container to step through the assembly code. Update on how I go with that soon.