title: Loop/Input Logic Flow Issue (NASM x86 Assembly)
body: <p>I have a program below that tries to take input from the user and repeat that same string until the user enters it again. (It's a personal learning project)</p>
  
  <p>However, I am having some severe diffuculty in getting it to perform correctly. In a past thread <a href="https://stackoverflow.com/questions/8073996/x86-nasm-assembly-problems-with-input">here</a>, you can see the input, pun intended, that other users have provided on this problem.</p>
  
  <pre><code>%include "system.inc"
  
  section .data
      greet:      db 'Hello!', 0Ah, 'Please enter a word or character:', 0Ah
      greetL:     equ $-greet     ;length of string
      inform:     db 'I will now repeat this until you type it back to me.', 0Ah
      informL:    equ $-inform
      finish:     db 'Good bye!', 0Ah
      finishL:    equ $-finish
      newline:    db 0Ah
      newlineL:   equ $-newline
  
  
  section .bss
  
  input: resb 40  ;first input buffer
  check: resb 40  ;second input buffer
  
  section .text
  
      global _start
  _start:
  
  
  greeting:
      mov eax, 4
      mov ebx, 1
      mov ecx, greet
      mov edx, greetL
      sys.write
  
  getword:
      mov eax, 3
      mov ebx, 0
      mov ecx, input
      mov edx, 40
      sys.read
  
      sub eax, 1  ;remove the newline
      push eax    ;store length for later
  
  instruct:
      mov eax, 4
      mov ebx, 1
      mov ecx, inform
      mov edx, informL
      sys.write
  
      pop edx     ;pop length into edx
      mov ecx, edx    ;copy into ecx
      push ecx    ;store ecx again (needed multiple times)
  
      mov eax, 4
      mov ebx, 1
      mov ecx, input
      sys.write
  
      mov eax, 4  ;print newline
      mov ebx, 1
      mov ecx, newline
      mov edx, newlineL
      sys.write
  
      mov eax, 3  ;get the user's word
      mov ebx, 0
      mov ecx, check
      mov edx, 40
      sys.read
  
      sub eax, 1
      push eax
  
      xor eax, eax
  
  checker:
      pop ecx     ;length of check
      pop ebx     ;length of input
      mov edx, ebx    ;copy
      cmp ebx, ecx    ;see if input was the same as before
  
      jne loop    ;if not the same go to input again
  
      mov ebx, check
      mov ecx, input
  secondcheck:
  
      mov dl, [ebx]
      cmp dl, [ecx]
      jne loop    
      inc ebx
      inc ecx
      dec eax
      jnz secondcheck
  
      jmp done
  
  loop:
  
      pop edx
      mov ecx, edx
      push ecx
      mov eax, 4
      mov ebx, 1
      mov ecx, check
      sys.write   ;repeat the word
  
      mov eax, 4
      mov ebx, 1
      mov ecx, newline
      mov edx, newlineL
      sys.write
      mov eax, 3  ;replace new input with old
      mov ebx, 0
      mov ecx, check
      mov edx, 40
      sys.read
  
      jmp checker
  
  done:
  
      mov eax, 1  
      mov ebx, 0  
      sys.exit
  </code></pre>
  
  <p>Example output would yield:</p>
  
  <pre><code>Hello!
  Please enter a word or character:
  INPUT: Nick
  I will now repeat this until you type it back to me.
  Nick
  INPUT: Nick
  N
  INPUT: Nick
  
  INPUT: Nick
  </code></pre>
  
  <p>And that goes on forever until is ^C it to death. Any ideas on the problem?</p>
  
  <p>Thanks.</p>