


;HEXIBIN&--Hexadecimal to binary converter
;Converts hex from keyboard to binary
;For use with BASIC programs
;on entry. BX holds FAC address
 
key_in	equ	1h		;keyboard input
doscall	equ	21h		;DOS interrupt number

;**********************************************************
hexibin segment			;defint code segment
;----------------------------------------------------------
main	proc	far		;main part of program

	assume cs:hexibin

;get digit from keyboard convert to binary
	mov	dx,0		;clear DX for number
newchar:			
	mov	ah,key_in	;keyboard input
	int	doscall		;call DOS
	sub	al,30h		;ASCII to binary
	jl	exit		;jump if < 0
	cmp	al,10d		;is it < 10d ?
	jl	add_to		;yes,so it is digit
;not dec digit ( 0 to 9 ) may be letter ( A to F )
	sub	al,27h		;convert ASCII to bin
	cmp	al,0ah		;is it <0a hex?
	jl	exit		;yes,not letter
	cmp	al,10h		;is it >0f hex?
	jge	exit		;yes,not letter
;is hex digit add to number in DX 
add_to:
	mov	cl,4		;set shift count
	shl	dx,cl		;rotate DX 4 bits
	mov	ah,0		;zero out AH
	add	dx,ax		;add digit to number
	jmp	newchar		;get next digit 
;put number in Floating Point Accumulator
exit:
	mov	[bx],dx		;number from DX
	ret			;return to BASIC

main    endp			;end subprocedure
;----------------------------------------------------------
hexibin ends			;end of code segment
;**********************************************************

	end	main		;end assembly





