Read a line and print it backwards.
Input
One line of 1 to 40 characters (letters, digits, spaces and punctuation).
Output
The same characters in reverse order.
Examples
Example 1 · Input
stack
Expected output
kcats
Example 2 · Input
a
Expected output
a
Hints
Hint 1
Read keys until Enter, pushing each one (PUSH AX) and counting them in CX.
Hint 2
Then pop CX times and print each character: the stack gives them back last first.
Hint 3
If the line could be empty, JCXZ would skip the loop; here it always has at least one character.
Solution
Show one correct solution (try it yourself first)
; Backwards
.MODEL SMALL
.STACK 100H
.CODE
MAIN PROC
MOV CX, 0
READ:
MOV AH, 1
INT 21H
CMP AL, 0DH
JE PRINT
PUSH AX
INC CX
JMP READ
PRINT:
POP DX ; the last character read comes first
MOV AH, 2
INT 21H
LOOP PRINT
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN