title: How to prompt user for string and display it again in Assembly Language Programming
body: <p>I'm having trouble with my assembly language code.</p>
  
  <p>We were asked to prompt user for input string and we're supposed to display it again or echo it to the command line. We need to assume that it's only up to 20 characters (in the string)</p>
  
  <p><strong>This is the sample output:</strong></p>
  
  <p><strong>Enter a string (max 20 char.)</strong> </p>
  
  <p><strong>012345678901234567890</strong></p>
  
  <p><strong>The string you entered is:</strong></p>
  
  <p><strong>012345678901234567890</strong></p>
  
  <p>When I run my code in DOSBOX, I enter: 0123456789
  After hitting enter it shows me a bunch of characters and symbols that look weird...</p>
  
  <p>Here is my code:</p>
  
  <pre><code>.186 
  
  data    segment                         
  
  message1 db "Enter a string (max 20 char.): " ,13, 10, '$'
  
  message2 db "The string you entered is: " , 13, 10, 'S'
  
  myBStr db 20, 21 dup(?) ,'S' 
  
  data    ends
  stack1  segment stack       
      db  100 dup(?)                  ; This is the stack of 100 bytes
  stack1  ends
  
  
  code    segment
      assume  cs:code, ds:data, ss:stack1
  
  start: 
      mov ax, data                    
      mov ds, ax                      
      mov ax, stack1                  
      mov ss, ax      
  
  
      lea dx, message1                    ;load message to dx
      mov ah, 9h                          ;show this message
      int 21h
  
      mov ah, 0Ah                         
      lea dx, myBStr                      ;Load address of string
      int 21h
  
      mov ah, 9h                          ; show message of entered string
      int 21h
  
      lea dx, message2                    ;load second message to dx
      mov ah, 9h                          ;show this message
      int 21h
  
      mov ah, 0Ah                         
      lea dx, myBStr                      ;Load address of string
      int 21h 
  
      mov ah, 4ch                     ;Set up code to specify return to dos
      int 21h                     
  code    ends
  end     start
  </code></pre>