An x86-64 assembly library for converting integers to ASCII (itoa64) and ASCII to integers (atoi64). Supports signed 64-bit integers (positive and negative). Can be used in Linux programs, bootloaders, or kernels.
- Convert signed 64-bit integers → ASCII (itoa64)
- Convert ASCII → signed 64-bit integers (atoi64)
- Null-terminated strings
- Minimal and fast
- Works on major Linux distributions
src/atoi64.asm— ASCII → integersrc/itoa64.asm— integer → ASCIIsetup.sh— installs NASM if missing and builds.ofilesbuild/— folder for assembled object files
- amd64 (x86_64, 64-bit)
- Linux only
Clone the repository first:
git clone https://github.com/s-r-e-e-r-a-j/libx64asm-atoi-itoa.gitNavigate to the project directory:
cd libx64asm-atoi-itoaAfter cloning and navigating to the project directory, follow the Build Instructions section.
Make setup.sh executable and run it:
chmod +x setup.sh
./setup.sh- Installs NASM if missing (supports Debian, RHEL, Arch)
- Assembles
atoi64.asmanditoa64.asminto.ofiles inbuild/ - After running
setup.sh, the object files for the library will be in thebuild/folder. - You will need to link the
.ofiles in thebuild/folder when compiling your own programs.
atoi64
- Input:
RDI→ pointer to null-terminated ASCII string
- Output:
RAX→ signed 64-bit integer
itoa64
- Input:
RDI→ signed 64-bit integerRSI→ pointer to output buffer
- Output:
RAX→ string length (without null byte)- Output buffer is null-terminated
After running setup.sh, the library object files are created in the build/ folder:
build/atoi64.o
build/itoa64.oWhen you build your own program, you must link these object files.
Example
nasm -f elf64 main.asm -o main.o
ld -o main main.o build/atoi64.o build/itoa64.o -e _startIf your program is in another directory Use the path to the build/ folder:
nasm -f elf64 main.asm -o main.o
ld -o main main.o \
../libx64asm-atoi-itoa/build/atoi64.o \
../libx64asm-atoi-itoa/build/itoa64.o \
-e _startImportant
- The library is not installed system-wide
- Only the
.ofiles inbuild/are needed - Always include them when linking
You only need to link the object file for the function you use.
- If you use
atoi64only, linkatoi64.o - If you use
itoa64only, linkitoa64.o - If you use both, link both files
Examples
Using only atoi64:
ld -o program program.o build/atoi64.o -e _startUsing only itoa64:
ld -o program program.o build/itoa64.o -e _startUsing both:
ld -o program program.o build/atoi64.o build/itoa64.o -e _startFrom another directory
ld -o program program.o \
../libx64asm-atoi-itoa/build/atoi64.o \
-e _startor
ld -o program program.o \
../libx64asm-atoi-itoa/build/itoa64.o \
-e _startglobal _start
extern atoi64
section .data
input db "-12345", 0 ; input string
section .text
_start:
mov rdi, input ; string address
call atoi64 ; convert to number
; rax now holds the result
mov rax, 60 ; exit syscall
xor rdi, rdi ; exit code 0
syscallBuild:
nasm -f elf64 example_atoi.asm -o example_atoi.o
ld -o example_atoi example_atoi.o build/atoi64.o -e _startglobal _start
extern itoa64
section .bss
buffer resb 32 ; output buffer
section .text
_start:
mov rdi, -9876 ; number to convert
mov rsi, buffer ; buffer address
call itoa64 ; convert to string
; RAX = length of string (excluding null byte)
; buffer now has the text
mov rax, 60 ; exit syscall
xor rdi, rdi ; exit code 0
syscallBuild:
nasm -f elf64 example_itoa.asm -o example_itoa.o
ld -o example_itoa example_itoa.o build/itoa64.o -e _startThis project is licensed under the MIT License