问题
;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
The input is a string up to 200 characters ("str"). It goes on the string and increace the ascii value location of each character in the string in the counter array ("arr"). The output is the several iterations of each ascii character [256 characters (the length of the counter array)]. For example:
a(005)3(016)%(109)
The problem is that if I write more than five characters, it displays just five of them and not the rest (all of them). What is the problem in the code?
important detail-
mone1
means counter1 and mone2
means counter2
Thank you!
回答1:
Your subroutine GetString:
lacks a ret
instruction. So it falls through to UpdateArr:
which does return, but is then called again, so who knows what effect that has, I am not going to explore to see if it satisfies the observed behaviour.
来源:https://stackoverflow.com/questions/36183130/the-output-is-not-displayed-in-its-entirety-8086-assembly