新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 匯編:統(tǒng)計(jì)字符串內(nèi)各種字符的數(shù)目

匯編:統(tǒng)計(jì)字符串內(nèi)各種字符的數(shù)目

作者: 時(shí)間:2016-12-01 來(lái)源:網(wǎng)絡(luò) 收藏
;對(duì)這個(gè)題目進(jìn)一步改造:
;3_7 用戶(hù)輸入一個(gè)由數(shù)字‘0’~‘9’英文大寫(xiě)字母‘A’~‘Z’;以及英文小寫(xiě)字母‘a’~‘z’組成的ASCII 字符串,
;字符串的結(jié)束符為 CR(即回車(chē)符,其ASCII 碼為0DH),字符串總長(zhǎng)度不超過(guò)256 個(gè)。
;要求統(tǒng)計(jì)傳送的字符總數(shù)以及其中各種字符的數(shù)目

DATA SEGMENT
SUM DB 00H ;總數(shù) 計(jì)數(shù)器
CAPITAL DB 00h ;大寫(xiě)字母?jìng)€(gè)數(shù) 計(jì)數(shù)器
small db 00h ;小寫(xiě)字母?jìng)€(gè)數(shù) 計(jì)數(shù)器
num db 00h ;數(shù)字個(gè)數(shù) 計(jì)數(shù)器
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) ;目標(biāo)內(nèi)存
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 ;將方向標(biāo)志位置零 串操作遞增
main: lods string ;字符串裝入指令 把字符串一個(gè)個(gè)裝入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號(hào)調(diào)用每次只輸出一個(gè)字符,即dl
INT 21H
LEA DX,kongzi ;換行
MOV AH,09H
INT 21H


上一頁(yè) 1 2 下一頁(yè)

關(guān)鍵詞: 匯編字符

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉