Я попробовал несколько вариантов: проверял значения в цикле, делал это вне цикла, проверял, достаточно ли места в массиве, корректировал пространство в массиве. , скорректированное пространство между значениями массива и все, что я лично мог себе представить.
Предполагается, что код вычисляет 64-битную контрольную сумму путем суммирования значений ASCII
символов в массиве. А затем помещаем их на терминал.
Код: Выделить всё
.data
array: .space 256
askC: .asciz "Enter a char value: "
fmt_check: .asciz "Checksum: %ld\n"
.text
.global main
main:
mov x4, #10 // Set x4 as counter for max 10 characters
ldr x5, =array
mov x6, #0 // Initialize x6 as checksum accumulator (64-bit)
input_loop:
ldr x0, =askCbl printf
// Read a character from the user
bl getchar // getchar reads into w0
cmp w0, #0 // Check for EOF (or invalid input)
beq end // If EOF, go to end
strb w0, [x5] // Store the character in the array (byte-wise)
uxtw x0, w0 // Zero-extend w0 to x0 for checksum addition
add x6, x6, x0 // Add ASCII value of character to checksum
add x5, x5, #1 // Move to the next byte in the array
// Decrement counter and call check function
sub x4, x4, #1
bl check // Call check to decide whether to continue input
check:
cmp x4, #0 // Compare counter with 0beq compute_checksumb input_loop
compute_checksum:
ldr x0, =fmt_check
mov x1, x6
end:
mov x0, #0
ret
Подробнее здесь: https://stackoverflow.com/questions/791 ... ion-faults