Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libasm

A library of standard C functions reimplemented in x86-64 assembly for the 42 libasm project.

Implemented Functions

  • ft_strlen - Calculate string length
  • ft_strcpy - Copy a string
  • ft_strcmp - Compare two strings
  • ft_strdup - Duplicate a string (with dynamic memory allocation)
  • ft_read - Read from file descriptor
  • ft_write - Write to file descriptor

x86-64 Registers Used

Register Size Purpose
rax 64-bit Return value, accumulator
rbx 64-bit Callee-saved general purpose
rcx 64-bit General purpose, loop counter
cl 8-bit Low byte of rcx
rdi 64-bit First function argument (pointer)
rsi 64-bit Second function argument (source)
rdx 64-bit Third function argument / data
rsp 64-bit Stack pointer

Linux System Calls

The assembly library uses the x86-64 syscall convention. Arguments are passed in rdi, rsi, rdx, r10, r8, r9 and the syscall number goes in rax. The syscall instruction transitions to kernel mode and the kernel dispatches based on rax.

x86-64 System Call Numbers and Argument Registers

rax Syscall rdi rsi rdx Notes
0 read unsigned int fd void *buf size_t count returns ≥0 or -errno
1 write unsigned int fd const void *buf size_t count
60 exit int status - - no return
2 open const char *pathname int flags mode_t mode
3 close unsigned int fd - -

Build & Test

Makefile Targets

  • make / make all - Compile the library (libasm.a)
  • make test - Compile library and link with main.c to create test executable
  • make clean - Remove object files
  • make fclean - Remove object files and library
  • make re - Clean and rebuild everything

Usage

# Build the library
make

# Compile and run tests
make test
./test

# Clean build artifacts
make clean

# Full rebuild
make re

About

some libc functions in asm for the 42 libasm project

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages