如何解决ARM 程序集,将换行符ASCII 10更改为空终止并重新打印后,将打印出额外的字符字母 A
该程序的目的是采用换行终止字符串 (ASCII 10) 并使其成为空终止字符串。我正在尝试将空终止字符串打印回控制台进行确认,但这是我看到的行为:
pi@raspBerrypi:~ $ ./tester
Please enter 4 different numbers between 1-5 together without space or special characters.
1234
1234A
pi@raspBerrypi:~ $
pi@raspBerrypi:~ $
这是程序,我跟踪了它,但我没有看到 A 来自哪里。这是为 ARMv7 编写的程序集
.global _start
_start:
LDR r1,=prompt
BL _sPrint
LDR r1,=userInput @ point to the space allocated for input
MOV r2,#4 @ set the limit of character to read in
BL _sInput
LDR r1,=userInput
BL _sPrint
Ldr r1,=newline
BL _sPrint
B _exit
@_sPrint prints out a string based on it's variable length determined by _strlen
@strlen,and findEnd are both needed for _sPrint.
_sPrint:
MOV r7,#4 @sets r7 to console STDOUT
MOV r0,#1 @set WRITE destination to STDOUT (terminal)
PUSH {r0,r1,lr}
BL _strLen @gets the stringlength and the end
POP {r0,lr}
SWI 0
mov pc,lr
_strLen:
mov r2,#0
findEnd:
ldrb r0,[r1],#1
add r2,r2,#1
cmp r0,#0
bne findEnd
sub r2,#1
mov pc,lr
_sInput:
PUSH {R1-R8,lr}
MOV r7,#3 @register r7 being set to 3 to indicate message being read in (read syscall)
MOV r0,#0 @Set READ device to the STDIN (keyboard)
SWI 0
POP {R1-R8,lr}
@String fix takes a string value at r1's address and changes the line Feed to be null termianted.
strfx:
LDRB r0,#1 @loads a single byte from r1 (r1 is dereferenced),which is the _sInput to r0
CMP r0,#10 @is r0 our newline?
BNE strfx
MOV r0,#0 @set r0 to null
STRB r0,[r1,#-1] @store r0's value back into r1's current address location. The final address
MOV PC,LR @location of r1 newline to be the NULL in r1.
_exit:
MOV r7,#1
SWI #0
.data
prompt: .asciz "\nPlease enter 4 different numbers between 1-5 together without space or special characters. \n \n"
newline: .asciz "\n"
userInput: .space 4
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。