//----------------------------------------------------------- // MultDiv Library Demo // Demonstrates multiplication and division routines //----------------------------------------------------------- #INCLUDE #INCLUDE #INCLUDE #INCLUDE #PRAGMA _P_USE_CBM_STRINGS 1 GOTO start WORD high BYTE i //----------------------------------------------------------- // Wait for key //----------------------------------------------------------- FUNC wait_key BYTE key WHILE 1 key = PEEK $c5 IF key = 64 BREAK ENDIF WEND WHILE 1 key = PEEK $c5 IF key != 64 BREAK ENDIF WEND POKE $c6 WITH 0 FEND //----------------------------------------------------------- // Main demo //----------------------------------------------------------- FUNC main lib_cbmio_cls() lib_cbmio_printlf("multdivlib demo") lib_cbmio_printlf("===============") lib_cbmio_lf() WORD a WORD b //----------------------------------------- // Test 1: mult - 123 * 456 (16-bit result) // io:lib_multdiv_acc is input/output // result in lib_multdiv_acc, high in lib_multdiv_ext //----------------------------------------- lib_cbmio_printlf("lib_multdiv_mult: 123 * 456 =") a = 123 b = 456 lib_multdiv_mult(a, b) lib_cbmio_print(" result: ") lib_cbmio_hexoutw(lib_multdiv_acc) lib_cbmio_lf() lib_cbmio_lf() lib_cbmio_print("press any key...") wait_key() lib_cbmio_lf() lib_cbmio_lf() //----------------------------------------- // Test 2: mult32 - 65000 * 100 (32-bit result) // out:high gets the high word //----------------------------------------- lib_cbmio_printlf("mult32: 65000 * 100 =") a = 65000 b = 100 lib_multdiv_mult32(a, b, high) lib_cbmio_print(" low: $") lib_cbmio_hexoutw(lib_multdiv_acc) lib_cbmio_print(" high: $") lib_cbmio_hexoutw(high) lib_cbmio_lf() lib_cbmio_lf() lib_cbmio_print("press any key...") wait_key() lib_cbmio_lf() lib_cbmio_lf() //----------------------------------------- // Test 3: div - 1337 / 7 // quotient in lib_multdiv_acc, remainder in lib_multdiv_ext //----------------------------------------- lib_cbmio_printlf("lib_multdiv_div: 1337 / 7 =") a = 1337 b = 7 lib_multdiv_div(a, b) lib_cbmio_print(" quotient: ") lib_cbmio_hexoutw(lib_multdiv_acc) lib_cbmio_lf() lib_cbmio_print(" remainder: ") lib_cbmio_hexoutw(lib_multdiv_ext) lib_cbmio_lf() lib_cbmio_lf() //----------------------------------------- // Test 4: divmod - 1000 / 13 // out:high gets the remainder //----------------------------------------- lib_cbmio_printlf("divmod: 1000 / 13 =") a = 1000 b = 13 lib_multdiv_divmod(a, b, high) lib_cbmio_print(" quotient: ") lib_cbmio_hexoutw(lib_multdiv_acc) lib_cbmio_lf() lib_cbmio_print(" remainder: $") lib_cbmio_hexoutw(high) lib_cbmio_lf() lib_cbmio_lf() lib_cbmio_print("press any key...") wait_key() lib_cbmio_lf() lib_cbmio_lf() //----------------------------------------- // Test 5: Loop 0-9 multiplied by 10 //----------------------------------------- lib_cbmio_printlf("loop: 0*10 through 9*10:") lib_cbmio_lf() i = 0 WHILE i < 10 a = i b = 10 lib_multdiv_mult(a, b) lib_cbmio_print(" ") lib_cbmio_hexoutb(i) lib_cbmio_print(" * 10 = ") lib_cbmio_hexoutw(lib_multdiv_acc) lib_cbmio_lf() i++ WEND lib_cbmio_lf() lib_cbmio_printlf("done!") FEND LABEL start main() SUBEND