My first x86-64 assembly program for Linux.
This program reads a line from standard input, tries to parse it as a decimal unsigned integer, and exits with that value as the process exit code.
Behavior:
- reads up to 63 bytes into a fixed buffer
- accepts a trailing newline
- rejects empty input
- rejects any non-digit character
- returns exit code
255on invalid input - prints nothing to standard output
nasm -f elf64 main.asm -o main.o
ld main.o -o mainprintf '42\n' | ./main
echo $?Expected exit code:
42
Invalid input example:
printf '12a\n' | ./main
echo $?Expected exit code:
255
- The program uses raw Linux syscalls and starts at
_start. - The exit status visible in the shell is limited to the low 8 bits, so values above
255are truncated by the OS.