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

⟦5df9a8900⟧ TextFile

    Length: 1664 (0x680)
    Types: TextFile
    Names: »MPLSR.MAC«

Derivation

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

TextFile

;
;
;	Title		Multiple-Precision Logical Shift Right
;	Name:		MPLSR
;
;
;	Purpose:	Logical shift right a multi-byte operand
;			N bits
;
;	Entry:		Register pair HL = Base address of operand
;			Register B = lenght of operand
;			Register C = Number of bits to shift
;
;			  The operand is stored with ARRAYÆ0Å as its
;			  least significant byte and ARRAYÆLENGHT-1Å
;			  its most significant byte, where ARRAY
;			  is its base address.
;
;	Exit:		Operand shifted right filling the most 
;			significant bits with zeros
;			CARRY := Last bit shifted from
;				 leasr significant position
;
;	Registers used:	AF,BC,DE,HL
;
;	Time:		59 cycles overhead plus
;			((34 * lenght) + 35) cycles per shift
;
;	Size:		Program 26 bytes
;
;
;
MPLSL:
	;Exit if number of shifts or lenght of operand is 0
	;or clears carry in eighter case
	ld	a,c
	or	a
	ret	z		;Return if number of shifts is 0
	ld	a,b
	or	a
	ret	z		;Return if lenght of operand is 0

	;Calculate address of most significant (last) byte
	ld	e,b		;Address of MSB = base + Lenght - 1
	ld	d,0
	add	hl,de
	dec	hl
	
	;Loop on number of shifts to perform
	;A = lenght of operand
	;C = number of shifts
	;HL = address of MSB
	;Carry  = 0 initialy for logical shift
loop:
	ld	e,l		;Save address of MSB
	ld	d,h
	ld	b,a		;B = lenght of operand
	or	a		;Clear carry for logical shift
	;Rotate bytes starting with most significant
lsllp:
	rr	(hl)		;Rotate next byte right
	dec	hl		;Decrement to less significant byte
	djnz	lsllp
	ld	l,e		;Restore address of MSB
	ld	h,d
	dec	c		;Decrement number of shifts
	jr	nz,loop
	ret


«eof»