so this is my combined .S file of functions, to be integrated with my .c file. go through this code and look for any potential errors that might lead to seg faults. if you need to see my .c file to make sure, let me know.

.syntax unified
.align 4
.type add %function
.section .text
.global add

add:
ADD r0, r0, r1
BX lr


@subtract function
.syntax unified
.align 4
.type subtract %function
.global subtract

subtract:
CMP r0, r1  @if r0<r1, swap the values
B subtract_swap

subtract_main:
SUB r0, r0, r1
BX lr

subtract_swap:  @swapping using EOR of two registers(like assignment 1)
EOR r0, r0, r1
EOR r1, r1, r0 @r1=100
EOR r0, r0, r1 @r0=101
B subtract


@multiply function
.syntax unified
.align 4
.type multiply %function
.global multiply

multiply:
MUL r0, r0, r1
BX lr


@exponentiation function
.syntax unified
.align 4
.type exponentiation %function
.global exponentiation

exponentiation: @r0 is base, r1 is power
CMP r1, #0x0		 @ Check if r1=0
BEQ exp_error_check

exp_start:
PUSH {r4, lr}	  @ To clear r2 once loop is finished
MOV r4, #0x1          @ Initialize result to 1
CMP r1, #0x0          @ Compare exponent to 0
BEQ exp_done          @ If exponent is 0, return 1

exp_loop:
MUL r4, r4, r0        @ Multiply result by base
SUB r1, r1, #1       @ Decrement exponent by 1
CMP r1, #0x0
BNE exp_loop          @ If exponent is not 0, continue loop

exp_done:
MOV r0, r4            @ Move result to r0 for return
POP {r4, lr}	  @ Clear all registers
BX lr                 @ Return

exp_error_check:
CMP r0, #0x0	@ Check if r0=0
BNE exp_start
MOV r0, #0xFFFFFFFF		@if 0^0 condition, error. returns -1
BX lr


@floor division function
.syntax unified
.align 4
.type floordivision %function
.global floordivision

floordivision:

CMP r1, #0x0            @ Compare divisor to 0
BNE floordivstart    
MOV r0, #0xFFFFFFFF	 @ If divisor is 0, return -1
BX lr

floor_div_start:
PUSH {r4, lr}	  @ To clear registers after returning
MOV r4, #0x0    @ To store result

floor_div_loop:
CMP r0, r1            @ Compare dividend to divisor
BLT floor_div_done    @ If dividend < divisor, break loop
SUB r0, r0, r1        @ Subtract divisor from dividend
ADD r4, r4, #0x1        @ Increment quotient by 1
B floor_div_loop      @ Repeat loop

floor_div_done:
MOV r0, r4            @ Move quotient to r0 for return
POP {r4, lr}
BX lr                 @ Return


@bitcounting function
.syntax unified
.align 4
.type bitcounting %function
.global bitcounting

bitcounting:
PUSH {r4, r5, r6, r7, lr}   @Save registers and link register
MOV r4, r0  @storing address of number in r4
LDR r5, [r4]    @moving number into r5
MOV r7, #0x0    @counter

bitcount_loop:
CMP r5, #0x0
BEQ bitcount_end
AND r6, r5, #0x1    @extracting first bit in string, storing in r6
ADD r7, r7, r6  @if it is a 1, add it to the counter (its gonna be either 0 or 1)
LSR r5, r5, #0x1
B bitcount_loop

bitcount_end:

MOV r0, r7
POP {r4, r5, r6, r7, lr}
BX lr


@summation function 
.syntax unified
.align 4
.type summation %function
.global summation

summation:
CMP r0, r1	
BGT sum_swap    @if r0>r1, swap
BEQ sum_equal	@if r0==r1, return r0
PUSH {r4, lr}	@pushing register to clear them once result is returned
B sum_loop

sum_equal:
BX lr

sum_swap:   @swapping using EOR of two registers(like assignment 1)
EOR r0, r0, r1
EOR r1, r1, r0 
EOR r0, r0, r1 
B summation

sum_loop:

ADD r4, r4, r0	@r4=r4+r0
ADD r0, #0x1	@r0++
CMP r0, r1	@if r0!=r1, loop
BLT sum_loop

ADD r4, r4, r1 @to add last number to result
MOV r0, r4
POP {r4, lr}
BX lr


@factorial function
.syntax unified
.align 4
.type factorial %function
.global factorial

factorial:
CMP r0, #0x0
BEQ baseCase0

factorialHelper:
PUSH {r4, lr}
MOV r4, r0
CMP r0, #0x1
BEQ baseCase1
SUB r0, r0, #0x1
BL factorialHelper

baseCase1:
MUL r0, r0, r4
POP {r4, lr}
BX LR

baseCase0:
MOV r0, #0x1
BX LR


@modulus function
.syntax unified
.align 4
.type modulus %function
.section .text
.global modulus

modulus:
CMP r1, #0x0	@check if dividing by zero. return -1 if yes
BEQ modulus_error
B modulus_loop

modulus_error:
MOV r0, #0xFFFFFFFF
POP {lr}
BX lr

modulus_loop:
CMP r0, r1	@if r0<r1
BLT modulus_end
SUB r0, r0, r1	@r0=r0-r1
B modulus_loop

modulus_end:
POP {lr}
BX lr