title: Assembly nasm; how to access front and end of string
body: <p>I am trying to convert input string '_Haris_I_' into 'Haris_I'. So I am trying to remove the underscore from the front and end of the string. I have already defined input and buffer pointers in memory and they store the char pointer to string '_Haris_I_'. This is the code I am using to do this, but it seems to not work for the front of the string:</p>
  
  <pre><code> ;;test front of buffer
  
           mov al, buffer
           cmp al, 0x5f
           jne test_end
  
         ;; move the buffer pointer to the next character
           mov eax, buffer
           inc eax
           mov buffer, eax
  
       ;; test end of buffer
         test_end:   
  
          push dword buffer
          call _strlen
          mov dword length, eax 
          mov ebx, length
          mov eax, buffer
          mov al, [eax+ebx-1] ;; put the final char of the string into al: "_"
          cmp al, 0x5f
          jne final_exit
          mov eax, buffer
          mov dword [eax+ebx-1], 0 ;; put 0 in place of the final char of the string ;to end the string prematurely
          mov buffer, eax
          add esp, 4
  
          final_exit:
          ;; // printf("|%s|\n",buffer); 
  ;copy buffer to input for printing
           mov eax, buffer
           mov ecx, input
           push eax
           push ecx
           call _strcpy
           add esp, 8
  
          push eax
  
          ;; free(buffer); 
          call _free
  
          add esp, 4
  
  
      leave 
      ret 
  </code></pre>