I have tried to write an ARM-LEGv8 assembler program that calculates the average of two values in an array at a certain position. It runs on a Raspberry Pi with Armbian.
The pseudo code should look like this:
int average(int v[], int i){
int average = (v[i] + v[i-1])/2;
return average;
}
The array is at X0 and the i on X1.
My assembly code looks like this:
.globl _start
.data
myArray: .word 0, 1, 2, 3, 35, 5
.text
average:
LSL X9, X1, #2
ADD X9, X9, X0
LDR X10, [X9, #0] // guess Segmentation Fault
LDUR X11, [X9, #-4]
ADD X3, X10, X11
LSR X3, X3, #1
BR X30
_start:
LDR X0, myArray
MOV X1, #5
BL mittelwert
MOV X8, #0x5d
MOV X0, X3
SVC 0
I used these commands to build it:
as average.s -o average.o
gcc average.o -o average -nostdlib -static
When I run my program I get a Segmentation Fault. Why?