问题
I'm trying to determine the length of an input string using buffer and memory allocation. So lets say I allocate some memory and read a string and store it into the buffer. Then how can I figure out how long the string is?
回答1:
Count from the beginning until you find a null character (0).
Something like:
la $t0 string
loop:
lb $t1 0($t0)
beq $t1 $zero end
addi $t0 $t0 1
j loop
end:
la $t1 string
sub $t3 $t0 $t1 #$t3 now contains the length of the string
来源:https://stackoverflow.com/questions/17837287/determine-the-length-of-a-string-in-mips32