;EQU STATEMENTS GO HERE
;display equ 2h
;key_in equ 1h
;doscall equ 21h
;*********************************************
HEXIDEC segment
;---------------------------------------------
main proc far
assume cs:HEXIDEC
;Main part of program links subroutines together
START:
;set up stack for return
push ds
sub ax,ax
push ax
;MAIN PART OF PROGRAM GOES HERE
call hexibin
call crlf
;
call binidec
call crlf
;
jmp main
;
ret
main endp
;---------------------------------------------
hexibin proc near
;Sburoutine to convert hex on keybd to binary
; result is left in BX register
mov bx,0
;Get digit from keyboard,convert to binary
newchar:
mov ah,1
int 21H
sub al,30h
jl exit2
emp al,10D
jl add_to
;not digit (0-9),may be letter(a to f)
sub al,27h
cmp al,0ah
jl exit2
cmp al,10h
jge exit2
;is hex digit,add to number in BX
add_to:
mov cl,4
shl bx,cl
mov ah,0
add bx,ax
jmp newchar
exit2:
ret
hexibin endp
;---------------------------------------------
binidec proc near
;Subroutine to convert binary number in BX
; to decimal on console screen
mov cs,10000d
call dec_div
mov cx,1000d
call dec_div
mov cx,100d
call dec_div
mov cx,10d
call dec_div
mov cx,1d
call dec_div
ret
;-----------------------------------------------
dec_div proc near
;Subroutine to divide number in BX by number in CX
;print quotient on screen
;(numberator in DX+AX,denom in CX)
mov ax,bx
mov dx,0
div cs
mov bx,dx
mov dl,al
;print the contents of DL on screen
add dl,30h
mov ah,2H
int 21H
ret
dec_div endp
;-------------------------------------------------
binidec endp
;--------------------------------------------------
crlf proc near
;print carriage return and linefeed
mov dl,0ah
mov ah,2H
int 21H
;
mov dl,0ah
mov ah,2H
int 21H
ret
crlf endp
HEXIDEC ends
;***************************************************
;EDN MAIN
END START
这个是十六进制转十进制的程序