libasm is a project that implements several standard library functions in x86-64 assembly. The goal is to gain a deeper understanding of low-level programming and assembly language while creating a functional library.
The library provides the following functions:
ft_strlen: Computes the length of a string.ft_strcpy: Copies a string from source to destination.ft_strcmp: Compares two strings lexicographically.ft_write: Writes data to a file descriptor.ft_read: Reads data from a file descriptor.ft_strdup: Duplicates a string.
libasm/
├── includes/ # Header files
│ └── libasm.h # Function prototypes and type definitions
├── sources/ # Assembly source files
│ ├── ft_io.s # Implementation of ft_read and ft_write
│ ├── ft_strlen.s # Implementation of ft_strlen
│ ├── ft_strcpy.s # Implementation of ft_strcpy
│ ├── ft_strcmp.s # Implementation of ft_strcmp
│ ├── ft_strdup.s # Implementation of ft_strdup
├── tests_includes/ # Test-specific headers
│ └── tests_utils.h # Utility functions for tests
├── tests_sources/ # Test source files
│ ├── test_strlen.c # Tests for ft_strlen
│ ├── test_strcpy.c # Tests for ft_strcpy
│ ├── test_strcmp.c # Tests for ft_strcmp
│ ├── test_write.c # Tests for ft_write
│ ├── test_read.c # Tests for ft_read
│ ├── test_strdup.c # Tests for ft_strdup
│ └── tests_utils.c # Utility functions implementation
├── Makefile # Build system
├── .clang-format # Code formatting rules
├── .gitignore # Git ignore rules
└── README.md # Project documentation
- Assembler:
nasm(Netwide Assembler) - C Compiler:
cc - Testing Framework: Criterion
-
Clone the repository:
git clone https://github.com/bac0nb0yy/libasm.git cd libasm -
Build the library:
make
-
Build and run the tests:
make test
To use the library in your project, include the libasm.h header and link the libasm.a static library:
#include "libasm.h"
int main() {
const char* str = "Hello, World!";
size_t len = ft_strlen(str);
printf("Length: %zu\n", len);
return 0;
}Compile your program with:
gcc -o my_program my_program.c -Llibrary/ -lasmThe project includes a comprehensive test suite using the Criterion framework. To run the tests:
make testTo remove compiled files and the library:
make fcleanTo remove dependencies and test tools:
make uninstallThis project is for educational purposes and does not include a license. Use at your own discretion.
Created as part of a learning exercise