问题描述
试图学习一些基本的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 (将#修改为@)