//---------------------------------------------------------------- // multest.cpp // // This program uses "inline assembly language" to test our // external 'softmulb' software multiplication function, by // comparing all its possible outputs with results produced // when the same multiplications are performed in hardware. // // compile using: $ g++ multest.cpp softmulb.s -o multest // // programmer: ALLAN CRUSE // written on: 12 OCT 2003 // revised on: 08 MAR 2006 //---------------------------------------------------------------- #include // needed for printf() extern void softmulb( 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 pairs of 8-bit values int errors = 0; for (a = 0; a < 256; a++) { for (b = 0; b < 256; b++) { printf( " a=%02X b=%02X ", a, b ); asm(" movb a, %al "); asm(" movb b, %bl "); asm(" mulb %bl "); asm(" movw %ax, d "); asm(" movb a, %al "); asm(" movb b, %bl "); asm(" call softmulb "); 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 ); } } printf( "\n\tNumber of errors = %d \n\n", errors ); }