Task

Create and display the sequence of binary digits for a given   non-negative integer.

   The decimal value      5   should produce an output of               101
   The decimal value     50   should produce an output of            110010
   The decimal value   9000   should produce an output of    10001100101000

The results can be achieved using built-in radix functions within the language   (if these are available),   or alternatively a user defined function can be used.

The output produced should consist just of the binary digits of each number followed by a   newline.

There should be no other whitespace, radix or sign markers in the produced output, and leading zeros should not appear in the results.




bdos:	equ	5h		; CP/M system call
puts:	equ	9h		; Print string
	org	100h
	lxi	h,5		; Print value for 5
	call	prbin
	lxi	h,50		; Print value for 50 
	call	prbin
	lxi	h,9000		; Print value for 9000
prbin:	call	bindgt		; Make binary representation of HL
	mvi	c,puts		; Print it
	jmp	bdos
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;;	Return the binary representation of the 16-bit number in HL
	;;;	as a string starting at [DE].
bindgt:	lxi	d,binend	; End of binary string
	ana	a		; Clear carry flag
binlp:	dcx	d		; Previous digit
	mov	a,h		; Shift HL left, LSB into carry flag
	rar				
	mov	h,a
	mov	a,l
	rar
	mov	l,a
	mvi	a,'0'		; Digit '0' or '1' depending on
	aci	0		; status of carry flag.
	stax	d
	mov	a,h		; Is HL 0 now?
	ora	l 
	rz			; Then stop
	jmp	binlp		; Otherwise, do next bit
binstr:	db	'0000000000000000'	; Placeholder for string
binend:	db	13,10,'$'		; end with \r\n 