Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

MIPs code programming?

am working on a mips program to convert numbers from ascii string into integers, with the parameter that it should accept positive and negative integer decimal strings. I know this is a pretty common a assignment but I wasn't able to resolve my problems online. I was able to get some tips, but still receiving errors when trying to run the program. I haven't been able to fix the errors, I have no idea what to do with them. I am getting bad address exceptions starting with this line "lb $t1, ($t0) # load $t1 = digit character"

This is my first time coding in assembly, please give me some guidance, I am completely lost.

Here is the code I have at this time:

.data

string: .byte '1','2','3','0' # create a 2-element character array

.text

main: # convert string to integer

lw $a0, string

li $t6, 0x00 # $t6 = 0

li $t7, 0x09 # $t7 = 9

li $v0, 0x00 # initialize $v0 = 0

lb $t0, ($a0) # $t0 = pointer to string

lb $t1, ($t0) # load $t1 = digit character

loop:

blt $t1, $t6, Done # check for each char < 0

bgt $t1, $t7, Done # check for each char > 9

subu $t1, $t1, $t6 # convert char to int

mul $v0, $v0, 10 # mult by 10 to shift value

add $v0, $v0, $t1 # add new digit to value

addiu $t0, $t0, 1 # point to next char

lb $t1, ($t0) # load next digit

bne $t1, $0, loop # repeat if not end of string

jr $ra # return integer

Done: #exit program if string not a number

li $v0, -1 # return -1 in $v0

jr $ra

1 Answer

Relevance
  • Anonymous
    9 years ago
    Favorite Answer

    Report this problem to the programming service to get things fixed.

Still have questions? Get your answers by asking now.