title: Palindrome Check Assembler - MIPS
body: <p>I am very new to Assemlber (MIPS) and I have to program a palindrome checker. I am not getting how to do this. What I got to work is, to calculate the length of the String as follows:</p>
  
  <pre><code>     .data
  string: .asciiz "hello"
  
  printedMessage: .asciiz "The length of the string: "
  
      .text
  main:
    la $a0, string             # Load address of string.
          jal strlen              # Call strlen procedure.
          jal print
          addi $a1, $a0, 0        # Move address of string to A1
          addi $v1, $v0, 0        # Move length of string to V1
          addi $v0, $0, 11        # System call code for message.
          la $a0, printedMessage            # Address of message.
          syscall
          jal reverseString
          addi $v0, $0, 10        # System call code for exit.
          syscall
  
  
  strlen:
      li $t0, 0 # initialize the count to zero
      loop:
          lb $t1, 0($a0) # load the next character into T1
          beqz $t1, exit # check for the null character
          addi $a0, $a0, 1 # increment the string pointer
          addi $t0, $t0, 1 # increment the count
          j loop # return to the top of the loop
      exit:
          jr $ra
  
  print:
      li $v0, 4
      la $a0, printedMessage
      syscall
  
      li $v0, 1
      move $a0, $t0
      syscall
  
      jr $ra
  </code></pre>
  
  <p>But I did this by reading examples etc. so now I want to reverse the String, but I run into some troubles here.</p>
  
  <p>What I want to do is</p>
  
  <pre><code>set j = strLength - 1
  while(j&gt;=0){
  load next character
  store character to array
  j--
  }
  </code></pre>
  
  <p>I try it as follows:</p>
  
  <pre><code>reverseString:
      li $t2, 0
      la $a0, string
      add $t2,  $t2, $t0 #initialize j with length of string - 1
      sub $t2, $t2, 1
      loop2:
          add $t3, $t2, $a0
          lb $t1, 0($t3) #load the next character into T1
          beq $t2, $0, exit
          subi $t2, $t2, 1 #j--
          j loop2
  </code></pre>
  
  <p>This code iterates backwards through the string, but how do i make a new string which I add the character in <code>$t1</code> each iteration</p>
  
  <p>I need to keep the originial string and also the reversed so i can loop through and check if they are equal.</p>