DataMuseum.dk

Presents historical artifacts from the history of:

CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦c468ed080⟧ TextFile

    Length: 1280 (0x500)
    Types: TextFile
    Names: »MUL16.MAC«

Derivation

└─⟦01b5c9619⟧ Bits:30005906 Microsoft Multiplan v1.05 og HELP
    └─ ⟦this⟧ »MUL16.MAC« 

TextFile

;
;
;	Title		16-bit Multiplication
;	Name:		MUL16
;
;
;	Purpose:	Multiply 2 signed or unsigned 16-bit words and
;			return a 16-bit signed or unsigned product
;
;			Answers needing more than 16 bits: bits higher
;			than 15 are lost
;
;	Entry:		Register HL = Multiplicand
;			Register DE = Mulitplier
;
;	Exit:		Product = multiplicand * mulitplier
;			Register HL = product
;
;	Registers used:	AF,BC,DE,HL
;
;	Time:		Approximately 865 to 965 cycles
;
;	Size:		Program 22 bytes
;
;
;
MUL16:
	;Initialize partial product, bit count
	ld	c,l		;BC = multiplier
	ld	b,h
	ld	hl,0		;product = 0
	ld	a,15		;count = bit lenght - 1

	;shift-and-add algorithm
	; if msb of multiplier is 1, add multiplicand to partial
	;  product
	; shift partial product, mltiplier left 1 bit
mlp:
	sla	e		;shift multiplier left 1 bit
	rl	d
	jr	nc,mlp1		;Jump if multiplier = 0
	add	hl,bc		;Add multiplicand to partial product
mlp1:
	add	hl,hl		;shift partial product left
	dec	a
	jr	nz,mlp		;Continue until count = 0

	;Add multiplicand one last time if msb of multiplier is 1

	or	d		;Sign flag = msb of multiplier
	ret	p		;exit if msb of multiplicand is 0
	add	hl,bc		;Add multiplicand to product
	ret
«eof»