我想知道是否有人可以帮我解释如何摆脱mips中字符串中的特定字符。 例如,如果字符串是" + 104367" 我想摆脱+,并简单地说:104367。
答案 0 :(得分:0)
.data
str: .asciiz "Hello+World"
.text
main:
la $t0, str # la means load address (so we load the address of str into $t0)
li $t1, 0 # $t1 is the counter. set it to 0
la $t3, 43 # 43 is ASCII of '+' in DEC
countChr:
lb $t2, 0($t0) # Load the first byte from address in $t0
beqz $t2, end # if $t2 == 0 then go to label end
bne $t2, $t3, proceed # branch if symbol equals 43 (+)
la $t4, $t0 # save the position
proceed:
add $t0, 1 # else increment the address
add $t1, $t1, 1 # and increment the counter of course
j countChr # finally loop
end:
# Do whatever you want here.
# Just remember that the length of the string is stored in $t1
# Here you have the position of '+' saved to t4