6 * 6 = 36d (0x24):

asciilifeform's sneakpreview (yet unreleased) of his Finite Field Arithmetic [FFA] prompted me to learn Ada, and to build a small test driver to become familiar with the library and its inner workings.


My goal was simply instantiate the `ffa' generic package and then utilize its routines to compute 6 * 6, then dump the results with its built-in dumper.

Without further ado, what follows is the code that I created in a file named 'ffa_test.adb'!


with ffa;

procedure FFA_Test is
        type Word is mod 2**64;

        package Foo is new ffa(Word => Word);
        WB  : Foo.WBool;
        A   : Word;
        B   : Word;

        BNA : Foo.FZ(8);
        BNB : Foo.FZ(8);
        BNP : Foo.FZ(8);

        procedure Mult(
                A   : in Word;
                B   : in Word;
                BNA : out Foo.FZ;
                BNB : out Foo.FZ;
                BNP : out Foo.FZ
        ) is
        begin
                Foo.FZ_Set(BNA, A);
                Foo.FZ_Set(BNB, B);
                Foo.FZ_Mul(BNA, BNB, BNP, WB);
                Foo.Dump(BNP);
        end Mult;

begin
        A := 6;
        B := 6;
        Mult(A, B, BNA, BNB, BNP);
end FFA_Test;
    

Compile:

Once my code was complete, I simply compiled my procedure along with the ffa library as follows:

gnatmake ffa ffa_test

Execute:

Here's an example of me executing the compiled binary:

./ffa_test 
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024

As you can see from above, the result is correct as 6 * 6 = 36 (0x24 in hex)!