📄 宏汇编字符串处理1.0.asm
字号:
shuchu macro x ;输出宏定义
lea dx,output&x
mov ah,09h
int 21h
add count&x,30h
cmp count&x,3ah
jl display&x
mov dl,31h
mov ah,02h
int 21h
sub count&x,0ah
display&x:
mov dl,count&x
mov ah,02h
int 21h
endm
datas segment
string db 20,?,20 dup(?) ;字符串缓冲区
input db 0ah,0dh,'Please input one string:$'
output1 db 0ah,0dh,' The number of others is:$'
output2 db 0ah,0dh,' The number of datas is:$'
output3 db 0ah,0dh,' The number of words is:$'
output4 db 0ah,0dh,' The number of chars is:$'
output db 0ah,0dh,'Output the right string:$' ;以上为各种显示信息
count1 db 0 ;初始化去掉的字符的个数
count2 db 0 ;初始化数字的个数
count3 db 0 ;初始化字母的个数
count4 db -1 ;初始化输入字符的总数
count db 0 ;初始化有效字符的个数
crlf db 0ah,0dh,'$' ;定义换行
datas ends
code segment
main proc far
assume cs:code,ds:datas
start:
push ds
sub ax,ax
push ax
mov ax,datas
mov ds,ax
lea dx,input
mov ah,9
int 21h ;显示输入提示信息
lea si,string+2 ;传送字符串的首地址
mov cx,20 ;默认字符串的字符总数不超过20
inputs:
inc count4
mov ah,01h
int 21h ;开始输入字符
cmp al,0dh
jz display ;若输入回车键,则结束字符串的输入
cmp al,'0'
jl jishu1 ;不是合法字符,则跳转到jishu1
cmp al,'9'
jg jishu2 ;字符大于9,则跳转到jishu2
jmp jishu4 ;输入的字符是数字,跳转到jishu4
jishu1:
inc count1 ;不合法字符的个数
jmp next
jishu2:
cmp al,'A'
jl jishu1
cmp al,'Z'
jg jishu3
jmp jishu ;判断是否是大写字母,并跳转到相应位置执行程序
jishu3:
cmp al,'a'
jl jishu1
cmp al,'z'
jg jishu1
jmp jishu ;判断是否是小写字母,并跳转到相应位置执行程序
jishu4:
inc count2 ;数字字符的个数
mov string[si],al ;把有限字符传送给string[si]
inc si
inc count ;有效字符个数
jmp next
jishu:
inc count3 ;字母字符的个数
mov string[si],al ;把有限字符传送给string[si]
inc si
inc count ;有效字符个数
next:
inc di
loop inputs
display:
lea dx,crlf
mov ah,09h
int 21h ;换行
shuchu 1 ;调用输出宏,输出非法字符的个数
shuchu 2 ;调用输出宏,输出数字字符的个数
shuchu 3 ;调用输出宏,输出字母字符的个数
shuchu 4 ;调用输出宏,输出输入字符的总数
lea dx,crlf
mov ah,09h
int 21h
lea dx,output
mov ah,09h
int 21h
mov cl,count
mov ch,0
lea di,string+2
print: ;逐个输出有效字符
mov dl,string[di]
mov ah,02h
int 21h
inc di
loop print
ret ;返回DOS
main endp
code ends
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -