Как вывести длину строки в ARM Assembly в Raspberry Pi? - PullRequest
0 голосов
/ 31 марта 2020

Я создаю программу для использования внешнего файла с именем String_Length() для вывода длины строки ввода пользователя (например, «Кот в шляпе»).

После ввода строки я продолжайте получать ошибку сегментации. Я хотел бы знать, что именно я делаю неправильно в этой программе. 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
...