title: Reversing an input string in Assembly
body: <p>I have this assembly code that reverses a string that I input. It only accepts maximum 20 characters. My problem is that when I hit enter to see the output there is an extra character at the end of the reversed string.<br>
  Please help me understand why that does occur and how I can remove that in the output.<br>
  We're required to only use function 09H int 21h to display the string and function 0Ah int 21h to input the string. We're using TASM.<br>
  Your help would be very much appreciated. Thank you.</p>
  
  <p>Here is my code: </p>
  
  <pre><code>.model small
  .stack 100h
  .data 
      MSG DB "Input String(max 20 chars): ", 10, 13, "$"
      Sentence1 DB 21,?,21 dup("$")  
      str2 dw 21 dup("$")
  .code
  start:
      mov ax, @data
      mov ds, ax
  
      ;Getting the string input
          mov ah,09h
          lea dx, MSG
          int 21h
  
          lea si,Sentence1
          mov ah,0ah
          mov dx,si
          int 21h
  
      ;Reverse String    
          mov cl,Sentence1
          add cl,1
          add si,2
      loop1:
          inc si
          cmp byte ptr[si],"$"
          jne loop1
  
          dec si
          lea di,str2
      loop2:
          mov al,byte ptr[si]
          mov byte ptr[di],al
          dec si
          inc di
          loop loop2
  
          ;Printing the reverse string    
              mov ah,09h
              lea dx,str2
              int 21h    
  
          mov ah, 4ch
          int 21h
  end start 
  </code></pre>