;decihex-main program ;convert decimal on keybd to hex on screen ;***************************************** decihex segment assume cs:decihex start: ;main proc far repeate: call decibin ;keybd to binary call crlf ;print cr and lf call binihex ;binary to hex on screen call crlf ;print cr and lf jmp repeate ;do it again ;main endp ;---------------------------------------------------- ;procedure to convert dec on keybd to binary ;result is left in bx register decibin proc near mov bx,0 ;clear bx for number newchar: mov ah,1 ;keybd input int 21h ;call dos sub al,30h ;ASCII to binary jl exit ;jump if<0 cmp al,9d ;is it >9d? jg exit ;yes,not dec digit cbw ;bytein al to word in ax ;(digit is now in ax) ;Multiply number in bx by 10decimal xchg ax,bx ;trade digit &number mov cx,10d ;put 10 dec in cx mul cx ;number times 10 xchg ax,bx ;trade number & digit ;Add digit in ax to number in bx add bx,ax ;add digit to number jmp newchar ;get next digit exit : ret ;return from decibin decibin endp ;end of decibin proc ;------------------------------------------------- ;procedure to convert binary number in bx to hex on screen binihex proc near mov ch,4 ;number of digits rorate: mov cl,4 ;set count to bits rol bx,cl ;left digit to right mov al,bl ;mov to al and al,0fh ;mask off left digit add al,30h ;convert hex to ASCII cmp al,3ah ;is it >9? jl printit ;jump if digit =0 to 9 add al,7h ;digit is A to F printit: mov dl,al ;print ASCII charin DL mov ah,2 ;display output funct int 21h ;call dos dec ch ;done 4 digits? jnz rorate ;not yet ret ;return from binihex binihex endp ;--------------------------------------------------- ;procedure to print carriage return and linefeed crlf proc near mov dl,0dh ;carriage return mov ah,2 ;display function int 21h ;call dos mov dl,0ah ;linefeed mov ah,2 ;display function int 21h ;call dos ret ;return from crlf crlf endp ;--------------------------------------------------- decihex ends ;--------------------------------------------------- end start
;作者:课本教材;时间:2007.11.14;功能:十进制到十六进制数转换的程序实现;主要实现:调用子程序来实现转换 ;decihex-main program ;convert decimal on keybd to hex on screen;*****************************************decihex segment assume c