Git Product home page Git Product logo

bcd_arithmetic's Introduction

BCD Arithmetic Library in C++

This project provides a C++ library for Binary Coded Decimal (BCD) arithmetic operations. It is built using CMake as the build tool, and Google Test for unit testing.

Table of Contents

BCD Representation

struct BCD {
    std::vector<unsigned char> digits_before_point;
    std::vector<unsigned char> digits_after_point;
};

Each decimal digit is represented by a single byte (unsigned char). The most significant digit is stored in the first element of the vector. The digits are stored in the vector in the same order as they are in the BCD number. The digits before the point are stored in the digits_before_point vector, and the digits after the point are stored in the digits_after_point vector.

Features

Supported operations:

  • Addition
  • Subtraction
  • Multiplication
  • Division

Implementation

Assembly instructions used to adjust the result of operations can be found here. The following instructions are used:

  • AAA: ASCII Adjust After Addition
  • AAS: ASCII Adjust AL After Subtraction
  • AAM: ASCII Adjust AX After Multiply

The assembly code is written for x86-64 architecture, and compiled using the GNU assembler (GAS).

Prerequisites

To use this library, you need to have the following software installed on your system:

  • A C++ compiler that supports C++11 or later
  • CMake (version 3.14 or later)

Getting Started

Building the Library

To build the library on linux, follow these steps:

  1. Clone the repository:

    git clone https://github.com/Mario-659/bcd_arithmetic
    cd bcd_arithmetic
  2. Create a buld directory and change to it:

    mkdir build
    cd build
  3. Run CMake to generate the build files:

    cmake ..
  4. Build the library:

    make

If you are getting error below:

fatal error: bits/c++config.h: No such file or directory
#include <bits/c++config.h>

then make sure to install dependencies needed for 64-bit architecture:

sudo apt-get update && sudo apt-get install -y g++-multilib libc6-dev-i386

Running Unit Tests

The unit tests are implemented using Google Test. To run the tests, follow these steps:

  1. Build the library as described in the previous section.

  2. Run the unit tests:

    make test

bcd_arithmetic's People

Contributors

mario-659 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.