title: x86 NASM Assembly - Problems with Input
body: <p>I am working to take input from a user twice, and compare the input. If they are the same, the program exits. If not, it reprints the input from the first time, and waits for the user to type something. If it is the same, the same thing as before occurs. If not, the same thing as before occurs.</p>
  
  <p>Input and looping is not the problem. The main problem is the result I am getting from the program. My following is what I am doing codewise:</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 %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:   db $-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
  
          xor eax, eax
  
      checker:
          mov ebx, check
          mov ecx, input
          cmp ebx, ecx    ;see if input was the same as before
  
          jne loop    ;if not the same go to input again
          je done     ;else go to the end
          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
  
  
  
      loop:
          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
      sys.write
  
  getword:
      mov eax, 3
      mov ebx, 0
      mov ecx, input
      mov edx, 40
      sys.read
  </code></pre>
  
  <p>My result is now: EDITED</p>
  
  <pre><code>Hello!
  Please enter a word or character:
  Nick
  I will now repeat this until you type it back to me.
  Nick
  (I input) Magerko
  (I get) M
  (I input)Nick
  (I get)
  (I input)Nick
  (I get)
  </code></pre>
  
  <p>EDITED</p>
  
  <p>And this continues. My checks do not work as intended in the code above, and I eventually don't even get the program to print anything but a newline. Is there a reason for this?</p>
  
  <p>Thanks.</p>