title: How to deal with unknown length input in x86 ASM?
body: <p>So I have most of the code working, but I cannot figure out how exactly to deal with the fact that the input sentence is of an unknown length. I am new to assembly and this is all a bit confusing.</p>
  
  <p>(Right now I have it set up as if the length were known to be three characters, but obviously I need to change that.)</p>
  
  <pre><code>.data       
  input_msg:  .ascii "Enter a random sentence: "
  input_msg_len:  .long 25
  input_str:  .ascii  "???" # 3rd should get newline  
  count:      .long 0 
  newline:    .long 10    
  
  .text               
  .global _start          
  _start:             
  
  # prompt for input
      mov $4, %eax    # prompt for input
      mov $1, %ebx
      mov $input_msg, %ecx
      mov input_msg_len, %edx
      int $0x80
  # get input
      mov $3, %eax    # 3 to request "read"
      mov $0, %ebx    # 0 is "console" (keyboard)
      mov $input_str, %ecx # input buffer addr
      mov $3, %edx    # number of symbols typed in
      int $0x80       # Go do the service!
  
  again1:
      mov $input_str, %ecx    
      add count, %ecx # count is offset from input_str beginning
  
      mov $4, %eax    # to write
      mov $1, %ebx    # to console display
      mov $1, %edx    # 1 byte to write
      int $0x80   # Do it!
  
      push    %ecx        # push onto stack   
  
      incl    count   # increment count
  
      cmp $3, count   # compare lengths
      jnz again1     # jmp again if not 0 (no difference)
  
      mov $0, %edi    # use edi as loop counter
  
      mov $4, %eax    # print out msg
      mov $1, %ebx    # etc.
      mov $1, %edx    # length
      int $0x80       # OS, serve!
  
  again2:     
      pop %ecx    
  
      mov $4, %eax    # print out msg
      mov $1, %ebx    # etc.
      mov $1, %edx    # length
      int $0x80       # OS, serve!        
  
      inc %edi    # increment edi 
      cmp count, %edi # compare lengths
      jnz again2  # jmp again if not 0 (no difference)
  
  # print newline
      mov $4, %eax    # print out msg
      mov $1, %ebx    # etc.
      mov $newline, %ecx  # addr
      mov $1, %edx    # length
      int $0x80       # OS, serve!
  # exit
      mov $1, %eax    # exit
      int $0x80       # OS, serve!    
  </code></pre>
  
  <p>Basically, what I want to know is how do I get the code to work for any sentence rather than just one 3 characters long? </p>