我正在创建一个程序来使用一个名为String_Length()
输出用户字符串输入长度的外部文件(例如“Cat in the hat”)。
输入字符串后,我不断收到分段错误。我想知道我在这个程序中到底做错了什么。String_Length.s
工作正常,只需要知道我的主要功能有什么问题。任何帮助深表感谢。
.data
szEnter: .asciz "Enter STRING: "
szLength: .asciz "STRING LENGTH: "
strLen: .word 0
szString: .skip 12
endl: .byte 10
.text
.global _start @ Provide program starting address to Linker
_start:
@ ENTER STRING
ldr r0, =szEnter @ Load address of r0 into szString
bl putstring @ Display the string to the terminal
@ READ-IN STRING DATA
ldr r0, =szString @ Load address of r0 into szString
mov r1, #12 @ Load address of r1 into 12 bytes
bl getstring @ Read a string of characters terminated by a null
@ COUNT LENGTH OF STRING
ldr r0, =szString @ Load address of r0 into szString
bl string_Length @ Counts the characters in the string
@ OUTPUT LENGTH OF STRING
ldr r0, =szLength @ Load address of r0 into szLength
bl putstring @ Display the string to the terminal
ldr r0, =strLen @ Load address of r0 into strLen
bl putstring @ Display the string to the terminal
@ Newline
ldr r0, =endl
bl putch
mov r0, #0 @ Exit Status code set to 0 indicates "normal completion"
mov r7, #1 @ Service command code (1) will terminate this program
svc 0 @ Issue Linux command to terminate program
.end @ Issue Linux command to terminate program