微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 汇编:统计字符串内各种字符的数目

汇编:统计字符串内各种字符的数目

时间:12-01 来源:互联网 点击:
;对这个题目进一步改造:
;3_7 用户输入一个由数字‘0’~‘9’英文大写字母‘A’~‘Z’;以及英文小写字母‘a’~‘z’组成的ASCII 字符串,
;字符串的结束符为 CR(即回车符,其ASCII 码为0DH),字符串总长度不超过256 个。
;要求统计传送的字符总数以及其中各种字符的数目

DATA SEGMENT
SUM DB 00H ;总数 计数器
CAPITAL DB 00h ;大写字母个数 计数器
small db 00h ;小写字母个数 计数器
num db 00h ;数字个数 计数器
result db The amout all of the zifu in this string is ,$
result1 db The amout of the number in the string is ,$
result2 db The amout of the big capital is ,$
result3 db The amout of the small capital is ,$
string db 256 dup (?) ;保存输入的字符
kongzi DB 0DH,0AH,$ ;换行使用
buffer DB 256 DUP(0) ;目标内存
results DB 256 DUP(?)
tital db Please input the string you want to be done : ,0dh,0ah,$
tip db Do you want to have a try again (if yes: "y" ,else "n"): ,$
tip1 db welcome to use the program again ,the original is WQ ,$
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
MOV DS,AX
lea dx,tital
mov ah,09h
int 21h
mov di,0
again:
mov ah,01h
int 21h
mov string[di],al
inc di
cmp al,0dh
jnz again
cld ;将方向标志位置零 串操作递增
main: lods string ;字符串装入指令 把字符串一个个装入al
INC SUM
CMP AL,0DH
JE DONE
CMP AL,30H
Jb main
cmp al,41h
jb k1
CMP AL,61H
Jb k2
JMP main
DONE:
lea dx,result ;输出SUM
mov ah,09h
int 21h
DEC SUM
MOV AX,0
MOV AL,SUM
MOV BL,10
div BL
MOV DX,AX
ADD DX,3020H ;为什么要加20呢?
cmp dl,30h
jnz wuling
mov dl,20h
wuling:
MOV AH,02h
INT 21H
MOV DL,DH ;这是在干什么?
MOV AH,2h ;2号调用每次只输出一个字符,即dl
INT 21H
LEA DX,kongzi ;换行
MOV AH,09H
INT 21H



;输出num
mov ax,0
mov al,num
mov bl,10
div bl
mov dx,ax
add dx,3030h
cmp dl,30h
jne wuling3
mov dl,32
wuling3:
push dx
lea dx,result1
mov ah,09h
int 21h
pop dx
mov ah,02h
int 21h
mov dl,dh
mov ah,02h
int 21h
LEA DX,kongzi
MOV AH,09H
INT 21H
;输出CAPITAL
MOV AX,0
MOV AL,CAPITAL
sub al,04h
MOV BL,10
div BL
MOV DX,AX
ADD DX,3030H
CMP Dl,30H
JNE WULING2
MOV Dl,32
WULING2:push dx
lea dx,result2
mov ah,09h
int 21h
pop dx
MOV AH,02h
INT 21H
MOV DL,DH
MOV AH,2
INT 21H

mov al,sum
sub al,capital
add al,04h
sub al,num
mov small,al

;输出small capital
MOV AX,0
MOV AL,small
MOV BL,10
div BL
MOV DX,AX
ADD DX,3020H
CMP Dl,30H
JNE WULING4
MOV Dl,32 ;空格

WULING4: push dx
LEA DX,kongzi
MOV AH,09H
INT 21H
lea dx,result3
mov ah,09h
int 21h
pop dx

MOV AH,02h
INT 21H
MOV DL,DH
MOV AH,2
INT 21H

lea dx,kongzi
mov ah,09h
int 21h
lea dx,tip
mov ah,09h
int 21h
mov ah,01h
int 21h
cmp al,y
je lop

lea dx,kongzi
mov ah,09h
int 21h
lea dx,tip1
mov ah,09h
int 21h
over:
MOV AH,4CH
INT 21H
k2:inc capital
jmp main
k1: inc num
jmp main
lop:
lea dx,kongzi
mov ah,09h
int 21h
jmp start

CODE ENDS
END START

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top