;The number of repetition of each character in the string
.MODEL small
.STACK 100h
.DATA
msg3 db 13,10,'Enter a string up to 200 characters:$'
msg4 db ' $'
msg5 db 13,10,'Hit any key to exit',13,10,'$'
crlf db 13,10,'$'
char db 0
repet db 0
mone1 dw 0
mone2 dw 0
dig1 db 0
dig2 db 0
dig3 db 0
arr db 256 dup(0)
str db 200
strlen db 0
strtxt db 200 dup(0)
.CODE
mov AX,@data
mov DS,AX
call GetString
call UpdateArr
call Repetitions
call EndProject
GetString: lea DX,msg3 ;Show msg3 on screen
mov AH,09h
int 21h
lea DX,str ;Accept a string
mov AH,0ah
int 21h
lea DX,crlf ;New line for the output
mov AH,09h
int 21h
UpdateArr: xor CX,CX ;Nullify CX register
mov CL,strlen
cmp mone1,CX ;Compare the location of the character in str
string to the full length of str
jb Below ;If below, jump Below
ret
Below: lea SI,strtxt ;Reach a character in str string
add SI,mone1
mov CL,[SI]
mov char,CL ;Move the character from CL to char operand
inc mone1 ;Increase mone1 in one
lea BX,arr ;Nullify CX register
mov CL,char
add BX,CX
inc [BX] ;Increace the ascii value place of the character
in arr counter array in one
jmp UpdateArr
Repetitions: lea BX,arr ;Reach the several iterations of each ascii
character
add BX,mone2
xor CX,CX
mov CL,[BX]
mov repet,CL ;Move the several iterations from CL to repet
operand
inc mone2
cmp repet,0 ;Compare repet to zero
je Repetitions ;If there is no repetition at all, jump to
Repetitions
xor AX,AX ;Nullify AX register
xor BX,BX ;Nullify BX register
mov AL,repet
mov BL,10 ;Divide AL by 10, result in AL, rest in AH
div BL
mov dig3,AH ;Move the rest of the devision in AH to dig3
operand
mov AH,0 ;Nullify AH
mov BL,10 ;Divide the result in AL by 10, new result in AL,
rest in AH
div BL
mov dig2,AH ;Move the rest of the devision in AH to dig2
operand
mov dig1,AL ;Move the result of the devision in AL to dig1
operand
add dig1,'0' ;Change digit from binary to ascii
add dig2,'0'
add dig3,'0'
lea BX,msg4 ;Put address of msg4 in BX
dec mone2 ;Decreace mone2 in one
mov AX,mone2
mov [BX],AL ;Put mone2 (the ascii character) in msg4
inc mone2 ;Increace mone2 in one
mov AL,'('
mov [BX+1],AL ;Put '(' in msg4
mov AL,dig1
mov [BX+2],AL ;Put dig1 in msg4
mov AL,dig2
mov [BX+3],AL ;Put dig2 in msg4
mov AL,dig3
mov [BX+4],AL ;Put dig3 in msg4
mov AL,')'
mov [BX+5],AL ;Put ')' in msg4
lea DX,msg4 ;Show output line msg4
mov AH,09h
int 21h
cmp mone2,256 ;Compare mone2 to 256
jle Repetitions ;If not all the ascii characters were checked,
jump to Repetitions
ret
EndProject: lea DX,msg5 ;show msg5 on screen
mov AH,09h
int 21h
mov AH,01h ;read a char
int 21h
mov AH,4CH ;end program
int 21h
ret
END
输入是最多 200 个字符(“str”)的字符串。它继续字符串并增加计数器数组(“arr”)中字符串中每个字符的ascii值位置。输出是每个 ascii 字符 [256 个字符(计数器数组的长度)] 的多次迭代。例如:
一个(005)3(016)%(109)
问题是如果我写了五个以上的字符,它只会显示其中的五个而不是其余的(全部)。代码中的问题是什么?
重要细节——
mone1
表示 counter1 和mone2
表示 counter2
谢谢!