This content is translated with AI. Please refer to the original Traditional Chinese version (zh-TW) for accuracy.
Recently, the author has been studying nasm, an assembly implementation, since operating systems have upgraded to 64 bits. Compiling asm code requires some additional handling steps. Here are the steps I’ve recorded, using ArchLinux, though I imagine other operating systems shouldn’t differ much.
Firstly, the author provides asm_io.asm, which needs to be compiled first. Install the nasm assembler from the author:
sudo pacman -S nasm
Assembly:
nasm -f elf -d ELF_TYPE asm_io.asm
nasm -f elf first.asm
Here, “first” is the asm code we wrote ourselves.
The next step is to use gcc; originally, the book suggested:
gcc -o first driver.c first.o asm_io.o
However, since we’ve been assembling with elf32, we need to change it to:
gcc -m32 -lc -o first driver.c first.o asm_io.o
Here, install the following:
sudo pacman -S gcc-multilib gcc-libs-multilib
I also encountered an issue where the shared library libisl couldn’t be found, possibly because gcc-multilib didn’t keep up with isl updates. This was resolved by creating a symbolic link to libisl.13.0.0.
Afterwards, the compilation can be completed, but perhaps learning to write 64-bit assembly is a more fundamental solution?