【发布时间】:2021-03-04 23:41:18
【问题描述】:
这个程序应该要求输入字符串并计算字符数 知道为什么我输入的任何内容都会得到 0 个字符。
例如,当我输入 hello 时, 输出是:“有 0 个字符:“你好”
这是我的代码:
.data
courseStr: .string "myName\t"
userInput: .string "\nThe string is:"
countMessage: .string "There are %d charachters in:\"%s\".\n"
temp: .word 10
inputBuffer: .skip 15
inputValue: .string "%s"
.text
.global main
main:
STMDB SP!, {R4,LR}
LDR R0, =courseStr
BL puts
LDR R0, =userInput
BL printf
LDR R0, =inputValue
从用户那里获取输入
LDR R1, =inputBuffer
BL scanf
获取char函数
getLine:
MOV R2,R0
BL getchar
调用计数字符循环函数
LDR R0,=inputBuffer
BL countCharactersLoop // call the counter
字符循环函数 countCharactersLoop: // 计数器
LDRB R0,[R1,R2]
CMP R0,#00 // if null then print
BEQ countCharactersDone
ADD R1,R2, #01 // if not null add one
B countCharactersLoop // repeat
如果 char 为 null 那么我们打印结果 如果没有,我们继续计数
countCharactersDone:
// print "there are (numberOfChars) in the string inputed"
LDR R2,=inputBuffer
MOV R1,R0
LDR R0, =countMessage
BL printf
LDMIA SP!,{R4,LR}
MOV R0, R2
BX LR
【问题讨论】:
-
你有什么问题?
-
请edit您的问题添加一个实际问题。此外,将错误描述移到问题的正文中,并尽可能选择更好的标题。
标签: string assembly counter armv7