// Test the binary division library
import "print.kc"
import "division.kc"

void main() {
    print_cls();
    test_8u();
    test_16u();
}

void test_16u() {
    word[] dividends = { $ffff, $ffff, $ffff, $ffff, $ffff, $ffff};
    word[] divisors = { 5, 7, 11, 13, 17, 19 };
    for( byte i=0;i!=12;i=i+2) {
        word dividend = dividends[i];
        word divisor = divisors[i];
        word res = div16u(dividend, divisor);
        print_word(dividend);
        print_str(" / @");
        print_word(divisor);
        print_str(" = @");
        print_word(res);
        print_str(" @");
        print_word(rem16u);
        print_ln();
    }
}

void test_8u() {
    byte[] dividends = { 255, 255, 255, 255, 255, 255};
    byte[] divisors = { 5, 7, 11, 13, 17, 19 };
    byte rem = 0;
    for( byte i: 0..5 ) {
        byte dividend = dividends[i];
        byte divisor = divisors[i];
        byte res = div8u(dividend, divisor, &rem);
        print_byte(dividend);
        print_str(" / @");
        print_byte(divisor);
        print_str(" = @");
        print_byte(res);
        print_str(" @");
        print_byte(rem);
        print_ln();
    }
}
