I am trying to compile the following function:
#include <stdio.h>extern long long int f(int a, int b);int main() { long long int x = f(3, 2); printf("Value of x = %lld\n", x); return 0;}
function f:
// Keep local variable b in X19;// // Assume n and k are passed in X0 and X1 respectively and that the result is returned in X0..section .text.global ff: SUB SP, SP, #24 //Clearing space in the SP STUR X30, [SP, #16] //Storing the LR in the SP STUR X19, [SP, #8] //Storing b in the SP ADD X19, X1, #2 //b = k + 2 CMP X0, #0 //Comparing if (n == 0) B.NE else //Goes to else if false MOV X19, #8 //k = 8 ADD SP, SP, #8 //Adding 8 as we don't use the SP to store X9 in this case B end //Goes to endelse: MOV X9, X0 //Storing n in X9 STUR X9, [SP, #0] //Storing X9 in the SP SUB X0, X0, #1 //n = n - 1 ADD X1, X1, #1 //k = k + 1 BL f //Calling recursive function LDUR X9, [SP, #0] //Loading X9 from the SP ADD SP, SP, #8 //Removing space for X9 from the SP LSL X9, X9, #2 //n = n * 4 ADD X19, X19, X9 //b = b + 4*n ADD X19, X19, X0 //b = b + 4*n + f()end: ADD X0, X19, X1 //Stores b + n into X0 LDUR X19, [SP, #0] //Loading X19 from the SP LDUR X30, [SP, #8] //Loading X30 from the SP ADD SP, SP, #16 //Removing space for X19 and X30 from the SP BR LR //Branches to the LR
But whenever I use my makefile, I get errors for every single line of the assembly instruction for f().
TARGET = question_4CC = gccLD = gccFLAGS = -g -O0all: $(TARGET)clean: rm *.o rm $(TARGET)main.o: main.c $(CC) $(FLAGS) -c $^ -o $@question_4.o: question_4.S $(CC) $(FLAGS) -c $^ -o $@$(TARGET): main.o question_4.o $(LD) main.o question_4.o -o $@
I get the following error messages.Error message from terminal
I've used similar makefiles for other files on a raspberry pie. But this compile attempt was done on my local machine, a windows through wsl. Could this be the issue?