汇编语言实验题:分类统计字符个数,出现问题,急需解决!!!
时间:2011-06-19
来源:互联网
;这是我写的代码,个人认为没有错误,但出来的结果是错的!希望高手能帮我解决
;*********************************************************************
data segment
string1 label byte
max1 db 80
act1 db ?
str1 db 80 dup(?)
numbers db ?
letters db ?
others db ?
mess1 db 'The numbers of number:','$'
mess2 db 'The numbers of letter:','$'
mess3 db 'The numbers of others:','$'
mess4 db 13,10,'$'
mess5 db 'Enter Sentence:',13,10,'$'
data ends
;*********************************************************************
code segment
main proc far
assume cs:code,ds:data,es:data
start: push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov es,ax
mov numbers,0
mov letters,0
mov others,0
mov ch,act1
lea dx,mess5
mov ah,09h
int 21h
lea dx,string1
mov ah,0ah
int 21h
lea dx,mess4
mov ah,09h
int 21h
lea si,str1
p5: mov dx,[si]
cmp dx,'0'
jl p1 ;dx<'0'
cmp dx,'9'
jle p2 ;'0'<=dx<='9'
cmp dx,'A'
jl p1 ;'9'<dx<'A'
cmp dx,'Z'
jle p3 ;'A'<=dx<='Z'
cmp dx,'a'
jl p1 ;'Z'<dx<'a'
cmp dx,'z'
jle p3 ;'a'<=dx<='z'
jmp p1 ;dx>'z'
p1: inc others ;bh中存放其他字符的个数
jmp p4
p2: inc numbers ;al中存放数字的个数
jmp p4
p3: inc letters ;bl中存放字母的个数
p4: inc si
dec ch
cmp ch,0
jnz p5
mov cl,4
p8: lea dx,mess1
mov ah,09h
int 21h
mov ch,2
jmp p7
p9: lea dx,mess2
mov ah,09h
int 21h
mov ch,2
jmp p12
p10: lea dx,mess3
mov ah,09h
int 21h
mov ch,2
jmp p13
p7: rol numbers,cl
mov bh,numbers
and bh,0fh
jmp p14
p12: rol letters,cl
mov bh,letters
and bh,0fh
jmp p16
p13: rol others,cl
mov bh,others
and bh,0fh
jmp p18
p14: add bh,30h
cmp bh,3ah
jb p15
add bh,07h
p15: mov dl,bh
mov ah,2
int 21h
dec ch
cmp ch,0
jnz p7
lea dx,mess4
mov ah,09h
int 21h
jmp p9
p16: add bh,30h
cmp bh,3ah
jb p17
add bh,07h
p17: mov dl,bh
mov ah,2
int 21h
dec ch
cmp ch,0
jnz p12
lea dx,mess4
mov ah,09h
int 21h
jmp p10
p18: add bh,30h
cmp bh,3ah
jb p19
add bh,07h
p19: mov dl,bh
mov ah,2
int 21h
dec ch
cmp ch,0
jnz p13
lea dx,mess4
mov ah,09h
int 21h
jmp exit
exit: ret
main endp
code ends
end start
此程序在编译和连接时都没有错误,只是结果有问题
运行结果如下:
Enter Sentence:
we are 123
按回车键出现如下结果:
The numbers of number:00
The numbers of letter:34
The numbers of others:FD
;*********************************************************************
data segment
string1 label byte
max1 db 80
act1 db ?
str1 db 80 dup(?)
numbers db ?
letters db ?
others db ?
mess1 db 'The numbers of number:','$'
mess2 db 'The numbers of letter:','$'
mess3 db 'The numbers of others:','$'
mess4 db 13,10,'$'
mess5 db 'Enter Sentence:',13,10,'$'
data ends
;*********************************************************************
code segment
main proc far
assume cs:code,ds:data,es:data
start: push ds
sub ax,ax
push ax
mov ax,data
mov ds,ax
mov es,ax
mov numbers,0
mov letters,0
mov others,0
mov ch,act1
lea dx,mess5
mov ah,09h
int 21h
lea dx,string1
mov ah,0ah
int 21h
lea dx,mess4
mov ah,09h
int 21h
lea si,str1
p5: mov dx,[si]
cmp dx,'0'
jl p1 ;dx<'0'
cmp dx,'9'
jle p2 ;'0'<=dx<='9'
cmp dx,'A'
jl p1 ;'9'<dx<'A'
cmp dx,'Z'
jle p3 ;'A'<=dx<='Z'
cmp dx,'a'
jl p1 ;'Z'<dx<'a'
cmp dx,'z'
jle p3 ;'a'<=dx<='z'
jmp p1 ;dx>'z'
p1: inc others ;bh中存放其他字符的个数
jmp p4
p2: inc numbers ;al中存放数字的个数
jmp p4
p3: inc letters ;bl中存放字母的个数
p4: inc si
dec ch
cmp ch,0
jnz p5
mov cl,4
p8: lea dx,mess1
mov ah,09h
int 21h
mov ch,2
jmp p7
p9: lea dx,mess2
mov ah,09h
int 21h
mov ch,2
jmp p12
p10: lea dx,mess3
mov ah,09h
int 21h
mov ch,2
jmp p13
p7: rol numbers,cl
mov bh,numbers
and bh,0fh
jmp p14
p12: rol letters,cl
mov bh,letters
and bh,0fh
jmp p16
p13: rol others,cl
mov bh,others
and bh,0fh
jmp p18
p14: add bh,30h
cmp bh,3ah
jb p15
add bh,07h
p15: mov dl,bh
mov ah,2
int 21h
dec ch
cmp ch,0
jnz p7
lea dx,mess4
mov ah,09h
int 21h
jmp p9
p16: add bh,30h
cmp bh,3ah
jb p17
add bh,07h
p17: mov dl,bh
mov ah,2
int 21h
dec ch
cmp ch,0
jnz p12
lea dx,mess4
mov ah,09h
int 21h
jmp p10
p18: add bh,30h
cmp bh,3ah
jb p19
add bh,07h
p19: mov dl,bh
mov ah,2
int 21h
dec ch
cmp ch,0
jnz p13
lea dx,mess4
mov ah,09h
int 21h
jmp exit
exit: ret
main endp
code ends
end start
此程序在编译和连接时都没有错误,只是结果有问题
运行结果如下:
Enter Sentence:
we are 123
按回车键出现如下结果:
The numbers of number:00
The numbers of letter:34
The numbers of others:FD
作者: aomi98 发布时间: 2011-06-19
Assembly code
; ;This Program Compiled Sucess by Masm 6.15 ; assume cs:code,ds:data data segment msg db 'Enter a string:$' buffer db 80,0,80 dup (0) _number db 0 _cap db 0 _low db 0 _other db 0 nummsg db 'numbers of digit:$' capmsg db 'numbers of cap-letter:$' lowmsg db 'numbers of low-letter:$' othmsg db 'numbers of other-char:$' data ends code segment start: mov ax,data mov ds,ax mov dx,offset msg mov ah,9 int 21h mov dx,offset buffer mov ah,10 int 21h call crlf mov bx,offset buffer+2 mov cl,buffer+1 s: mov al,[bx] cmp al,'0' jae sz jmp oth sz: cmp al,'9' jbe num jmp zm num: inc _number jmp jx zm: cmp al,'A' jae zm0 jmp oth zm0: cmp al,'Z' jbe zm1 jmp zm2 zm1: inc _cap jmp jx zm2: cmp al,'a' jae zm3 jmp oth zm3: cmp al,'z' jbe zm4 oth: inc _other jmp jx zm4: inc _low jx: inc bx loop s mov dx,offset nummsg mov ah,9 int 21h mov dl,_number call disp call crlf mov dx,offset capmsg mov ah,9 int 21h mov dl,_cap call disp call crlf mov dx,offset lowmsg mov ah,9 int 21h mov dl,_low call disp call crlf mov dx,offset othmsg mov ah,9 int 21h mov dl,_other call disp mov ah,4ch int 21h ;crlf crlf proc uses ax dx mov ah,2 mov dl,13 int 21h mov dl,10 int 21h ret crlf endp ; ;input:dx disp proc uses dx mov ax,dx xor dx,dx mov bx,10 mov cx,0 d2: cmp ax,10 jb ok2 div bx add dl,30h push dx xor dx,dx inc cx jmp d2 ok2: add al,30h push ax inc cx d3: pop dx mov ah,2 int 21h loop d3 ret disp endp ; code ends end start
作者: masmaster 发布时间: 2011-06-19
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28