; ; Modifications of routines by ; Jerry L. Goodrich, ; Pennsylvania State University, ; University Park, Pa. ; Replaces previous .imul, .idiv routines - faster but longer ; ; unsigned integer multiply ; operand range 0 to 65535, product 0 to 4295*10^6 (approx) ; (dehl) := (bc) * (de) ; d,e,h,l .imul:: push psw mov a,e; low order multiplier byte push d; save hi multiplier byte call bmult; do 1 byte mult xthl; save low order product, get multiplier push psw; store hi byte of 1st product mov a,h; hi order byte of multiplier call bmult; 2nd 1 byte multiply mov d,a; position hi order product byte pop psw; hi order byte of 1st product add h; update 3rd byte of product mov e,a; to e jnc imul1 inr d; propagate carry imul1: mov a,l; low byte, 2nd product pop h; low 2 bytes, 1st product add h; combine mov h,a jnc imul2 inx d; propagate carry imul2: pop psw ret ; ; 8 bit by 16 bit unsigned multiplication ; (ahl) := (a) * (bc) ; (d) := (e) := 0 ; a,f,d,e,h,l bmult: lxi d,8; d := 0, e := bit ctr mov h,d mov l,d; clear hl ora a rz; zero multiplier add a; 1st multiplier bit to cy jnc bmult2; zero bit bmult1: dad b; 1 bit, add to partial product adc d; cy to (a) rh bit bmult2: dcr e rz; done dad h; l shift product adc a; into (a), mul bit to cy jc bmult1; bit is 1 jmp bmult2; bit is 0 end