Skip to content

This program implements an algorithm in x86-64 assembly to calculate the factorial of very large numbers—up to 40,000! Unlike standard methods that overflow quickly

License

Notifications You must be signed in to change notification settings

rsamanez/BigFactorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BigFactorial

This program implements an algorithm in x86-64 assembly to calculate the factorial of very large numbers—up to 40,000! Unlike standard methods that overflow quickly, it uses arrays to store and manipulate each digit of the result, allowing it to handle extremely large integers. The core logic mimics manual multiplication, digit by digit, with proper handling of carry operations. It’s an educational example of high-precision arithmetic done at the lowest level, ideal for exploring how to work with big numbers using pure assembly.

Este programa implementa un algoritmo en ensamblador x86-64 para calcular el factorial de números extremadamente grandes, ¡hasta 40,000! A diferencia de los métodos estándar que desbordan rápidamente, utiliza arreglos para almacenar y manipular cada dígito del resultado, lo que le permite trabajar con enteros de gran tamaño. La lógica central imita la multiplicación manual, dígito por dígito, manejando correctamente los acarreos. Es un ejemplo educativo de aritmética de alta precisión a bajo nivel, ideal para explorar cómo trabajar con grandes números usando solo ensamblador.

Algorithm

multiply(a[1..p], b[1..q], base)                            // Operands containing rightmost digits at index 1
  product = [1..p+q]                                        // Allocate space for result
  for b_i = 1 to q                                          // for all digits in b
    carry = 0
    for a_i = 1 to p                                        // for all digits in a
      product[a_i + b_i - 1] += carry + a[a_i] * b[b_i]
      carry = product[a_i + b_i - 1] / base
      product[a_i + b_i - 1] = product[a_i + b_i - 1] mod base
    product[b_i + p] = carry                               // last digit comes from final carry
  return product

How to Compile and RUN

Compile with:
     nasm -f elf64 -o bigFactorialNumber64.o bigFactorialNumber64.asm
Link with:
     ld -m elf_x86_64 -o bigFactorialNumber64 bigFactorialNumber64.o
Run with:
     ./bigFactorialNumber64

About

This program implements an algorithm in x86-64 assembly to calculate the factorial of very large numbers—up to 40,000! Unlike standard methods that overflow quickly

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published