title: Reversing a string given by the user in Assembly Language
body: <p>I am working on a program in Assembly Language right now where the user can input any word of their preference and then the program will reverse it. So, if the user inputs <strong>HELLO</strong> and the program will output <strong>OLLEH</strong>.</p>
  <p>The algorithm I decided to implement was by first getting the length of the string and storing it in <code>length</code>. I will then use the length to traverse backward in the given string and store each character in a new memory location which is <code>REVERSE</code>. I tested my program several times but it only outputs one character. I tried several words and noticed that the character is always output is the second character of the string so I am unsure if it is able to reverse the word or not.</p>
  <p>Did I miss anything or I implemented a code block incorrectly?</p>
  <p><em>Note: The <code>GET_STRING[end] 5</code> is used when I run the code in <code>.exe</code> format.</em></p>
  <p>Below is the code I am currently working on:</p>
  <pre><code>%include &quot;io.inc&quot;
  section .data
  string dd 0x00
  end dd 0x00
  REVERSE dd 0x00
  length db 0
  
  section .text
  global CMAIN
  CMAIN:
      ;write your code here
      
      PRINT_STRING &quot;Please enter a string: &quot;
      GET_STRING [string], 10
      
      lea esi, [string]
      lea edi, [REVERSE]
      lea ecx, [length]
      
  L1:
      mov al, [esi]
      cmp al, 0
      JE FINISH
      JNE INCREMENT
      inc esi
      jmp L1
  
  INCREMENT:
      inc byte[length]
      inc esi
      jmp L1
      
  
      FINISH: 
      L2:
  ;points to the current index of the string (i.e. if Hello,it will first point at 'o' which is 5
      mov al, [ecx] 
      cmp cl, 0  ;checks if length == 0
      JE DONE
      JNE DECREMENT
      dec ecx
      jmp L2
  
  DECREMENT:
      mov byte[edi], al ;adds a character from [string]
      dec ecx
      jmp L2
      
  DONE:
      PRINT_STRING REVERSE
      GET_STRING[end], 5
      xor eax, eax
      ret
  </code></pre>