Determine the length of a string in MIPS32

孤街浪徒 提交于 2021-02-17 05:43:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!