;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)
問題は、5 文字以上書くと、5 文字だけが表示され、残り (すべて) が表示されないことです。コードの問題は何ですか?
重要な詳細 -
mone1
counter1 をmone2
意味し、counter2を意味します。
ありがとうございました!