0

I am new to mips and have an assignment in which I'm required to convert a string into an integer. The catch is that I my input string is prefixed with an arbitrary non-numeric character that must be removed and then 5 added to resulting integer. This is what I have so far, it removes the first letter of the string but that's all it does.

# Question 2
# Thuso Kharibe
# 23 september 2015

.data
   N: .word 0
   inp0: .space 20

   iMsg: .asciiz "Enter a a string:\n"
   oMsg: .asciiz "The values +5 is:\n"
   line: .asciiz "\n"

.text

   main:

   # ouput the prompt
   li $v0,4
   la $a0,iMsg
   syscall
   # get the string
   li $v0,8
   la $a0,inp0
   li $a1,100
   syscall

   # output the string prefix text
   li $v0,4
   la $a0,oMsg
   syscall
   # output the string
   la $t0, inp0
   lb $a0, ($t0)
   li $v0, 11
   syscall


   # exit
   jr $ra
Jon Sn0w
  • 3
  • 2
  • Questions regarding conversion from strings to integers have been asked many times before. Do a search. The principle is easy: the value of each digit is 10 times the value of the digit to its right, so all you need is a loop that multiplies and accumulates. – Michael Sep 22 '15 at 13:03
  • I can work through that but I'm terrible at mips so I'm still stuck at trying to remove the prefix char – Jon Sn0w Sep 22 '15 at 13:06
  • 1
    The address of the second character is the address of the first character + 1. – Michael Sep 22 '15 at 13:15

0 Answers0