Skip to content

bac0nb0yy/libasm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libasm

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.

Features

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.

Project Structure

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

Requirements

  • Assembler: nasm (Netwide Assembler)
  • C Compiler: cc
  • Testing Framework: Criterion

Installation

  1. Clone the repository:

    git clone https://github.com/bac0nb0yy/libasm.git
    cd libasm
  2. Build the library:

    make
  3. Build and run the tests:

    make test

Usage

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/ -lasm

Testing

The project includes a comprehensive test suite using the Criterion framework. To run the tests:

make test

Cleaning Up

To remove compiled files and the library:

make fclean

To remove dependencies and test tools:

make uninstall

License

This project is for educational purposes and does not include a license. Use at your own discretion.

Author

Created as part of a learning exercise

About

Implementing basic libc functions in x86-64 assembly to understand low-level programming.

Topics

Resources

Stars

Watchers

Forks

Contributors