[计算机]汇编_分类统计字符个数附源代码
;****分类统计字符个数************
年级 学号 班号 专业 姓名
型 综合型 创新型 实验 实验 分类统计字符个数 名称 类型
实验目的: 实 掌握分支程序设计的原理和方法,重点掌握各种分支程序中形成和判断条件而产生验 的程序段的设计方法和技巧。 目 实验要求: 的 程序接收用户输入的一行字符(字符个烽不超过80个,该字符串以回连符结束),并按或 字母、数字及其它字符类计数,然后将结果分别显示出来。要求有信息提示用户按照要要 求输入字符串,三类字符的个数分别在三行显示,并指明是哪类字符。 求
(对算法设计进行描述,变量定义和寄存器分配情况,画出程序
图或给出伪代码)
算法设计:
在下面的程序中,以读到的字符的ASCII码是否为0作为字符串末尾的标志;而进行三个逻辑判断(即数字字符判,大写字母字符判断和小写字母字符判)对相应字符的个数进行统计。在实现每一个逻辑判断时,用了两个判断指令:一个判断是否大于或等于该类型字符的最小ASCII码的字符,另一个判断是是否小于或等于该类型字符的最大ASCII码的字符,通过如此判断,便可实现上述的各个逻辑判断。
实 变量定义和寄存器分配: 验 prompt1为输入字符串的提示提示信息,charLabel、numberLabel、otherLabel分别原 为输出字母、数字及其它字符个数的提示信息 理 三个字属性内存变量forOther、forNumber、forChar分别
示其他字符个数,数字( 个数,字母个数。 算 stringIn用来接收输入的字符,char、number、other分别为字母、数字及其它字符法 个数的ASCII码表示。 流 ax, bx, cx分别储存相应字符个数 程 ) 程序伪代码:
(写不完时,可另加附页。)
data segment
string db 82
db 82 dup (?)
letter dw ?
digit dw ?
other dw ?
nextli db 0dh,0ah,'$'
printl db 'please a string',0dh,0ah,'-:$'
leprin db 'letter number:$' diprin db 'digiter number:$' otprin db 'other char:$' data ends
;-------------------------------- code segment
main proc far
assume ds:data,es:data,cs:code start:
mov ax,data
mov ds,ax
mov es,ax
;--------------------------------
mov ah,09h
lea dx,printl
int 21h
mov ax,0
mov ah,0ah
lea dx,string
int 21h
;--------------------------------
mov ah,09h
lea dx,nextli
int 21h
;--------------------------------
mov si,0
inc si
mov cl,string[si]
mov ax,0
mov bx,0
mov dx,0
;-------------------------------- loop1:
inc si
cmp string[si],2fh
jl cod1
cmp string[si],3ah
jnl cod2
inc bx
jmp cod4
cod2:
cmp string[si],40h
jl cod1
cmp string[si],5bh
jnl cod3
inc ax
jmp cod4
cod3:
cmp string[si],60h
jl cod1
cmp string[si],7bh
jnl cod1
inc ax
jmp cod4
cod1:
inc dx
cod4:
loop loop1 ;--------------------------------
toend:
mov letter,ax
mov digit,bx
mov other,dx
mov ah,09h
lea dx,leprin
int 21h
mov ax,letter
call print
mov ah,09h
lea dx,nextli
int 21h
mov ah,09h
lea dx,diprin
int 21h
mov ax,digit
call print
mov ah,09h
lea dx,nextli
int 21h
mov ah,09h
lea dx,otprin
int 21h
mov ax,other
call print
mov ah,09h
lea dx,nextli
int 21h
;--------------------------------
mov ah,01h
int 21h
mov ah,4ch
int 21h
;--------------------------------
main endp
;--------------------------------
;****实现输出的子程序************
print proc near
push ax
push bx
push cx
push dx
push si
mov bl,0ah loop2:
div bl
mov dl,ah
push dx
inc cx
mov ah,0
cmp ax,0
jnz loop2
printf:
pop dx
add dx,30h
mov ah,02h
int 21h
loop printf
pop ax
pop bx
pop cx
pop dx
pop si
ret
print endp
;--------------------------------
code ends
end start
组
内
分
工 (
可
选
)
(给出测试过程和测试结果,并对实验结果进行
。
可以写设计和实现整个过程
中的心得)
实验测试:
1(提示输入
实
验
结 2(输入字符,得出结果 果
分
析
及
心
得
体
会
结果分析:从输出结果看,结果正确。
心得体会:
成 绩 评 教师签名: 定 年 月 日 备注:源代码附后,源代码要求有注释说明
.386
.model flat
ExitProcess proto near32 stdcall, dwexitcode:dword
INCLUDE io.h
cr EQU 0dh
lf EQU 0ah
.STACK 4096
.DATA
prompt1 BYTE cr,lf,lf,"Please enter the string(<80).",cr,lf,lf
BYTE "The string is:",0 stringIn BYTE 1 DUP (?) charLabel BYTE cr,lf,"The number of char is:"
char BYTE 16 DUP (?)
BYTE cr,lf,0 numberLabel BYTE cr,lf,"The number of number is:"
number BYTE 16 DUP (?)
BYTE cr,lf,0 otherLabel BYTE cr,lf,"The number of other is:"
other BYTE 16 DUP (?)
BYTE cr,lf,0
.CODE
_start: output prompt1 ;提示输入字符
mov ax,0
mov bx,0
mov cx,0
begin:
input stringIn,1; 输入字符
cmp stringIn,0dh
je forOut ; 是回车则结束程序
cmp stringIn,0dh
jb forOther ;ASCII码值小于0dh则其他字符数加1
cmp stringIn,2fh
jbe forOther;ASCII码值小于或等于2fh则其他字符数加1
cmp stringIn,39h
jbe forNumber;ASCII码值小于或等于39h则数字数加1
cmp stringIn,40h
jbe forOther;ASCII码值小于或等于40h则其他字符数加1
cmp stringIn,5ah
jbe forChar;ASCII码值小于或等于5ah则字母数加1
cmp stringIn,60h
jbe forOther;ASCII码值小于或等于60h则其他字符数加1
cmp stringIn,7ah
jbe forChar;ASCII码值小于或等于7ah则字母数加1
jmp forOther;其他字符数加1
forOther: ;其他字符数加1,回到循环开始
inc ax
jmp begin
forNumber: ;数字数加1,回到循环开始
inc bx
jmp begin
forChar: ;字母数加1,回到循环开始
inc cx
jmp begin
forOut:
itoa other,ax
output otherLabel ;输出其他字符数
itoa number,bx
output numberLabel ;输出数字数
itoa char,cx
output charLabel ;输出字母数
INVOKE ExitProcess,0 PUBLIC _start
END