DataMuseum.dk

Presents historical artifacts from the history of:

Jet Computer Jet80

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

See our Wiki for more about Jet Computer Jet80

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - download

⟦519b023b4⟧ TextFile

    Length: 3840 (0xf00)
    Types: TextFile
    Names: »BN2DEC.MAC«

Derivation

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

TextFile

;
;
;	Title		Binary to decimal ASCII
;	Name:		BN2DEC
;
;
;	Purpose:	Convert a 16-bit signed binary number
;			to ASCII data
;
;	Entry:		Register H = High byte of output buffer address
;			Register L = Low  byte of output buffer address
;			Register D = High byte of value to convert
;			Register E = Low  byte of value to convert
;
;	Exit:		The first byte of the buffer is the lenght.
;			followed by the characters.
;
;	Registers used:	AF,BC,DE,HL
;
;	Time:		Approximately 7.200 cycles
;
;	Size:		Program 107 bytes
;			Data	  4 bytes
;
;
;
BN2DEC:
	;Save parameters
	ld	(bufptr),hl	;Store the buffer pointer
	ex	de,hl
	ld	a,0
	ld	(curlen),a	;Current buffer lenght is 0
	ld	a,h
	ld	(ngflag),a	;Save sign of value
	or	a		;Set flags from value
	jp	p,cnvert	;Jump if value is positive
	ex	de,hl		;Else take absolute value (0 - value)
	ld	hl,0
	or	a		;Clear carry
	sbc	hl,de		;Subtract value from 0

	;Convert value to a string
cnvert:
	; HL := HL DIV 10   (Dividend,Quotient)
	; DE := HL MOD 10   (Remainder)
	ld	e,0		;Remainder = 0
	ld	b,16		;16 bits is dividend
	or	a		;Clear to start
dvloop:
	;Shift the next bit of the quotient into bit 0 of the dividend
	;Shift next most significant bit of dividend into
	;  least significant bit of remainder
	;HL holds both dividend and quotient. Quotient is shifted
	;  in as the dividend is shifted out.
	;E is the remainder.

	;Do a 24-bit shift left, shifting
	;  carry to L, L to H, H to E
	rl	l		;Carry (next bit of quotient) to bit 0
	rl	h		;Shift high byte
	rl	e		;Shift next bit of dividend

	;If remainder is 10 or more, next bit of
	;  quotient is 1 (this bit is placed in carry)
	ld	a,e
	sub	10		;Subtract 10 from remainder
	ccf			;Complement carry
				;  (This is the next bit of quotient)
	jr	nc,deccnt	;Jump if remainder is less than 10
	ld	e,a		;Otherwise remainder = difference
				;  between previous remainder and 10

deccnt:
	djnz	dvloop		;Continue until all bits are done

	;Shift last carry into cuotient
	rl	l		;Last bit of quotient to bit 0
	rl	h

	;Insert the next character in ASCII
chins:
	ld	a,e		;Convert 0...9 to ASCII '0'...'9'
	add	a,'0'
	call	insert

	;If quotient is not 0 then keep dividing
	ld	a,h
	or	l
	jr	nz,cnvert

exit:
	ld	a,(ngflag)
	or	a
	jp	p,pos		;Branch if orginal value was positive
	ld	a,'-'		;Else
	call	insert		;  put a minus sign in front
pos:
	ret

	;--------------------------------------------------
 	;Subroutine:  Insert
	;Purpose:     Insert the character in register a at the
	;	      front of the buffer
	;Entry:	      CURLEN = lenght of buffer
	;             BUFPTR = Current address of last character in buffer
	;Exit:	      Register A insreted immediately atfer lenght byte
	;Registers used:  AF,B,C,D,E
	;--------------------------------------------------

insert:
	push	hl		;Save HL
	push	af		;Save character to insert

	;Move entire buffer up 1 byte in memory
	ld	hl,(bufptr)	;Get buffer pointer
	ld	d,h		;HL = source (current end of buffer)
	ld	e,l
	inc	de		;DE = destination (current end +1)
	ld	(bufptr),de	;Store new buffer pointer
	ld	a,(curlen)
	or	a		;Test for culen = 0
	jr	z,exitmr	;Jump if zero (nothing to move)
				;  just store one character
	ld	c,a		;BC = loop counter
	ld	b,0
	lddr			;Move entire buffer up 1 byte

exitmr:
	ld	a,(curlen)	;Increment current lenght by 1
	inc	a
	ld	(curlen),a
	ld	(hl),a		;Update lenght byte of buffer
	ex	de,hl		;HL points to first character in buffer
	pop	af		;Get character to insert
	ld	(hl),a		;Insert character at front of buffer
	pop	hl		;Restore HL
	ret

;DATA
bufptr:	ds	2		;Address of last chacter in buffer
curlen:	ds	1		;current lenght of buffer
ngflag:	ds	1		;sign of orginal value

«eof»