📄 c3.asm
字号:
data 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',0dh,0ah
db '2.capital letter to small letter',0dh,0ah
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
db 'The number is:',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,'$'
data ends
;**************宏定义
output macro m
lea dx,m
mov ah,9
int 21h
endm
;**************
code segment
main proc far
assume cs:code,ds:data
start:
push ds
xor ax,ax
push ax
mov ax,data
mov ds,ax
again:
output mesg1
repeat:
mov ah,1
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
output mesg2
jmp repeat
L1: call crlf
call small_capital
call crlf
jmp again
L2: call crlf
call capital_small
call crlf
jmp again
L3: call crlf
call binhex
call crlf
jmp again
L4: call crlf
call hexbin
call crlf
jmp again
L5: call crlf
call decbin
call crlf
jmp again
L6: call crlf
call bindec
call crlf
jmp again
L7: call crlf
call hexdec
call crlf
jmp again
L8: call crlf
call dechex
call crlf
jmp again
ret
main endp
;*************************************
;小写字母转大写字母
small_capital proc near
xor ax,ax
output mesg3
mov ah,1
int 21h
mov bl,al
call crlf
mov al,bl
sub al,20h
push ax
output mesg4
pop ax
mov dl,al
mov ah,2
int 21h
ret
small_capital endp
;*******************************
;大写字母转小写字母
capital_small proc near
xor ax,ax
output mesg5
mov ah,1
int 21h
mov bl,al
call crlf
mov al,bl
add al,20h
push ax
output mesg6
pop ax
mov dl,al
mov ah,2
int 21h
ret
capital_small endp
;***************************
;二进制转十六进制
binhex proc near
xor ax,ax
mov bx,ax
output mesg7
mov si,4
newchar1:
mov ah,1
int 21h
sub al,30h
jl rotate1
cmp al,2
jl add_to1
jmp rotate1
add_to1:
mov cl,1
shl bx,cl
mov ah,0
add bx,ax
jmp newchar1
rotate1: call crlf
output mesg12
mov cx,4
rotate1_1: push cx
mov dl,bh
mov cl,4
shr dl,cl
or dl,30h
cmp dl,'9'
jbe print1
add dl,7
print1:
mov ah,2
int 21h
mov cl,4
rol bx,cl
pop cx
loop rotate1_1
ret
binhex endp
;*****************************
;十六进制转二进制
hexbin proc near
mov bx,0
output mesg9
mov si,16
newchar2:
mov ah,1
int 21h
sub al,30h
jl rotate2
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
rotate2: call crlf
output mesg10
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
output mesg8
mov si,16
mov bx,0
newchar3:
mov ah,1
int 21h
sub al,30h
jl rotate3
cmp al,9d
jg print3
cbw
xchg ax,bx
mov cx ,10d
mul cx
xchg ax,bx
add bx,ax
jmp newchar3
rotate3: call crlf
output mesg10
print3:
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
xor ax,ax
mov bx,ax
output mesg7
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: call crlf
output mesg11 ;display dec
mov cx,10000d
call ddec
mov cx,1000
call ddec
mov cx,100
call ddec
mov cx,10
call ddec
mov cx,1
call ddec
ret
bindec endp
;**********************
;十六进制转十进制
hexdec proc near
output mesg9
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: call crlf
output mesg11
mov cx,10000d
call ddec
mov cx,1000d
call ddec
mov cx,100d
call ddec
mov cx,10d
call ddec
mov cx,1d
call ddec
ret
hexdec endp
;****************
ddec 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
ddec endp
;***********************
;十进制转十六进制
dechex proc near
output mesg8
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: call crlf
mov si,4
output mesg12
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 si
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
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -