Kip Irvine’s x86 assembly book is a good introduction to assembly. However, it requires using Visual Studio on Windows, both for the syntax and more importantly for the Irvine32 support library that the examples require. Happily, some folks have put together a Linux port of that library called Along32 and so using the crossplatform nasm assembler, one can make nearly full use of the book on Linux.
Below are the basic instructions for using nasm and this library.
-
Install nasm (if it is not already installed).
wget -c http://www.nasm.us/pub/nasm/releasebuilds/2.10rc3/nasm-2.10rc3.tar.gz
tar -xzf nasm-2.10rc3.tar.gz
cd nasm-2.10rc3
./configure --prefix=$HOME/nasm
make
make install
cd ..
rm -rf nasm-2.10rc3 nasm-2.10rc3.tar.gz
export PATH=$PATH:$HOME/nasm/bin -
Install Along32.
wget -c http://sourceforge.net/projects/along32/files/Along32-1.0.3.tar.gz/download
tar -xzf Along32-1.0.3.tar.gz
cd Along32/src
make
mkdir -p $HOME/nasm/lib $HOME/nasm/include
make install INSTDIR=$HOME/nasm/lib
cp ../Along32.inc $HOME/nasm/include
cd ../../
rm -rf Along32 Along32-1.0.3.tar.gz
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/nasm/lib -
Convert your program to nasm syntax. The instructions here should provide a good starting point. The
%include
line should be:%include "/path/to/my/home/nasm/include/Along32.inc"
-
Assemble your program (assuming source is program.asm)
nasm -f elf -o program. o program.asm
-
Link your program.
gcc -o program program.o -lAlong32 -L$HOME/nasm/lib
-
Run your program.
./program