如何解决ARM中的字符串长度?
试图学习一些基本的ARM,我试图弄清楚如何使用while循环来获取字符串的长度。以下是我试图在C中实现的目标,也是我试图在ARM中实现的目标。我的问题来自while循环,直到击中null终止符并使用变量跟踪它,我才能遍历该字符串。
char inputString[7];
int lengthOfInput = 0;
while (inputString[lengthOfInput] != '\0')
{
lengthOfInput++;
}
.section .data
#need to include \n if you want to test the output. no idea why
input_prompt : .asciz "string: "
input_spec : .asciz "%[^\n]"
length_spec : .asciz "length: %d\n"
#8 bytes for 7 characters plus \0
input: .space 8
.section .text
.global main
main:
#print prompt
ldr x0,=input_prompt
bl printf
#get input
ldr x0,=input_spec
ldr x1,=input
bl scanf
#call get_length
ldr x9,=input
ldrsw x0,[x9]
bl get_length
#print result from get_length
#to do
#exit
b exit
get_length:
#intializing "i" as 0
add x19,xzr,xzr
get_length_loop:
#address of userString[i]
add x12,x19,x1
#if == 0,go somewhere,maybe get_length should be changed
cbz x12,get_length
add x19,1
b get_length_loop
#return result
mov x0,x19
ret
exit:
mov x0,0
mov x8,93
svc 0
ret
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。