Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

asm-atoi-exit-code

My first x86-64 assembly program for Linux.

What it does

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 255 on invalid input
  • prints nothing to standard output

Build

nasm -f elf64 main.asm -o main.o
ld main.o -o main

Run

printf '42\n' | ./main
echo $?

Expected exit code:

42

Invalid input example:

printf '12a\n' | ./main
echo $?

Expected exit code:

255

Notes

  • 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 255 are truncated by the OS.

About

x86-64 Linux assembly: parse argv integer and return it as the process exit code

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages