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.
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.
Supported operations:
- Addition
- Subtraction
- Multiplication
Division
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).
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)
To build the library on linux, follow these steps:
-
Clone the repository:
git clone https://github.com/Mario-659/bcd_arithmetic cd bcd_arithmetic
-
Create a buld directory and change to it:
mkdir build cd build
-
Run CMake to generate the build files:
cmake ..
-
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
The unit tests are implemented using Google Test. To run the tests, follow these steps:
-
Build the library as described in the previous section.
-
Run the unit tests:
make test