A library of standard C functions reimplemented in x86-64 assembly for the 42 libasm project.
- 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
| 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 |
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.
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 | - | - |
make/make all- Compile the library (libasm.a)make test- Compile library and link with main.c to create test executablemake clean- Remove object filesmake fclean- Remove object files and librarymake re- Clean and rebuild everything
# Build the library
make
# Compile and run tests
make test
./test
# Clean build artifacts
make clean
# Full rebuild
make re