loops - ARM中的字符串长度?
问题描述
试图学习一些基本的ARM,我试图弄清楚如何使用while循环来获取字符串的长度。以下是我在 C 中尝试实现的目标,也是我在 ARM 中尝试实现的目标。我的问题来自 while 循环,我无法遍历字符串,直到我遇到空终止符并使用变量跟踪它。
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,x19, 1
b get_length_loop
#return result
mov x0, x19
ret
exit:
mov x0, 0
mov x8, 93
svc 0
ret
解决方案
推荐阅读
- javascript - 两个 ios 版本中的画外音默认焦点行为不同
- c# - C# GC 可以移动内存对象吗
- coldfusion - 试图从表中提取最后一个 id 并按特定列分组
- javascript - Bootstrap modal 和 JS onChange(),有可能吗?
- python - 格式化字符串属性
- directadmin - 使用 directadmin 控制面板创建两级子域
- matlab - 陷波滤波最小化信号中的伪影
- sql-server - 如何在没有USE语句的情况下执行SqlPackage命令行生成脚本
- linux - poll() 系统调用卡在 restart_syscall()
- excel - 如何使用excel vba从网站中提取价格?