Design of ALU and Code Converter Using Matrix Calculation

: Arithmetic Logic Unit (ALU) is a fundamental building block of a central processing unit (CPU) in any computing system. The ALU is the hardware that performs logical (and, or, xor) and basic arithmetic (addition, subtraction, multiplication, division) operations. Thus, its construction requires techniques in which the treatment of operands should be consistent with operations rules. In this paper, ALU based on matrix calculation introduced and developed by Raoelina Andriambololona is proposed. These techniques aim to remove illogic and inconsistent appearing in the international writing numeration with the usual rules in arithmetic. We also propose the design of code converters which convert Binary to BCD (Binary Coded Decimal) code and vice versa using matrix calculation.


Introduction
There are incoherencies and illogical between usual written numeration and arithmetic rules. For instance, in English language, the number 216 is written as two one six but read as two hundred sixteen (i.e. "261" instead of 216). In many languages (English, French, German, Malagasy) the same inconsistency exists [2-3-4].
In order to avoid these problems, Raoelina Andriambololona has investigated and used matrix calculation and linear algebra tools [1-2-3-4-13]. This approach exhibits four and only four possibilities to write a number according to the disposition in row matrix or column matrix and in decreasing or increasing order. It has been shown by Raoelina Andriambololona that the writing in line from Left (L) handside to the Right (R) handside by increasing (i) order (LRi disposition) is more logical and coherent with the basic arithmetic operations rules than the international which starts from the left (L) handside to the right (R) handside by decreasing (d) order (or LRd). For instance, the number 216 written in usual one (LRd disposition) is written as 612 in LRi disposition. Thus, new rules for the addition, subtraction, multiplication and division operation which are homogeneous and consistent with the LRi disposition are established [2][3]. Raoelina Andriambololona's work has led him also to the study of the problem of numeral basis change by using the basis change in a linear space through a passage matrix.
The result thus obtained is simpler and more direct than the usual one utilizing the euclidian successive division [3][4][5][6]. These results are helpful for the construction of supercomputer system. This leads us to design new ALU and code converters which follow new rules established using matrix calculation. In this work, the components of the arithmetic unit such as addition, subtraction, multiplication and division of the proposed ALU are explicited and designed according to LRi disposition. As for the code converters, we only use full adders to perform calculations from the change of basis matrix.
In the present work, the vocabulary "radix" is used to express the basis of a number and any number will be written according to the LRi disposition. For instance, in the radix 10 the number spelt as one hundred twenty five will be written by 521 . Besides, the direction of the basic arithmetic operations starts from the left handside to the right handside according the LRi writing and not always from the right handside to the left handside as in usual operation.

Matrix Representation for Writing Numeration and Numeral Basis Change
The matrix formalism consists to consider the numeral representation of a number as a matrix representation of an intrinsic number in a basis which represents the numeral system. The LRi disposition is shown to be more logical and consistent with the arithmetic operations rules than the usual one which is LRd. According to LRi writing, an intrinsic number N will be written as a row matrix ⋯ ⋯ from left (L) handside to the right (R) handside by increasing (i) order in the basis numeral system with radix with the vector basis [1][2][3].
In the change of radix ′ represented by vector basis ′ where the change of basis matrix is . Therefore, the writing of the number in the radix b' will be Example 1: the number usually spelt as ninety thousand two hundred and thirty one in the usual language is written in the numeral system with the radix 10 = 13209 = 1 3 2 0 9 10 10 10 $ 10 % 10 & Example 2: Convert 74 into binary.

Rules for Addition
These rules are obtained from [4]. We have for two positive integer D and A′ D = K L MDN = ∑ P P PQ We can suppose 6′ > 6 with ′ ≠ 0 for 6 + 1 ≤ 0 ≤ 6′, without loosing in generality.  The integer 6" must be chosen so that " P < for all 0 and in particular for 0 = 6′. In fact we know that the elements " P of the row matrix K L MD + D N must be null or strictly less than : -If P + ′ P < , then we have " P = P + ′ P is the element at the M0 + 1N Y column (from the left handside) of the matrix K L MD + D N. -If P + ′ P > we perform the decompositions " P = PZ Z + ⋯ + P + P with PZ < " P P = PZ Z P + ⋯ + P P + P P without summation on i. The element at the M0 + 1N Y column from the left handside of K L MD + D N is " P = P while the remainders P , P$ , ⋯ are to be brought respectively at the M0 + 2N Y , M0 + 3N Y , ⋯ M0 + \ + 1N Y column (from the left) of K L MD + D N.

Rules for Subtraction
The subtraction of a number D" from a number D is the research of the number D′ such as D" = D + D′ . It is the inverse operation of addition. We can also use the inverse of the addition operation and establish the LRi procedure. The rules can be obtained by analogy with the addition rules. [2] Example 5: subtract 06478 10

Rules for Multiplication
Let be For the explicit calculation, we proceed as for the case of the addition in respecting the places In the calculation of the component MD × D′N P , of the product D × D′, which must be strictly less than b, we must bring the remainder in the partial sum. [2] Example 6: multiply 518 10

Rules for Division
The division is the inverse operation of multiplication. The division of a number A" by a number A is the operation which gives the number A′ such as A" = A × A′ [2]. According to the LRi procedure its rules differ radically from the usual one which starts from the left handside to the right handside by decreasing order LRd. The division starts from left handside by subtracting the least significant digit of the dividend from the divisor. Then we shift the divisor one place to the right and perform again the subtraction. Shifts end to the right where the most significant digit is. If the remainder is still greater than the divisor, we repeat the same operation from the left handside to the right handside until getting remainder less than the divisor. The final result is obtained from the addition of the partial quotients.
The advantages of this method are that it respects the writing numeration and the inverse operation of the multiplication according to the LRi disposition. In addition, we can usually get from the beginning the remainder.

Design of Arithmetic Logic Unit (ALU)
An ALU typically has three input words which are the two input operands, denoted by D and E, and the carry-in input 3 P . The output words are the result c and the carry-out 3 deY . Besides data inputs and outputs, an ALU must have control inputs to specify the operations to be performed. All these data are coded in Binary.
The major parts of ALU are [7][8][9][10]: -Arithmetic block: This block is used to perform four arithmetic operations such as addition, subtraction, multiplication and division; -Logic block: This block is used to perform simple bitwise logic operations such as AND, OR, XOR, XNOR, NAND, NOT and etc; -Multiplexers: These blocks are used to select the appropriate inputs for the arithmetic and logic blocks Here we apply the new rules established for arithmetic using matrix calculation and LRi writing to construct the components of the ALU's arithmetic unit which are addition, subtraction, multiplication and division.

Binary Addition -Subtraction
Let D M , ⋯ , N $ and E M , ⋯ , N $ be two n-bit numbers respectively. As the rules for arithmetic operations are similar for any basis binary, the addition is performed by adding bit by bit the components located at the same row of the matrix representing and bringing an eventual carry at the next row. [2][3][4][5][6][7][8].

Its truth table is shown in the table below
The same way as the n-bits Full Adder we can have the following structure

Binary Multiplication
The multiplication is realized by performing the addition of the partial product with itself shifted 1 bit to the right in each step until n times. Partial product is equal to the multiplicand when the concerned multiplier is 1 if not it is 0 for multiplier set 0. [2][3][4][5][6][7][8] Example 12: 0101 2 by 101 2 As the partial products can be performed with AND logical and their sum by n-bit full adders multiplier circuit performing A 9 B is shown in figure 7 [12]  In order to make this technique straightforward to implement in programmable logic the algorithm below is helpful.

Binary Division
The binary division follows the same rules as the decimal division by starting the subtraction of the dividend by the divisor from the left handside and shifting 1 bit to the right the divisor in every step. The final result is obtained by the sum of the partial quotients. [2] Example 13: division of 1011000 2 by 0100 2 The output D is expressed as Cascading the subtractor-multiplexer modules permits the subtraction of the dividend from the divisor and the generation of the quotient of the division: -The modules first subtract the dividend from the divisor from the least significant bit on the left handside. If the subtraction output borrowing r } is zero, that is, the dividend is greater than the divisor; setting the input control bits c of each module to this value allows the calculation of the division remainders which are the new dividend. Otherwise, if r } = 1, the subtraction result will not be considered and the new dividend will be the same as the previous. After each subtraction operation the divisor is shifted 1 bit to right until the subtraction of the most significant bit. If the dividend is still greater than the divisor we repeat the same process which starts from left until we get dividend less than the divisor. -Each subtraction matches a quotient bit which is the inverse of the output borrowing r } . -The final quotient of the division is the sum of the partial quotients ∑ r } Considering these factors and the new rules established for division, the figure 11 shows the divisor circuit according to the LRi disposition. The following algorithm helps illustrate this method The components of the arithmetic unit are done according to the new rules established for the basic arithmetic operations.

Design of Code Converters
After operation results from the ALU outputs are usually coded in binary. It is sometimes necessary to use the output of one system as the input to another. A conversion circuit should be inserted between the two systems if each uses different codes for the same information. Thus, a code converter is a circuit that makes the two systems compatible even though each uses a different code. This particular section deals with the design of binary to BCD (Binary Coded Decimal) code converter and vice versa using matrix calculation.
For practical purposes decimal system can be represented in BCD or Binary Coded Decimal which represents the 10 decimal digits in terms of binary numbers in arithmetic circuits.  The number 857 will be represented, for instance, by 0001 1010 1110 •€• . In BCD, counting is always performed in radix b 10, that is the greatest digit of the 4-bit binary string is 9 1001 $ . Consequently we have to make correction when exceeding 9 by adding 6 (0110) to generate carry brought to next row. [9] The examination of this example shows that a binary to BCD converter is realized with simple adders and BCD adders. As the digit 1 is less than 0 in the basis change, the binary numbers to be converted are connected to the digits 1 of the operands. We thus propose in figure 12 the design of a binary converter to BCD using matrix calculation. Example

Conclusion
The utilization of matrix calculation illuminates the writing and the disposition of operations on numbers. In addition, as spoken numeration must be consistent with the writing numeration, the writing and reading of numbers have to be performed by increasing order. It supposes changes in the design of computer system. In this paper, circuits for basic arithmetic operations such as adder, subtractor, multiplier and divisor are designed and implemented in the arithmetic unit of the ALU according to the LRi writing and using matrix calculation. We propose design of code converters based on matrix calculation to convert the output code to another code such as binary to BCD code and inversely too. As the quantum computations are consistent with matrix calculations, we think that the application of these algorithms to quantum circuits is also promising.