//---------------------------------------------------------------- // divtest.cpp // // This program uses "inline assembly language" to test our // external 'softdivb' software division function, based on // comparing all its possible outputs with results produced // when the same divisions are performed in hardware. Note // that only those cases in which a "divide overlow" cannot // occur are tested here. // // compile using: $ g++ divtest.cpp div_bl.o -o divtest // // programmer: ALLAN CRUSE // written on: 12 OCT 2003 // revised on: 22 FEB 2005 //---------------------------------------------------------------- #include // needed for printf() extern void softdivb( 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 softdivb "); 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 ); }