汇编_分类统计字符个数(附源代码)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

;****分类统计字符个数************

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

2.输入字符,得出结果

.386

.model flat

ExitProcess proto near32 stdcall, dwexitcode:dword

INCLUDE io.h

cr EQU 0dh

lf EQU 0ah

.STACK 4096

.DA TA

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

相关文档
最新文档