; ************* SWEET 16 MULTIPLY SR ************* ; A BIT-BY-BIT MULTIPLY SUBROUTINE. ; MULTIPLIER X MULTIPLICAND. ; ENTRY: (DE) = MULTIPLIER, UNSIGNED 16-BIT. ; (BC) = MULTIPLICAND, UNSIGNED 16-BIT. ; EXIT: (DE,HL) = PRODUCT, UNSIGNED 32-BIT. ; (BC) = RETAINED. ; (A) = DEVASTATED. ; EVERYTHING ELSE IN REASONABLE ORDER :-) ; *********************************************** .ORG 0000h LD SP, 0080h ; ADDED FOR TESTING PURPOSES. LD DE, 0010 ; ADDED FOR TESTING PURPOSES. LD BC, 0100 ; ADDED FOR TESTING PURPOSES. CALL SWE16 ; ADDED FOR TESTING PURPOSES. HALT ; ADDED FOR TESTING PURPOSES. SWE16: LD HL, 0 ; ZERO THE PRODUCT HALF. LD A, 16 ; ITERATION COUNT. SWE001: EX DE, HL ; SETUP FOR SHIFT. ADD HL, HL ; SHIFT DE. PUSH AF ; SAVE POSSIBLE CARRY. EX DE, HL ; PUT DE BACK. ADD HL, HL ; NOW BOTTOM HALF. JP NC, SWE002 ; GO IF NO CARRY. INC DE ; PROPAGATE. SWE002: POP AF ; GET CARRY FROM DE. JP NC, SWE003 ; GO IF NO CARRY TO MSB. ADD HL, BC ; BIT WAS A ONE. JP NC, SWE003 ; GO IF NO CARRY TO MSB. INC DE ; PROPAGATE. SWE003: DEC A ; DECREMENT COUNT. JP NZ, SWE001 ; GO IF MORE. RET ; RETURN. .END