;数据段
datarea segment
mesg1 db 'Please input a number(1,2,3,4,5,,6,7,8) to select style:',13,10
db '1.small letter to capital letter',13,10
db '2.capital letter to small letter',13,10
db '3.bin to hex',13,10
db '4.hex to bin',13,10
db '5.dec to bin',13,10
db '6.bin to dec',13,10
db '7.hex to dec',13,10
db '8.dec to hex',13,10,'$'
mesg2 db 'You have input a invalid number!Please select again:',13,10,'$'
mesg3 db 'Please input a small letter:',13,10,'$'
mesg4 db 'Its capital letter is',13,10,'$'
mesg5 db 'Please input a capital letter:',13,10,'$'
mesg6 db 'Its small letter is',13,10,'$'
mesg7 db 'Please input a bin number:',13,10,'$'
mesg8 db 'Please input a dec number:',13,10,'$'
mesg9 db 'please input a hex number:',13,10,'$'
mesg10 db 'Its bin number is',13,10,'$'
mesg11 db 'Its dec number is',13,10,'$'
mesg12 db 'Its hex number is',13,10,'$'
datarea ends
prognam segment
main proc far
assume cs:prognam,ds:datarea
start:
push ds
xor ax,ax
push ax
mov ax,datarea
mov ds,ax
again:
lea dx,mesg1
mov ah,09h
int 21h
repeat:
mov ah,01h
int 21h
cmp al,31h
je L1
cmp al,32h
je L2
cmp al,33h
je L3
cmp al,34h
je L4
cmp al,35h
je L5
cmp al,36h
je L6
cmp al,37h
je L7
cmp al,38h
je L8
lea dx,mesg2
mov ah,9
int 21h
jmp repeat
L1:
call small_capital
call crlf
jmp again
L2:
call capital_small
call crlf
jmp again
L3:
call binhex
call crlf
jmp again
L4:
call hexbin
call crlf
jmp again
L5:
call decbin
call crlf
jmp again
L6:
call bindec
call crlf
jmp again
L7:
call hexdec
call crlf
jmp again
L8:
call dechex
call crlf
jmp again
ret
main endp
small_capital proc near
xor ax,ax
lea dx,mesg3
mov ah,9
int 21h
mov ah,1
int 21h
sub al,20h
push ax
lea dx,mesg4
mov ah,9
int 21h
pop ax
mov dl,al
mov ah,2
int 21h
ret
small_capital endp
capital_small proc near
xor ax,ax
lea dx,mesg5
mov ah,9
int 21h
mov ah,1
int 21h
add al,20h
push ax
lea dx,mesg6
mov ah,9
int 21h
pop ax
mov dl,al
mov ah,2
int 21h
ret
capital_small endp
binhex proc near
xor ax,ax
mov bx,ax
lea dx,mesg7
mov ah,9
int 21h
mov si,4
newchar1:
mov ah,1
int 21h
sub al,30h
jl rotate1
cmp al,10d
jl add_to1
jmp rotate1
add_to1: ;save bin to bx
mov cl,1
shl bx,cl
mov ah,0
add bx,ax
jmp newchar1
rotate1:
lea dx,mesg12
mov ah,9
int 21h
rotate1_1:
mov cl,4
rol bx,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jl print1
add al,7h
print1:
mov dl,al
mov ah,2
int 21h
dec si
jnz rotate1_1
ret
binhex endp
hexbin proc near
mov bx,0
lea dx,mesg9
mov ah,9
int 21h
mov si,16
newchar2:
mov ah,1
int 21h
sub al,30h
jl print2
cmp al,10d
jl add_to2
sub al,27h
cmp al,0ah
jl print2
cmp al,10h
jge print2
add_to2:
mov cl,4
shl bx,cl
mov ah,0
add bx,ax
jmp newchar2
lea dx,mesg10
mov ah,9
int 21h
print2:
rol bx,1
mov al,bl
and al,1h
add al,30h
mov dl,al
mov ah,2
int 21h
dec si
jnz print2
ret
hexbin endp
decbin proc near
lea dx,mesg8
mov ah,9
int 21h
mov bx,0
newchar3:
mov ah,1
int 21h
sub al,30h
jl print3
cmp al,9d
jg print3
cbw
xchg ax,bx
mov cx ,10d
mul cx
xchg ax,bx
add bx,ax
jmp newchar3
print3:
lea dx,mesg10
mov ah,9
int 21h
rol bx,1
mov al,bl
and al,1h
add al,30h
mov dl,al
mov ah,2
int 21h
dec si
jnz print3
ret
decbin endp
bindec proc near
lea dx,mesg7
mov ah,9
int 21h
newchar4:
mov ah,1
int 21h
sub al,30h
jl print4
cmp al,10d
jl add_to4
jmp print4
add_to4:
mov cl,1
shl bx,cl
mov ah,0
add bx,ax
jmp newchar4
print4:
lea dx,mesg11
mov ah,9
int 21h ;display dec
mov cx,10000d
call dec_div4
mov cx,1000
call dec_div4
mov cx,100
call dec_div4
mov cx,10
call dec_div4
mov cx,1
call dec_div4
ret
dec_div4 proc near
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
add dl,30h
mov ah,2
int 21h
ret
dec_div4 endp
bindec endp
hexdec proc near
lea dx,mesg9
mov ah,9
int 21h
mov bx,0
newchar5:
mov ah,1
int 21h
sub al,30h
jl next5
cmp al,10d
jl add_to5
sub al,27h
cmp al,0ah
jl next5
cmp al,10h
jge next5
add_to5:
mov cl,4
shl bx,cl
mov ah,0
add bx,ax
jmp newchar5
next5:
lea dx,mesg11
mov ah,9
int 21h ;display dec
mov cx,10000d
call dec_div5
mov cx,1000d
call dec_div5
mov cx,100d
call dec_div5
mov cx,10d
call dec_div5
mov cx,1d
call dec_div5
ret
hexdec endp
dec_div5 proc near
mov ax,bx
mov dx,0
div cx
mov bx,dx
mov dl,al
add dl,30h
mov ah,2
int 21h
ret
dec_div5 endp
dechex proc near
lea dx,mesg11
mov ah,9
int 21h
mov bx,0
newchar6:
mov ah,1
int 21h
sub al,30h
jl next6
cmp al,9d
jg next6
cbw
xchg ax,bx
mov cx,10d
mul cx
xchg ax,bx
add bx,ax
jmp newchar6
next6:
mov si,4
lea dx,mesg12
mov ah,9
int 21h
rotate6:
mov cl,4
rol bx,cl
mov al,bl
and al,0fh
add al,30h
cmp al,3ah
jl print6
add al,7h
print6:
mov dl,al
mov ah,2
int 21h
dec ch
jnz rotate6
ret
dechex endp
crlf proc near
mov dl,13
mov ah,2
int 21h
mov dl,10
mov ah,2
int 21h
ret
crlf endp
prognam ends
end start
一个是在repeat那里。一个是在程序最后。