	.ORIG	x3000

	LD	R0,NUMBER

	; print the value in R0 as a 16-bit binary number

	; R0 holds the number (shifted left to find bits)
	; R1 holds the bit number being printed (15 down to 0)
	; R2 holds the ASCII character for that bit
	; R3 holds x30 (ASCII '0') for convenience

	AND	R1,R1,#0	; start with bit 15
	ADD	R1,R1,#15
	LD	R3,ZERO		; initialize R3
BITLOOP ADD	R2,R3,#0	; copy R3 to R2 ('0')
	ADD	R0,R0,#0	; check bit value
	BRzp	ZEROBIT		; skip next instruction for 0 bit
	ADD	R2,R2,#1	; print a 1 bit
ZEROBIT	LDI	R4,DSR		; wait for display to be ready
	BRzp	ZEROBIT
	STI	R2,DDR		; write ASCII character to display
	ADD	R0,R0,R0	; shift R0 left to find next bit
	ADD	R1,R1,#-1	; count down in bit index
	BRzp	BITLOOP		; print another until index < 0
	HALT

NUMBER	.FILL	xABCD		; a number to print
ZERO	.FILL	x30		; ASCII digit '0'
DSR	.FILL	xFE04		; DSR address in LC-3
DDR	.FILL	xFE06		; DDR address in LC-3

	.END

