A fast and space-efficient big int division library written in NASM assembly.
int64_t mdiv(int64_t *x, size_t n, int64_t y);Parameters:
x: Pointer to an array ofn64-bit integers representing the dividend in little-endian order.n: Number of elements in the arrayx.y: 64-bit signed integer divisor.
Returns:
- The remainder of the division (
x%y). - The quotient (
x/y) is stored back in the arrayx.
Error Handling:
In cases of overflow or division by zero, the function triggers an overflow condition (SIGFPE signal on Linux).
- The divisor (
y) must be a signed 64-bit integer (int64_t).
- For the library (
mdiv.o):- NASM assembler
- For the example program (
example.c):- CMake version 3.30 or higher.
- A C compiler supporting the C17 standard (e.g., GCC or Clang)
- NASM assembler
-
Clone the Repository:
git clone https://github.com/Iteron-dev/bigint-div.git cd bigint-div -
Building the Library Only:
To compile just the library (
mdiv.o) for use in your own projects:nasm -f elf64 -w+all -w+error -o mdiv.o mdiv.asm
-
Building the Example Program:
To build the example program demonstrating the library usage:
a) Using CMake:
cmake -B build/ make -C build/
This will create the
exampleexecutable in thebuild/directory.b) Manual Compilation:
If you prefer to compile manually without CMake:
nasm -f elf64 -w+all -w+error -o mdiv.o mdiv.asm gcc -c -Wall -Wextra -std=c17 -O2 -o example.o example.c gcc -z noexecstack -o example example.o mdiv.o
For demonstration purposes, you can refer to and modify the example.c file. It showcases a sample usage of this library.
This project is licensed under the GNU General Public License v3.0.
See LICENSE for the full terms.