data/full_repos/permissive/200314387/verilog/alu/test.v
 line:71: before: ">"
1: b'%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:4: Cannot find include file: ./alu.v\n`include "./alu.v" \n         ^~~~~~~~~\n        ... Looked in:\n             data/full_repos/permissive/200314387/verilog/alu,data/full_repos/permissive/200314387/./alu.v\n             data/full_repos/permissive/200314387/verilog/alu,data/full_repos/permissive/200314387/./alu.v.v\n             data/full_repos/permissive/200314387/verilog/alu,data/full_repos/permissive/200314387/./alu.v.sv\n             ./alu.v\n             ./alu.v.v\n             ./alu.v.sv\n             obj_dir/./alu.v\n             obj_dir/./alu.v.v\n             obj_dir/./alu.v.sv\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:5: Cannot find include file: ../lib/assertion.v\n`include "../lib/assertion.v" \n         ^~~~~~~~~~~~~~~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:14: syntax error, unexpected IDENTIFIER, expecting PACKAGE-IDENTIFIER or STRING\n    import alu_ops::*;\n           ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:151: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b0); \n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:151: syntax error, unexpected \',\'\n        `Equals(o, 8\'b0); \n                 ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:162: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b1); \n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:162: syntax error, unexpected \',\'\n        `Equals(o, 8\'b1); \n                 ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:169: Define or directive not defined: \'`Equals\'\n        `Equals(o, 10); \n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:169: syntax error, unexpected \',\'\n        `Equals(o, 10); \n                 ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:178: Define or directive not defined: \'`Equals\'\n        `Equals(o, 2); \n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:178: syntax error, unexpected \',\'\n        `Equals(o, 2); \n                 ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:185: Define or directive not defined: \'`Equals\'\n        `Equals(o, 20); \n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:185: syntax error, unexpected \',\'\n        `Equals(o, 20); \n                 ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:195: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b0)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:195: syntax error, unexpected \',\'\n        `Equals(o, 8\'b0)\n                 ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:201: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:202: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b11111111)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:208: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:209: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b11111110)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:215: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:216: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b10000001)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:217: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'((-128)+1))\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:223: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:224: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b10000000)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:230: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:231: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b10000000)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:237: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:238: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b01111111)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:239: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'((127)))\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:248: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:249: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b11111111)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:256: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:257: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b0)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:263: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:264: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b11111111)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:270: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:271: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b11111110)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:277: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:278: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b10000001)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:279: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'((-128)+1))\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:285: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:286: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b10000000)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:292: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:293: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b10000000)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:299: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:300: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b01111111)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:301: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'((127)))\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:310: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:311: Define or directive not defined: \'`Equals\'\n        `Equals(o, 8\'b0)\n        ^~~~~~~\n%Error: data/full_repos/permissive/200314387/verilog/alu/test.v:316: syntax error, unexpected \';\', expecting IDENTIFIER\n        PD;\n          ^\n%Error: Exiting due to too many errors encountered; --error-limit=50\n'
module test();
    import alu_ops::*;

	logic [7:0] a;
	logic [7:0] b;
	logic [4:0] alu_op;
    logic _flag_c_in;
	wire  [7:0] o;

    wire _flag_c;
    wire _flag_n;
    wire _flag_z;
    wire _flag_o;
    wire _flag_gt;
    wire _flag_lt;
    wire _flag_eq;
    wire _flag_ne;
	
	alu #(.LOG(0)) Alu( .result(o), .a, .b, .alu_op, ._flag_c_in, ._flag_c, ._flag_z, ._flag_n, ._flag_o, ._flag_gt, ._flag_lt, ._flag_eq, ._flag_ne);

    `define MAX_POS (127)
    `define MAX_NEG (-128)


    OpName op_name;
    string s;
    always @* begin
        op_name = aluopNameR(alu_op);
`ifndef verilator





`endif
    end

    `define  BAD_FLAG(X) begin $display("BAD FLAG VALUE FOR X @ line %d", `__LINE__); `FINISH_AND_RETURN(1)  end




    initial begin
        `ifndef verilator

        $dumpfile("dumpfile.vcd");
        $dumpvars(0, test);


        
        `endif
    end

    wire [7:0] C=1;
    wire [7:0] Z=2;
    wire [7:0] N=4;
    wire [7:0] O=8;
    wire [7:0] EQ=16;
    wire [7:0] NE=32;
    wire [7:0] GT=64;
    wire [7:0] LT=128;

    function flagCheck(string flagName, [0:0] _flagValue, [7:0] expectation, bitSelector, string expectationStr);
        reg bitExpected;
        bitExpected = (expectation & bitSelector) == 0;
        flagCheck = (_flagValue == bitExpected);
        if (!flagCheck) $display("FLAG %2s wrong : got=%1b expected=%1b     for test case '%s'      a=%8b(d%-d/h%-2h) b%8b (d%-d/h%-2h) o=%8b (d%-d/h%-2h)", flagName, _flagValue, bitExpected, expectationStr, a,a,a,b,b,b,o,o,o); 
    endfunction

    `define FCMP(EXPECTATION,FLAGNAME,flagname) flagCheck("FLAGNAME", _flag_``flagname``, (EXPECTATION), FLAGNAME, "EXPECTATION")

    `define FLAGS(X) \
        if (!(`FCMP(X, C, c) & `FCMP(X, N, n) & `FCMP(X, Z, z) & `FCMP(X, O, o) & `FCMP(X, EQ, eq) & `FCMP(X, NE, ne) & `FCMP(X, GT, gt) & `FCMP(X, LT, lt))) \
        begin \
            $display("flag error at ", `__LINE__);  \
        `ifndef verilator \
            $finish_and_return(1);  \
        `endif \
        end

    localparam PropDelay=2000;

    function [7:0] to8([7:0] i);
        to8 = i;
    endfunction

    integer testcount=0;

    task PD;
        #PropDelay

        testcount++;
    endtask

    integer count;
    function [7:0] count8();
        count8=8'(count);
    endfunction

    initial begin

        assign a = 1;
        assign b = 2;
        assign _flag_c_in=1;
        assign alu_op = OP_0;
        PD;
        `Equals(o, 8'b0); 
        `FLAGS(NE | Z | LT)




        assign a = 1;
        assign b = 2;
        assign _flag_c_in='x;
        assign alu_op = OP_A;
        PD;
        `Equals(o, 8'b1); 
        `FLAGS(NE | LT)

        assign a = 10;
        assign b = 20;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 10); 
        `FLAGS(NE | LT)


        assign a = 1;
        assign b = 2;
        assign _flag_c_in='x;
        assign alu_op = OP_B;
        PD;
        `Equals(o, 2); 
        `FLAGS(NE | LT)

        assign a = 10;
        assign b = 20;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 20); 
        `FLAGS(NE | LT)



        assign a = 0; 
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_NEGATE_A;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|EQ)

        assign a = 1; 
        assign b = 0;
        assign _flag_c_in = 'x; 
        PD;
        `Equals(o, 8'b11111111)
        `FLAGS(N|NE|GT)

        assign a = 2; 
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b11111110)
        `FLAGS(N|NE|GT)

        assign a = `MAX_POS;
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000001)
        `Equals(o, 8'(`MAX_NEG+1))
        `FLAGS(N|NE|GT)

        assign a = (`MAX_POS+1);
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000000)
        `FLAGS(O|N|NE|GT)

        assign a = (`MAX_NEG);
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000000)
        `FLAGS(O|N|NE|GT)

        assign a = (`MAX_NEG+1);
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b01111111)
        `Equals(o, 8'(`MAX_POS))
        `FLAGS(NE|GT)



        assign a = 0; 
        assign b = 1;
        assign _flag_c_in = 0;
        assign alu_op = OP_NEGATE_B;
        PD;
        `Equals(o, 8'b11111111)
        `FLAGS(N|NE|LT)

        assign a = 0; 
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_NEGATE_B;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|EQ)

        assign a = 0; 
        assign b = 1;
        assign _flag_c_in = 'x; 
        PD;
        `Equals(o, 8'b11111111)
        `FLAGS(N|NE|LT)

        assign a = 0; 
        assign b = 2;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b11111110)
        `FLAGS(N|NE|LT)

        assign a = 0;
        assign b = `MAX_POS;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000001)
        `Equals(o, 8'(`MAX_NEG+1))
        `FLAGS(N|NE|LT)

        assign a = 0;
        assign b = (`MAX_POS+1);
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000000)
        `FLAGS(O|N|NE|LT)

        assign a = 0;
        assign b = (`MAX_NEG);
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000000)
        `FLAGS(O|N|NE|LT)

        assign a = 0;
        assign b = (`MAX_NEG+1);
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b01111111)
        `Equals(o, 8'(`MAX_POS))
        `FLAGS(NE|LT)



        assign a = 0; 
        assign b = 0; 
        assign _flag_c_in = 'x;
        assign alu_op = OP_BA_DIV_10;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|EQ) 

        assign a = 0; 
        assign b = 1;
        PD;
        `Equals(o, 8'd25);
        `FLAGS(NE|LT) 

        assign a = 1; 
        assign b = 10;
        PD;
        `Equals(o, 8'd0);
        `FLAGS(O|Z|NE|LT) 

        assign a = 10; 
        assign b = 2;
        PD;
        `Equals(o, 8'd52);
        `FLAGS(NE|GT) 



        assign a = 0; 
        assign b = 0; 
        assign _flag_c_in = 'x;
        assign alu_op = OP_BA_MOD_10;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|EQ) 

        assign a = 0; 
        assign b = 1;
        PD;
        `Equals(o, 8'd6);
        `FLAGS(NE|LT) 

        assign a = 1; 
        assign b = 10;
        PD;
        `Equals(o, 8'd0);
        `FLAGS(O|Z|NE|LT) 

        assign a = 10; 
        assign b = 2;
        PD;
        `Equals(o, 8'd2);
        `FLAGS(NE|GT) 



        assign a = 0;
        assign b = 0; 
        assign _flag_c_in = 'x;
        assign alu_op = OP_B_MINUS_1;
        PD;
        `Equals(o, 8'b11111111)
        `FLAGS(C|N|EQ) 

        assign a = 0;
        assign b = 1;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|NE|LT) 

        assign a = 0;
        assign b = 127;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 126) 
        `FLAGS(NE|LT) 

        assign a = 0;
        assign b = 128;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 127);
        `FLAGS(O|NE|LT) 

        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 254);
        `Equals(o, 8'(-2));
        `FLAGS(N|NE|LT) 


        assign a = 0;
        assign b = 0; 
        assign _flag_c_in = 'x;
        assign alu_op = OP_B_PLUS_1;
        PD;
        `Equals(o, 1)
        `FLAGS(EQ) 

        assign a = 0;
        assign b = 1;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 2)
        `FLAGS(NE|LT) 

        assign a = 0;
        assign b = 127;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 128) 
        `FLAGS(O|N|NE|LT) 

        assign a = 0;
        assign b = 128;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 129);
        `Equals(o, 8'(-127));
        `FLAGS(N|NE|LT) 

        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 0);
        `FLAGS(C|Z|NE|LT) 




        assign a = 8'b00000000;
        assign b = 8'b00000000;
        assign _flag_c_in='x;
        assign alu_op = OP_A_PLUS_B;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(Z | EQ )

        assign a = 8'b00000000;
        assign b = 8'b11111111;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N | NE|  LT )


        assign a = 8'b10101010;
        assign b = 8'b10000001;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 8'b00101011);
        `FLAGS(C | O | NE | GT)




        assign a = 1;  
        assign b = -5;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 8'(-4));
        `Equals(o, 252);
        `FLAGS(N | NE | LT)


        assign a = 251;
        assign b = 3;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 8'b11111110);
        `FLAGS(N|NE|GT)

        assign a = 1;
        assign b = -1; 
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 0);
        `FLAGS(C|Z|NE|LT) 

        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'd2);
        `FLAGS(EQ) 



        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_MINUS_B;
        PD;
        `Equals(o, 8'b11111110);
        `Equals(o, -8'd2);
        `FLAGS(C|N|NE|LT)

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b00000100);
        `Equals(o, 8'd4);
        `FLAGS(C|NE|LT)


        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'h01);
        `FLAGS(C|NE|LT) 


        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 'x;
        assign alu_op = OP_B_MINUS_A;
        PD;
        `Equals(o, 0);
        `FLAGS(Z|EQ)

        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'd2);
        `FLAGS(NE|LT)  

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'd252);
        `Equals(o, -8'd4);
        `FLAGS(N|NE|LT)   


        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 255);
        `FLAGS(N|NE|LT) 



        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_MINUS_B_SIGNEDMAG;
        PD;
        `Equals(o, 8'b11111110);
        `Equals(o, -8'd2);
        `FLAGS(C|N|NE|LT)

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b00000100);
        `Equals(o, 8'd4);
        `FLAGS(C|NE|GT)


        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'h01);
        `FLAGS(C|NE|GT) 

        assign a = 1;
        assign b = 1; 
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'h00);
        `FLAGS(Z|EQ) 




        assign a = 8'b00000000; 
        assign b = 8'b00000000; 
        assign _flag_c_in=1;
        assign alu_op = OP_A_PLUS_B_PLUS_C;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(Z | EQ)

        assign a = 8'b00000000; 
        assign b = 8'b00000000; 
        assign _flag_c_in=0;
        assign alu_op = OP_A_PLUS_B_PLUS_C;
        PD;
        `Equals(o, 8'b00000001);
        `FLAGS(EQ)


        assign a = 8'b10101010;
        assign b = 8'b10000001;
        assign _flag_c_in=0;
        assign alu_op = OP_A_PLUS_B_PLUS_C;
        PD;
        `Equals(o, 8'b00101100);
        `FLAGS(C | O | NE | GT)




        assign a = 1;  
        assign b = -5;
        assign _flag_c_in=0;
        PD;
        `Equals(o, 8'(-3));
        `Equals(o, 8'(253));
        `FLAGS(N | NE | LT)


        assign a = 251;
        assign b = 3;
        assign _flag_c_in=0;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N|NE|GT)

        assign a = 1;
        assign b = -1; 
        assign _flag_c_in =0;
        PD;
        `Equals(o, 1);
        `FLAGS(C|NE|LT) 

        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 1;
        PD;
        `Equals(o, 8'd2);
        `FLAGS(EQ) 





        assign a = 1;
        assign b = 0;
        assign _flag_c_in = 1; 
        assign alu_op = OP_A_MINUS_B_MINUS_C; 
        PD;
        `Equals(o, 1);
        `FLAGS(NE|GT)
        assign a = 1;

        assign b = 1;
        assign _flag_c_in = 1; 
        PD;
        `Equals(o, 0);
        `FLAGS(Z|EQ)

        assign b = 1;
        assign _flag_c_in = 0; 
        PD;
        `Equals(o, 8'hff);
        `FLAGS(C|N|EQ)



        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'b11111101);
        `Equals(o, -8'd3);
        `FLAGS(C|N|NE|LT)

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'd3);
        `FLAGS(C|NE|LT)




        assign a = 0;
        assign b = (`MAX_POS-1);
        assign _flag_c_in = 1;
        PD;
        `Equals(o, 8'b10000010);
        `FLAGS(C|N|NE|LT)

        assign a = 0;
        assign b = `MAX_POS;
        assign _flag_c_in = 1;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(C|N|NE|LT)

        assign a = 0;
        assign b = `MAX_POS;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'b10000000);
        `FLAGS(C|N|NE|LT)


        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 0;
        assign alu_op = OP_B_MINUS_A_MINUS_C;
        PD;
        `Equals(o, 8'd255);
        `FLAGS(C|N|EQ)

        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'd1);
        `FLAGS(NE|LT)  

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'd251);
        `Equals(o, -8'd5); 
        `FLAGS(N|NE|LT)   


        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'd254);
        `FLAGS(N|NE|LT) 

        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 1; 
        PD;
        `Equals(o, 8'd0);
        `FLAGS(Z|EQ)



        assign a = 8'hff;
        assign b = 8'h00;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_TIMES_B_HI;
        PD;
        `Equals(o, 8'h00);
        `FLAGS(Z|NE|GT)  

        assign a = 8'h0F;
        assign b = 8'h0F;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b00000000);
        `Equals(_flag_c, 1'b1);
        `FLAGS(EQ|Z) 

        assign a = 8'hFF;
        assign b = 8'hFF;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'hFE);
        `FLAGS(N|EQ) 

        assign a = 8'hF0;
        assign b = 8'h10;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'h0F);
        `FLAGS(NE|GT) 


        assign a = 8'hff;
        assign b = 8'h00;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_TIMES_B_LO;
        PD;
        `Equals(o, 8'h00);
        `FLAGS(Z|NE|GT)  

        assign a = 8'h0f;
        assign b = 8'h0f;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'he1);
        `FLAGS(N|EQ)  

        assign a = 8'hFF;
        assign b = 8'hFF;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'h01);
        `FLAGS(C|EQ)



        assign a = 8'haa;
        assign b = 8'h02;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_DIV_B;
        PD;
        `Equals(o, 8'h55);
        `FLAGS(NE|GT)  

        assign a = 8'haa;
        assign b = 8'h00;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b0);
        `FLAGS(O|Z|NE|GT)



        assign a = 8'd7;
        assign b = 8'd2;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_MOD_B;
        PD;
        `Equals(o, 8'd1);
        `FLAGS(NE|GT) 

        assign a = 8'haa;
        assign b = 8'h00;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b0);
        `FLAGS(O|Z|NE|GT)


        assign a = 8'b10000010;
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_LSL_B;
        PD;
        `Equals(o, 8'b10000010);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b00000100);
        `FLAGS(O|C|NE|GT)  

        assign b = 6;
        PD;
        `Equals(o, 8'b10000000);
        `FLAGS(N|NE|GT)  

        assign b = 0;
        PD;
        `Equals(o, 8'b10000010);
        `FLAGS(N|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b00001000);
        `FLAGS(O|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  

        assign b = 9;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  

        assign b = 10;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  



        assign a = 8'b10000001;
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_LSR_B;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b01000000);
        `FLAGS(O|C|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b00100000);
        `FLAGS(O|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|C|Z|NE|GT)  

        assign b = 9;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  

        assign b = 10;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  



        assign a = 8'b10000001;
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_ASR_B;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b11000000);
        `FLAGS(C|N|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b11100000);
        `FLAGS(N|NE|GT)  

        assign b = 6;
        PD;
        `Equals(o, 8'b11111110);
        `FLAGS(N|NE|GT)  

        assign b = 7;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(C|N|NE|GT)  

        assign b = 9;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(C|N|NE|GT)  

        assign b = 10;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(C|N|NE|GT)  


        assign a = 8'b00000100;
        assign b = 2;
        PD;
        `Equals(o, 8'b00000001);
        `FLAGS(NE|GT)  

        assign b = 3;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(C|Z|NE|GT)  




        assign a = 8'b10000001;
        assign b = 0;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_RLC_B;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b00000011);
        `FLAGS(C|O|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b00000110);
        `FLAGS(O|NE|GT)  

        assign b = 3;
        PD;
        `Equals(o, 8'b00001100);
        `FLAGS(O|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b10000001); 
        `FLAGS(C|N|NE|GT)  



        assign a = 8'b10000001;
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_RRC_B;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b11000000);
        `FLAGS(C|N|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b01100000);
        `FLAGS(O|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(C|N|NE|GT)  



        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_A_AND_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b10000000);
        `FLAGS(N|NE|GT)

        assign b = 8'b11111111;
        PD;
        `Equals(o, 8'b11010101);
        `FLAGS(N|NE|LT)

        assign b = 8'b00000000;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(Z|NE|GT)


        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_A_OR_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b11110101);
        `FLAGS(N|NE|GT)

        assign b = 8'b11111111;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N|NE|LT)

        assign b = 8'b00000000;
        PD;
        `Equals(o, 8'b11010101);
        `FLAGS(N|NE|GT)


        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_A_XOR_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b01110101);
        `FLAGS(NE|GT)

        assign b = 8'b11111111;
        PD;
        `Equals(o, 8'b00101010);
        `FLAGS(NE|LT)

        assign b = 8'b00000000;
        PD;
        `Equals(o, 8'b11010101);
        `FLAGS(N|NE|GT)


        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_A_NAND_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b01111111);
        `FLAGS(NE|GT)

        assign a = 8'b11010101;
        assign b = 8'b11111111;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b00101010);
        `FLAGS(NE|LT)

        assign a = 8'b11010101;
        assign b = 8'b00000000;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N|NE|GT)



        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_NOT_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b01011111);
        `FLAGS(NE|GT)


        assign a = 8'h29; 
        assign b = 8'h32; 
        assign alu_op = OP_A_PLUS_B_BCD;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'h61);
        `FLAGS(NE|LT)

        assign a = 8'h99; 
        assign b = 8'h00; 
        PD;
        `Equals(o, 8'h99);
        `FLAGS(NE|GT) 

        assign a = 8'h99; 
        assign b = 8'h01; 
        PD;
        `Equals(o, 8'h00);
        `FLAGS(C|Z|NE|GT)

        assign a = 8'h99; 
        assign b = 8'h99; 
        PD;
        `Equals(o, 8'h98);
        `FLAGS(C|EQ)


        assign a = 8'haa;
        assign b = 8'h01; 
        PD;
        `Equals(o, 8'h11);
        `FLAGS(C|NE|GT)

        assign a = 8'h00; 
        assign b = 8'h0a;
        PD;
        `Equals(o, 8'h10);
        `FLAGS(NE|LT) 

        assign a = 8'haa;
        assign b = 8'h11;
        PD;
        `Equals(o, 8'h21);
        `FLAGS(C|NE|GT) 



        assign a = 8'h70; 
        assign b = 8'h25; 
        assign alu_op = OP_A_MINUS_B_BCD;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'h45);
        `FLAGS(NE|GT)

        assign a = 8'h00; 
        assign b = 8'h01; 
        PD;
        `Equals(o, 8'h99);
        `FLAGS(C|N|NE|LT)


        assign a = 8'haa; 
        assign b = 8'hff; 
        PD;
        `Equals(o, 8'h45);
        `FLAGS(C|N|NE|LT) 



        PD;
        $display("---");
        $display("done : %d tests", testcount);
        

    end
endmodule
module test();

    import alu_ops::*;

	logic [7:0] a;
	logic [7:0] b;
	logic [4:0] alu_op;
    logic _flag_c_in;
	wire  [7:0] o;

    wire _flag_c;
    wire _flag_n;
    wire _flag_z;
    wire _flag_o;
    wire _flag_gt;
    wire _flag_lt;
    wire _flag_eq;
    wire _flag_ne;
	
	alu #(.LOG(0)) Alu( .result(o), .a, .b, .alu_op, ._flag_c_in, ._flag_c, ._flag_z, ._flag_n, ._flag_o, ._flag_gt, ._flag_lt, ._flag_eq, ._flag_ne);

    `define MAX_POS (127)
    `define MAX_NEG (-128)


    OpName op_name;
    string s;
    always @* begin
        op_name = aluopNameR(alu_op);
`ifndef verilator





`endif
    end

    `define  BAD_FLAG(X) begin $display("BAD FLAG VALUE FOR X @ line %d", `__LINE__); `FINISH_AND_RETURN(1)  end




    initial begin
        `ifndef verilator

        $dumpfile("dumpfile.vcd");
        $dumpvars(0, test);


        
        `endif
    end

    wire [7:0] C=1;
    wire [7:0] Z=2;
    wire [7:0] N=4;
    wire [7:0] O=8;
    wire [7:0] EQ=16;
    wire [7:0] NE=32;
    wire [7:0] GT=64;
    wire [7:0] LT=128;

    function flagCheck(string flagName, [0:0] _flagValue, [7:0] expectation, bitSelector, string expectationStr);
        reg bitExpected;
        bitExpected = (expectation & bitSelector) == 0;
        flagCheck = (_flagValue == bitExpected);
        if (!flagCheck) $display("FLAG %2s wrong : got=%1b expected=%1b     for test case '%s'      a=%8b(d%-d/h%-2h) b%8b (d%-d/h%-2h) o=%8b (d%-d/h%-2h)", flagName, _flagValue, bitExpected, expectationStr, a,a,a,b,b,b,o,o,o); 
    endfunction

    `define FCMP(EXPECTATION,FLAGNAME,flagname) flagCheck("FLAGNAME", _flag_``flagname``, (EXPECTATION), FLAGNAME, "EXPECTATION")

    `define FLAGS(X) \
        if (!(`FCMP(X, C, c) & `FCMP(X, N, n) & `FCMP(X, Z, z) & `FCMP(X, O, o) & `FCMP(X, EQ, eq) & `FCMP(X, NE, ne) & `FCMP(X, GT, gt) & `FCMP(X, LT, lt))) \
        begin \
            $display("flag error at ", `__LINE__);  \
        `ifndef verilator \
            $finish_and_return(1);  \
        `endif \
        end

    localparam PropDelay=2000;

    function [7:0] to8([7:0] i);
        to8 = i;
    endfunction

    integer testcount=0;

    task PD;
        #PropDelay

        testcount++;
    endtask

    integer count;
    function [7:0] count8();
        count8=8'(count);
    endfunction

    initial begin

        assign a = 1;
        assign b = 2;
        assign _flag_c_in=1;
        assign alu_op = OP_0;
        PD;
        `Equals(o, 8'b0); 
        `FLAGS(NE | Z | LT)




        assign a = 1;
        assign b = 2;
        assign _flag_c_in='x;
        assign alu_op = OP_A;
        PD;
        `Equals(o, 8'b1); 
        `FLAGS(NE | LT)

        assign a = 10;
        assign b = 20;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 10); 
        `FLAGS(NE | LT)


        assign a = 1;
        assign b = 2;
        assign _flag_c_in='x;
        assign alu_op = OP_B;
        PD;
        `Equals(o, 2); 
        `FLAGS(NE | LT)

        assign a = 10;
        assign b = 20;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 20); 
        `FLAGS(NE | LT)



        assign a = 0; 
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_NEGATE_A;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|EQ)

        assign a = 1; 
        assign b = 0;
        assign _flag_c_in = 'x; 
        PD;
        `Equals(o, 8'b11111111)
        `FLAGS(N|NE|GT)

        assign a = 2; 
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b11111110)
        `FLAGS(N|NE|GT)

        assign a = `MAX_POS;
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000001)
        `Equals(o, 8'(`MAX_NEG+1))
        `FLAGS(N|NE|GT)

        assign a = (`MAX_POS+1);
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000000)
        `FLAGS(O|N|NE|GT)

        assign a = (`MAX_NEG);
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000000)
        `FLAGS(O|N|NE|GT)

        assign a = (`MAX_NEG+1);
        assign b = 0;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b01111111)
        `Equals(o, 8'(`MAX_POS))
        `FLAGS(NE|GT)



        assign a = 0; 
        assign b = 1;
        assign _flag_c_in = 0;
        assign alu_op = OP_NEGATE_B;
        PD;
        `Equals(o, 8'b11111111)
        `FLAGS(N|NE|LT)

        assign a = 0; 
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_NEGATE_B;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|EQ)

        assign a = 0; 
        assign b = 1;
        assign _flag_c_in = 'x; 
        PD;
        `Equals(o, 8'b11111111)
        `FLAGS(N|NE|LT)

        assign a = 0; 
        assign b = 2;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b11111110)
        `FLAGS(N|NE|LT)

        assign a = 0;
        assign b = `MAX_POS;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000001)
        `Equals(o, 8'(`MAX_NEG+1))
        `FLAGS(N|NE|LT)

        assign a = 0;
        assign b = (`MAX_POS+1);
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000000)
        `FLAGS(O|N|NE|LT)

        assign a = 0;
        assign b = (`MAX_NEG);
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b10000000)
        `FLAGS(O|N|NE|LT)

        assign a = 0;
        assign b = (`MAX_NEG+1);
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b01111111)
        `Equals(o, 8'(`MAX_POS))
        `FLAGS(NE|LT)



        assign a = 0; 
        assign b = 0; 
        assign _flag_c_in = 'x;
        assign alu_op = OP_BA_DIV_10;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|EQ) 

        assign a = 0; 
        assign b = 1;
        PD;
        `Equals(o, 8'd25);
        `FLAGS(NE|LT) 

        assign a = 1; 
        assign b = 10;
        PD;
        `Equals(o, 8'd0);
        `FLAGS(O|Z|NE|LT) 

        assign a = 10; 
        assign b = 2;
        PD;
        `Equals(o, 8'd52);
        `FLAGS(NE|GT) 



        assign a = 0; 
        assign b = 0; 
        assign _flag_c_in = 'x;
        assign alu_op = OP_BA_MOD_10;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|EQ) 

        assign a = 0; 
        assign b = 1;
        PD;
        `Equals(o, 8'd6);
        `FLAGS(NE|LT) 

        assign a = 1; 
        assign b = 10;
        PD;
        `Equals(o, 8'd0);
        `FLAGS(O|Z|NE|LT) 

        assign a = 10; 
        assign b = 2;
        PD;
        `Equals(o, 8'd2);
        `FLAGS(NE|GT) 



        assign a = 0;
        assign b = 0; 
        assign _flag_c_in = 'x;
        assign alu_op = OP_B_MINUS_1;
        PD;
        `Equals(o, 8'b11111111)
        `FLAGS(C|N|EQ) 

        assign a = 0;
        assign b = 1;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b0)
        `FLAGS(Z|NE|LT) 

        assign a = 0;
        assign b = 127;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 126) 
        `FLAGS(NE|LT) 

        assign a = 0;
        assign b = 128;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 127);
        `FLAGS(O|NE|LT) 

        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 254);
        `Equals(o, 8'(-2));
        `FLAGS(N|NE|LT) 


        assign a = 0;
        assign b = 0; 
        assign _flag_c_in = 'x;
        assign alu_op = OP_B_PLUS_1;
        PD;
        `Equals(o, 1)
        `FLAGS(EQ) 

        assign a = 0;
        assign b = 1;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 2)
        `FLAGS(NE|LT) 

        assign a = 0;
        assign b = 127;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 128) 
        `FLAGS(O|N|NE|LT) 

        assign a = 0;
        assign b = 128;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 129);
        `Equals(o, 8'(-127));
        `FLAGS(N|NE|LT) 

        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 0);
        `FLAGS(C|Z|NE|LT) 




        assign a = 8'b00000000;
        assign b = 8'b00000000;
        assign _flag_c_in='x;
        assign alu_op = OP_A_PLUS_B;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(Z | EQ )

        assign a = 8'b00000000;
        assign b = 8'b11111111;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N | NE|  LT )


        assign a = 8'b10101010;
        assign b = 8'b10000001;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 8'b00101011);
        `FLAGS(C | O | NE | GT)




        assign a = 1;  
        assign b = -5;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 8'(-4));
        `Equals(o, 252);
        `FLAGS(N | NE | LT)


        assign a = 251;
        assign b = 3;
        assign _flag_c_in='x;
        PD;
        `Equals(o, 8'b11111110);
        `FLAGS(N|NE|GT)

        assign a = 1;
        assign b = -1; 
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 0);
        `FLAGS(C|Z|NE|LT) 

        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'd2);
        `FLAGS(EQ) 



        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_MINUS_B;
        PD;
        `Equals(o, 8'b11111110);
        `Equals(o, -8'd2);
        `FLAGS(C|N|NE|LT)

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b00000100);
        `Equals(o, 8'd4);
        `FLAGS(C|NE|LT)


        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'h01);
        `FLAGS(C|NE|LT) 


        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 'x;
        assign alu_op = OP_B_MINUS_A;
        PD;
        `Equals(o, 0);
        `FLAGS(Z|EQ)

        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'd2);
        `FLAGS(NE|LT)  

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'd252);
        `Equals(o, -8'd4);
        `FLAGS(N|NE|LT)   


        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 255);
        `FLAGS(N|NE|LT) 



        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_MINUS_B_SIGNEDMAG;
        PD;
        `Equals(o, 8'b11111110);
        `Equals(o, -8'd2);
        `FLAGS(C|N|NE|LT)

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'b00000100);
        `Equals(o, 8'd4);
        `FLAGS(C|NE|GT)


        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'h01);
        `FLAGS(C|NE|GT) 

        assign a = 1;
        assign b = 1; 
        assign _flag_c_in = 'x;
        PD;
        `Equals(o, 8'h00);
        `FLAGS(Z|EQ) 




        assign a = 8'b00000000; 
        assign b = 8'b00000000; 
        assign _flag_c_in=1;
        assign alu_op = OP_A_PLUS_B_PLUS_C;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(Z | EQ)

        assign a = 8'b00000000; 
        assign b = 8'b00000000; 
        assign _flag_c_in=0;
        assign alu_op = OP_A_PLUS_B_PLUS_C;
        PD;
        `Equals(o, 8'b00000001);
        `FLAGS(EQ)


        assign a = 8'b10101010;
        assign b = 8'b10000001;
        assign _flag_c_in=0;
        assign alu_op = OP_A_PLUS_B_PLUS_C;
        PD;
        `Equals(o, 8'b00101100);
        `FLAGS(C | O | NE | GT)




        assign a = 1;  
        assign b = -5;
        assign _flag_c_in=0;
        PD;
        `Equals(o, 8'(-3));
        `Equals(o, 8'(253));
        `FLAGS(N | NE | LT)


        assign a = 251;
        assign b = 3;
        assign _flag_c_in=0;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N|NE|GT)

        assign a = 1;
        assign b = -1; 
        assign _flag_c_in =0;
        PD;
        `Equals(o, 1);
        `FLAGS(C|NE|LT) 

        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 1;
        PD;
        `Equals(o, 8'd2);
        `FLAGS(EQ) 





        assign a = 1;
        assign b = 0;
        assign _flag_c_in = 1; 
        assign alu_op = OP_A_MINUS_B_MINUS_C; 
        PD;
        `Equals(o, 1);
        `FLAGS(NE|GT)
        assign a = 1;

        assign b = 1;
        assign _flag_c_in = 1; 
        PD;
        `Equals(o, 0);
        `FLAGS(Z|EQ)

        assign b = 1;
        assign _flag_c_in = 0; 
        PD;
        `Equals(o, 8'hff);
        `FLAGS(C|N|EQ)



        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'b11111101);
        `Equals(o, -8'd3);
        `FLAGS(C|N|NE|LT)

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'd3);
        `FLAGS(C|NE|LT)




        assign a = 0;
        assign b = (`MAX_POS-1);
        assign _flag_c_in = 1;
        PD;
        `Equals(o, 8'b10000010);
        `FLAGS(C|N|NE|LT)

        assign a = 0;
        assign b = `MAX_POS;
        assign _flag_c_in = 1;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(C|N|NE|LT)

        assign a = 0;
        assign b = `MAX_POS;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'b10000000);
        `FLAGS(C|N|NE|LT)


        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 0;
        assign alu_op = OP_B_MINUS_A_MINUS_C;
        PD;
        `Equals(o, 8'd255);
        `FLAGS(C|N|EQ)

        assign a = 1;
        assign b = 3;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'd1);
        `FLAGS(NE|LT)  

        assign a = 1;
        assign b = -3;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'd251);
        `Equals(o, -8'd5); 
        `FLAGS(N|NE|LT)   


        assign a = 0;
        assign b = 255;
        assign _flag_c_in = 0;
        PD;
        `Equals(o, 8'd254);
        `FLAGS(N|NE|LT) 

        assign a = 1;
        assign b = 1;
        assign _flag_c_in = 1; 
        PD;
        `Equals(o, 8'd0);
        `FLAGS(Z|EQ)



        assign a = 8'hff;
        assign b = 8'h00;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_TIMES_B_HI;
        PD;
        `Equals(o, 8'h00);
        `FLAGS(Z|NE|GT)  

        assign a = 8'h0F;
        assign b = 8'h0F;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b00000000);
        `Equals(_flag_c, 1'b1);
        `FLAGS(EQ|Z) 

        assign a = 8'hFF;
        assign b = 8'hFF;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'hFE);
        `FLAGS(N|EQ) 

        assign a = 8'hF0;
        assign b = 8'h10;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'h0F);
        `FLAGS(NE|GT) 


        assign a = 8'hff;
        assign b = 8'h00;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_TIMES_B_LO;
        PD;
        `Equals(o, 8'h00);
        `FLAGS(Z|NE|GT)  

        assign a = 8'h0f;
        assign b = 8'h0f;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'he1);
        `FLAGS(N|EQ)  

        assign a = 8'hFF;
        assign b = 8'hFF;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'h01);
        `FLAGS(C|EQ)



        assign a = 8'haa;
        assign b = 8'h02;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_DIV_B;
        PD;
        `Equals(o, 8'h55);
        `FLAGS(NE|GT)  

        assign a = 8'haa;
        assign b = 8'h00;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b0);
        `FLAGS(O|Z|NE|GT)



        assign a = 8'd7;
        assign b = 8'd2;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_MOD_B;
        PD;
        `Equals(o, 8'd1);
        `FLAGS(NE|GT) 

        assign a = 8'haa;
        assign b = 8'h00;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b0);
        `FLAGS(O|Z|NE|GT)


        assign a = 8'b10000010;
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_LSL_B;
        PD;
        `Equals(o, 8'b10000010);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b00000100);
        `FLAGS(O|C|NE|GT)  

        assign b = 6;
        PD;
        `Equals(o, 8'b10000000);
        `FLAGS(N|NE|GT)  

        assign b = 0;
        PD;
        `Equals(o, 8'b10000010);
        `FLAGS(N|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b00001000);
        `FLAGS(O|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  

        assign b = 9;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  

        assign b = 10;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  



        assign a = 8'b10000001;
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_LSR_B;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b01000000);
        `FLAGS(O|C|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b00100000);
        `FLAGS(O|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|C|Z|NE|GT)  

        assign b = 9;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  

        assign b = 10;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(O|Z|NE|GT)  



        assign a = 8'b10000001;
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_ASR_B;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b11000000);
        `FLAGS(C|N|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b11100000);
        `FLAGS(N|NE|GT)  

        assign b = 6;
        PD;
        `Equals(o, 8'b11111110);
        `FLAGS(N|NE|GT)  

        assign b = 7;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(C|N|NE|GT)  

        assign b = 9;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(C|N|NE|GT)  

        assign b = 10;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(C|N|NE|GT)  


        assign a = 8'b00000100;
        assign b = 2;
        PD;
        `Equals(o, 8'b00000001);
        `FLAGS(NE|GT)  

        assign b = 3;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(C|Z|NE|GT)  




        assign a = 8'b10000001;
        assign b = 0;
        assign _flag_c_in = 1'bx;
        assign alu_op = OP_A_RLC_B;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b00000011);
        `FLAGS(C|O|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b00000110);
        `FLAGS(O|NE|GT)  

        assign b = 3;
        PD;
        `Equals(o, 8'b00001100);
        `FLAGS(O|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b10000001); 
        `FLAGS(C|N|NE|GT)  



        assign a = 8'b10000001;
        assign b = 0;
        assign _flag_c_in = 'x;
        assign alu_op = OP_A_RRC_B;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(N|NE|GT)  

        assign b = 1;
        PD;
        `Equals(o, 8'b11000000);
        `FLAGS(C|N|NE|GT)  

        assign b = 2;
        PD;
        `Equals(o, 8'b01100000);
        `FLAGS(O|NE|GT)  

        assign b = 8;
        PD;
        `Equals(o, 8'b10000001);
        `FLAGS(C|N|NE|GT)  



        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_A_AND_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b10000000);
        `FLAGS(N|NE|GT)

        assign b = 8'b11111111;
        PD;
        `Equals(o, 8'b11010101);
        `FLAGS(N|NE|LT)

        assign b = 8'b00000000;
        PD;
        `Equals(o, 8'b00000000);
        `FLAGS(Z|NE|GT)


        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_A_OR_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b11110101);
        `FLAGS(N|NE|GT)

        assign b = 8'b11111111;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N|NE|LT)

        assign b = 8'b00000000;
        PD;
        `Equals(o, 8'b11010101);
        `FLAGS(N|NE|GT)


        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_A_XOR_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b01110101);
        `FLAGS(NE|GT)

        assign b = 8'b11111111;
        PD;
        `Equals(o, 8'b00101010);
        `FLAGS(NE|LT)

        assign b = 8'b00000000;
        PD;
        `Equals(o, 8'b11010101);
        `FLAGS(N|NE|GT)


        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_A_NAND_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b01111111);
        `FLAGS(NE|GT)

        assign a = 8'b11010101;
        assign b = 8'b11111111;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b00101010);
        `FLAGS(NE|LT)

        assign a = 8'b11010101;
        assign b = 8'b00000000;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b11111111);
        `FLAGS(N|NE|GT)



        assign a = 8'b11010101;
        assign b = 8'b10100000;
        assign alu_op = OP_NOT_B;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'b01011111);
        `FLAGS(NE|GT)


        assign a = 8'h29; 
        assign b = 8'h32; 
        assign alu_op = OP_A_PLUS_B_BCD;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'h61);
        `FLAGS(NE|LT)

        assign a = 8'h99; 
        assign b = 8'h00; 
        PD;
        `Equals(o, 8'h99);
        `FLAGS(NE|GT) 

        assign a = 8'h99; 
        assign b = 8'h01; 
        PD;
        `Equals(o, 8'h00);
        `FLAGS(C|Z|NE|GT)

        assign a = 8'h99; 
        assign b = 8'h99; 
        PD;
        `Equals(o, 8'h98);
        `FLAGS(C|EQ)


        assign a = 8'haa;
        assign b = 8'h01; 
        PD;
        `Equals(o, 8'h11);
        `FLAGS(C|NE|GT)

        assign a = 8'h00; 
        assign b = 8'h0a;
        PD;
        `Equals(o, 8'h10);
        `FLAGS(NE|LT) 

        assign a = 8'haa;
        assign b = 8'h11;
        PD;
        `Equals(o, 8'h21);
        `FLAGS(C|NE|GT) 



        assign a = 8'h70; 
        assign b = 8'h25; 
        assign alu_op = OP_A_MINUS_B_BCD;
        assign _flag_c_in = 1'bx;
        PD;
        `Equals(o, 8'h45);
        `FLAGS(NE|GT)

        assign a = 8'h00; 
        assign b = 8'h01; 
        PD;
        `Equals(o, 8'h99);
        `FLAGS(C|N|NE|LT)


        assign a = 8'haa; 
        assign b = 8'hff; 
        PD;
        `Equals(o, 8'h45);
        `FLAGS(C|N|NE|LT) 



        PD;
        $display("---");
        $display("done : %d tests", testcount);
        

    end
endmodule