;	Lab 2 GJE soln
;
SCR	EQU	04E9h		; display screen
;
Start:
	mov	ax,[Value]	; get number to be displayed
	call	PrtD		; call sub and
	hlt			; end
;		
; Data follows
; 
Value: dw	-123		; check other numbers
;
; Subroutine PrtD - convert a 16 bit signed integer to decimal and print to screen
;
PrtD:
	push	bx		; save regs used in sub
	push	dx
	mov	bx,10		; divisor of 10
	push	bx		; mark end of number on stack
	cmp	ax,0		; is number negative?
	jg	Cont		; no, continue
	neg	ax		; negate (form two's complement) number
	push	ax		; save ax on stack
	mov	dx,SCR		; get address of display screen
	mov	al,'-'		; display a negative sign
	out	[dx],al
	pop	ax		; restore ax
;
Cont:
	mov	dx,0		; clear dx (high order divisor)
	div	bx		; divide ax by 10 (ax is quot, dx is rem)
	push	dx		; push rem on stack
	cmp	ax,0		; is quotient zero?
	jnz	Cont		; no, loop
	mov	dx,SCR		; get address of display screen
;
Disp:
	pop	ax		; get a digit
	cmp	al,10		; done?
	jz	Done		; yes, return
	or	al,30h		; convert to ascii
	out	[dx],al		; print digit
	jmp	Disp		; loop for next
;
Done:
	pop	dx		; restore regs and
	pop	bx
	ret			; return
	end	Start 