title: print ascii characters in mips
body: <p>I'm taking a Computer Design course which is MIPS programming (we're using the MARS simulator).</p>
  
  <p>We got an assignment and I got very confused. I'm new to this and having some problems.
  My task was as following:
  define in .data the following
  buf: .space 21
  buf1: .space 20</p>
  
  <p>get a 20-char long string from the user using syscall 8, and do the following:
  compare the ASCII values of buf[i] and buf[i+1]
  if it's positive, copy '+'to buf1, if it's negative do '-' and if it's equal do '='
  in the end print buf1 and the number of '=' in buf1.</p>
  
  <p>what I have so far is:</p>
  
  <pre><code>.data
  buf: .space 21
  buf1: .space 20
  msg1: .asciiz "The number of identical char in a row is: "
  #+ is 43 in ascii
  #- is 45 in ascii
  #= is 61 in ascii decimal
  ################# Code segment ####################
  #
  .text
  .globl main
  main:   # main program entry
      la $a0, buf 
      li $a1, 20
      li $v0, 8
      syscall
  
  loop:  
      la $s0, buf
      lb $t0, 0($s0) #buf[0]
      addi $s0, $s0, 1 # buf++
      lb $t1, 0($s0) #buf[1]
      beqz $t0, exit #if null, terminate
      bgt $t0, $t1, greater
      blt $t0, $t1, lesser
      beq $t0, $t1, equal
  greater:
      lb $t1, 43
      sb $t1, buf1
      la $a0, buf1
      li $v0, 4
      syscall
  
      j loop
  lesser:
  
      j loop
  equal:
  
      j loop
  print:
      la $a0, buf1
      li $v0, 4
      syscall
  exit:
      li $v0, 10       # Exit program
      syscall
  </code></pre>
  
  <p>so I am comparing buf[0] and buf[1] using $t0 and $t1 and doing bgt to greater label.</p>
  
  <p>How do I "copy" the signs from ascii and print them? I noted to myself that '+' is 43 ASCII value. what do I do with it? how do I add it to buf1 and then print it in the end?
  I know the code incomplete but I will appreciate any help.</p>
  
  <p>Thank  you!</p>