;在屏幕上显示转换后的十六进制数吧
code segment
assume cs:code
start:
mov cx,4
newchar: mov ah, 1 ;键盘输入
int 21h
sub al, 30h
jl newchar ; <0重输
cmp al, 9
jg newchar ; >9重输
cbw
xchg ax, bx
mov dx, 10
mul dx
xchg ax, bx
add bx, ax
loop newchar
exit:
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
mov ch, 4
rotate: mov cl, 4
rol bx, cl
mov al, bl
and al, 0fh
add al, 30h ; ’0’~’9’ ASCII 30H~39H
cmp al, 3ah
jl printit
add al, 7h ; ’A’~’F’ ASCII 41H~46H
printit: mov dl, al
mov ah, 2
int 21h
dec ch
jnz rotate
mov ah,1
int 21h
mov ah,4ch
int 21h
code ends
end start
code segment
assume cs:code
start:
mov cx,4
xor ax,ax
xor bx,bx;输入并存入bx中
loopIn:
mov ah,07h
int 21h
cmp al,30h
jb loopIn
cmp al,39h
ja loopIn
and al,0fh
rol bx,1
rol bx,1
rol bx,1
rol bx,1
or bl,al
loop loopIn
output:
mov ax,bx
mov bx,0ah
xor cx,cx
xor dx,dx
again1:
div bx
add dl,30h
push dx
xor dx,dx
inc cx
or ax,ax
jnzagain1
again2:
mov ah,2
pop dx
int 21h
dec cx
jnz again2
mov ah,4ch
int 21h
code ends
end start
display equ 2h
key_in equ 1h
doscall equ 21h
decihex segment
main proc far
assume cs:decihex
start:
push ds
mov ax,0
push ax
call decibin
call crlf
;call binihex
;call crlf
call binidec
call crlf
ret
main endp
decibin proc near
mov bx,0
mov cx,4
newchar:
mov ah,1
int 21h
sub al,30h
jl exit
cmp al,9d
jg exit
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
add bx,ax
loop newchar
exit:
ret
decibin endp
binihex proc near
mov ch,4
rotate:mov cl,4
rol bx,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jl printit
add al,7h
printit:
mov dl,al
mov ah,2
int 21h
dec ch
jnz rotate
ret
binihex endp
crlf proc near
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
ret
crlf endp
binidec proc near
mov cx,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
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
add dl,30h
mov ah,display
int doscall
ret
dec_div endp
binidec endp
decihex ends
end start