请教一下这段代码的后续编写
2022-11-29 17:20
程序代码:
DATA SEGMENT
Counter DB 0,0,0 ;数字,小写,大写...的数量
result db 10,13,'Number(' ;结果字串
N_num db 0,0,'), LowerLetter(' ;数字总量字串
L_num db 0,0,'), UpperLetter(' ;小写总量字串
U_num db 0,0,')',10,13,'$' ;大写总量字串
Addr_Off dw offset N_num,offset L_num,offset U_num ;各总量地址
DATA ENDS
Code SEGMENT
ASSUME CS: Code,DS: DATA
START:
MOV AX, DATA
MOV DS, AX
mov cx,100 ;限制数量
cld ;正向
Readkey:
mov ah,1 ;读键
int 21h ;调用dos
cmp al,0dh ;是否回车
jz Done ;是,跳
mov bx,0 ;bx = 0,数字数量位置
cmp al,'0' ;比较'0'
jb Readkey ;少于,其他字符,重来
cmp al,'9' ;比较'9'
jbe Counting ;少于,0~9内,跳counting
mov bx,2 ;bx = 2,大写数量位置
cmp al,'A' ;比较'A'
jb Readkey ;少于,其他字符,重来
cmp al,'Z' ;比较'Z'
jbe Counting ;少于,A~Z内,跳counting
mov bx,1 ;bx = 1,小写数量位置
cmp al,'a' ;比较'a'
jb Readkey ;少于,其他字符,重来
cmp al,'z' ;比较'z'
ja Readkey ;大于,其他字符,重来
Counting:
inc byte ptr Counter[bx] ;以bx作为索引,加对应(0.1或2)的数量
loop Readkey ;下一个
Done:
mov cx,3 ;=3
mov bx,offset Addr_Off ;结果字串地址
mov si,offset Counter ;元素数量起始
@@:
lodsb ;al=ds:[si], si+1
aam ;bcd调整,若al=0Ch,aam后,ax=0102
or ax,3030h ;转为ascii字符
xchg al,ah ;交换
mov di,[bx] ;取相应的数量字串地址
mov [di],ax ;存入数字符
add bx,2 ;下一组
loop @b ;回圈,跳到上一个@@:
mov ah,9 ;输出函数
mov dx,offset result ;结果地址
int 21h ;调用dos
mov ah,4ch ;离开
int 21h ;调用dos
Code ENDS
END START
2022-11-29 18:25
2022-11-29 22:18
2022-11-30 03:45

2022-11-30 12:25
2022-11-30 13:19
程序代码:
DATA SEGMENT
Counter DB 0,0,0 ;数字,小写,大写...的数量
result db 10,13,'Number(' ;结果字串
N_num db 0,0,'), LowerLetter(' ;数字总量字串
L_num db 0,0,'), UpperLetter(' ;小写总量字串
U_num db 0,0,')',10,13,'$' ;大写总量字串
Addr_Off dw offset N_num,offset L_num,offset U_num ;各总量地址
StringInput db 100,?,100 dup (?) ;输入缓冲
DATA ENDS
Code SEGMENT
ASSUME CS: Code,DS: DATA
START:
MOV AX, DATA
MOV DS, AX
cld ;正向
lea dx, StringInput ;取输入缓冲地址
mov ah,0Ah ;输入字串函式
int 21h ;调用dos
lea si,StringInput+2 ;实际输入地址
xor cx,cx ;cx=0
mov cl,[si-1] ;取实际输入字符数
jcxz exit ;若cx=0,即无输入,离开
Reload:
lodsb ;al=ds:[si], si+1
cmp al,0dh ;是否回车
jz Done ;是,跳
mov bx,0 ;bx = 0,数字数量位置
cmp al,'0' ;比较'0'
jb Reload ;少于,其他字符,重来
cmp al,'9' ;比较'9'
jbe Counting ;少于,0~9内,跳counting
mov bx,2 ;bx = 2,大写数量位置
cmp al,'A' ;比较'A'
jb Reload ;少于,其他字符,重来
cmp al,'Z' ;比较'Z'
jbe Counting ;少于,A~Z内,跳counting
mov bx,1 ;bx = 1,小写数量位置
cmp al,'a' ;比较'a'
jb Reload ;少于,其他字符,重来
cmp al,'z' ;比较'z'
ja Reload ;大于,其他字符,重来
Counting:
inc byte ptr Counter[bx] ;以bx作为索引,加对应(0.1或2)的数量
loop Reload ;下一个
Done:
mov cx,3 ;=3
mov bx,offset Addr_Off ;结果字串地址
mov si,offset Counter ;元素数量起始
@@:
lodsb ;al=ds:[si], si+1
aam ;bcd调整,若al=0Ch,aam后,ax=0102
or ax,3030h ;转为ascii字符
xchg al,ah ;交换
mov di,[bx] ;取相应的数量字串地址
mov [di],ax ;存入数字符
add bx,2 ;下一组
loop @b ;回圈,跳到上一个@@:
mov ah,9 ;输出函数
mov dx,offset result ;结果地址
int 21h ;调用dos
exit:
mov ah,4ch ;离开
int 21h ;调用dos
Code ENDS
END START
2022-11-30 13:51
2022-11-30 19:59