I have to get from user up to 8 letter to string, and print the string in reverse.
There is my code :

STA SEGMENT STACK
    DB 100H DUP (0)
STA ENDS

DATA SEGMENT
    MSG1 DB 'ENTER STRING (Maximum is 8) : $'
    MSG2 DB 'REVERS IS : $'
    ISTR DB 10,?,10 DUP('$')
DATA ENDS

CODE SEGMENT
    ASSUME CS:CODE,DS:DATA,SS:STA
MAIN:
    MOV AX, DATA
    MOV DS, AX
    LEA DX, MSG1
    MOV AH, 09H
    INT 21H
    MOV DX, 0
;INPUT
    MOV DX, OFFSET ISTR
    MOV AH, 0AH
    INT 21H
    MOV SI, OFFSET ISTR
    MOV CX, [SI+1]
    ADD SI, 2
    MOV DX, 0
    MOV BX, CX
TOSTACK:
    MOV DX, [SI]
    PUSH DX
    INC SI
    LOOP TOSTACK
    MOV DL, 10
    MOV AH, 02H
    INT 21H
    LEA DX, MSG2
    MOV AH, 09H
    INT 21H
    MOV DX, 0
    MOV CX, BX
    MOV SI, 2
FROMSTACK:
    POP DX
    MOV AH, 02H
    INT 21H
    INC SI
    LOOP FROMSTACK

    MOV AX, 4C00H
    INT 21H

CODE ENDS
    END MAIN

My code Print the reversing string BUT WITH TRASH FROM MEMORY

trash.PNG

And I can write 10 numbers and then cant press enter.
or I can enter 9~(123456789) numbers and press enter the its will reverse 987654321.
And I need maximum 8 or minimum 1.

While I did write in x86 PC BIOS assembly it was long ago. This is just me sharing my thoughts on your issue.

First I'd change line 8 to be double in size since you can easily get into a buffer overflow situation. Either that or work your code in lines 20 to 28 to limit input to just 10 characters (a better way.)

Second I don't see and of course could have missed how you count the number of characters the user typed in. You'll need that later when you output your string.

Last the garbage output is usually due to not specifying the correct starting location of the characters, not telling if how many characters (we needed that in my second comment) or the BIOS call needed a ZERO at the last string location to know to stop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.