* sample multi-byte multiply example RAM equ 0 EEPROM equ $f800 OPSIZE equ 3 org RAM opx rmb OPSIZE opy rmb OPSIZE res rmb 2*OPSIZE tmpd rmb 2 xcnt rmb 1 ycnt rmb 1 org EEPROM * get operands into opx and opy start ldaa #$ff staa opx ldaa #$ff staa opx+1 ldaa #$ff staa opx+2 ldaa #$ff staa opy ldaa #$ff staa opy+1 ldaa #$ff staa opy+2 * clear the result ldx #res ldaa #2*OPSIZE cloop clr 0,x inx deca bne cloop * Do the multiply. We'll initialize the counters to the operand size * less 1 (so it'll be the offset into the operands) and count down. * X loop ldaa #OPSIZE-1 staa xcnt xloop * Y loop ldaa #OPSIZE-1 staa ycnt yloop * Get a byte from X and one from Y, multiply them, * and put the result in temporaries. * Get offset from X operand into X index reg. clra ldab xcnt xgdx * Get offset from Y operand into Y index reg. clra ldab ycnt xgdy * Load the operands, multiply, put the result in a temporary ldaa opx,x ldab opy,y mul std tmpd * Figure out the offset into the result for these two bytes. * This ends up being the sum of the offsets of the operands. * Then put what we've built into X clra ldab xcnt addb ycnt xgdx * Add our digits into the result ldd res,x addd tmpd std res,x * Make sure we propagate any carry-outs bcc nocarr cagain dex ldaa res,x adda #1 staa res,x bcs cagain * Terminate Y loop by subtracting 1 and seeing if we're finished nocarr dec ycnt bge yloop * Terminate X loop by subtracting 1 and seeing if we're finished dec xcnt bge xloop * Done! done bra done end start