//---------------------------------------------------------------- // divtest.cpp // // This program uses "inline assembly language" to test the // external software division routine named 'div_bl', based // on comparing all of its possible cases with results from // performing the same divisions in hardware. Note that we // test here only those cases for which no "divide overlow" // can occur. // // compile using: $ gcc divtest.cpp div_bl.o -o divtest // // programmer: ALLAN CRUSE // written on: 12 OCT 2003 //---------------------------------------------------------------- #include // needed for printf() extern void div_bl( void ); // function symbol unsigned int a, b, c, d; // global variables int main( void ) { printf( "\n---a--- --b-- hardware software \n" ); // iterate over all possible combinations // of 16-bit dividend and 8-bit divisor int errors = 0; for (a = 0; a < 65536; a++) { for (b = 0; b < 256; b++) { printf( " a=%04X b=%02X ", a, b ); if ( ( a >> 8 ) < b ) { asm(" movw a, %ax "); asm(" movb b, %bl "); asm(" divb %bl "); asm(" movw %ax, d "); asm(" movw a, %ax "); asm(" movb b, %bl "); asm(" call div_bl "); asm(" movw %ax, c "); printf( " c=%04X d=%04X ", c, d ); if ( c != d ) ++errors; if ( c == d ) printf( " ok \n" ); else printf( "<--- error #%d \n", errors ); } else printf( " (divide overflow) \n" ); } } printf( "\n\tNumber of errors = %d \n\n", errors ); }