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

⟦30da013e3⟧ TextFile

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

Derivation

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

TextFile

;
;
;	Title		Binary to BCD conversion
;	Name:		BN2BCD
;
;
;	Purpose:	Convert one byte of binary data to two
;			bytes of BCD data
;
;	Entry:		Register A = binary data
;
;	Exit:		Register H = High byte of BCD data
;			Register L = Low  byte of BCD data
;
;	Register used:	AF,C,HL
;
;	Time:		497 cycles maximum
;
;	Size:		Program 27 bytes
;
;
;
BN2BCD:
	;CALCULATE 100'S DIGIT - DIVIDE BY 100
	; H = QUOTIENT
	; A = REMAINDER

	ld	h,0ffh			;Start quotient at -1
D100LP:
	inc	h			;Add 1 to quotient
	sub	100			;Subtract 100
	jr	nc,D100LP		;Jump if difference still positive
	add	a,100			;Add the last 100 back

	;CALCULATE 10'S AND 1'S DIGITS
	;   DIVIDE REMAINDER OF THE 100'S DIGIT BY 10
	; L = 10'S DIGIT
	; A = 1 'S DIGIT

	ld	l,0ffh			;Start quotient at -1

D10LP:
	inc	l			;Add 1 to quotient
	sub	10			;Subtract 10
	jr	nc,D10LP		;Jump if differnce still positive
	add	a,10			;Add the last 10 back

	;Combine 1's and 10's digits

	ld	c,a			;Save 1's digit in C
	ld	a,l
	rlca				;Move 10's to high nibble of a
	rlca
	rlca
	rlca
	or	c			;Or in the 1's digit

	;Return with L = Low byte, H = High byte

	ld	l,a
	ret
«eof»