title: Converting an integer input to hexadecimal in MIPS assembly
body: <p>I am writing a program in MIPS to convert an integer input by the user to hex and then output it. For some reason, no matter what I put in, the syscall only outputs 0x which is what I put in the answer space at the beginning. What am I doing wrong?</p>
  
  <pre><code>.data
  prompt1: .asciiz "Enter an integer number: "
  answer: .space 8
  .text
  .globl main
  
  main:
          la $a0, prompt1     #prompt user for integer
          li $v0, 4
          syscall
  
          la $a1, answer      # load the address of answer into $a1
          addi $t0, $zero, 48 #set $t0 to 48
              sb $t0, 0($a1)          #store 48 at location 0 in $a1
              addi $t0, $0, 120       #set $t0 equal to 120
              sb $t0, 1($a1)          #store 120 at location 1 in $a1
              addi $a1, $a1, 4
  
              li $v0, 5       #allow for input of integer
          syscall
          add $a0, $v0, $zero #add the input to the $a0 register
          jal print_hex
  
          la $a0, answer
          li $v0, 4
          syscall         #print out hex answer to console
  
          j main
  
  
  print_hex:
          andi $t0, $a0, 0xf
          addi $a1, $a1, 4
  
          ble $t0, 10, lessThanTen        
          addi $t0, $t0, 39   
      lessThanTen:
          addi $t0, $t0, 48
          sb $t0, 0($a1)
          srl $a0, $a0, 4
          bne $a0, $zero, print_hex
      done:
          jr $ra
  </code></pre>