Recursive function using ARMv8

I am trying to create a program in ARMv8 which finds all permutations of a string. When I compile my code using GCC I get a Bus error (core dumped). I used GDB using next/step and debugger stops when trying to leave from the .permute function after the recursive call from the same function. The error is 0x0000000000000001 in ??. Can someone help?

.data                  // The Start of the .data Segment
string_str: .string "AB"

    .text                   // The Start of the .text Segment
    .global main
main:

     stp    x29,x30,[sp, -32]!      
     add    x29,sp,0            

     adr    x19,string_str
     mov    x20,x19

     mov    x21,xzr

loop_length:

     ldrb   w1,[x19,#0]
     cbz    w1,exit_length
     add    x19,x19,1
     add    x21,x21,1
     b  loop_length

exit_length:
     mov    x0,x20
     mov    x1,xzr
     sub    x2,x21,1

     bl .permute

exit:
     ldp    x29, x30, [sp], 32  // Release the stack space
     ret                // Return to loading function

.permute:

     stp    x29,x30,[sp,-32]!
     add    x29,sp,0

     str    x0,[x29,#0]
     str    x1,[x29,#8]
     str    x2,[x29,#16]
     mov    x22,x1

     subs   xzr,x2,x1
     b.ne   loop_permute


print_str:
     adrp   x0,string_str
     add    x0,x0,:lo12:string_str
     bl     printf
     b  exit_permute

loop_permute:
     subs   xzr,x2,x22
     b.eq   exit_permute


     adr    x0,string_str
     ldr    x1,[x29,#8]
     mov    x2,x22
     bl .swap

     adr    x0,string_str
     ldr    x1,[x29,#8]
     add    x1,x1,1
     ldr    x2,[x29,#16]
     bl .permute


     adr    x0,string_str
     ldr    x1,[x29,#8]
     sub    x1,x1,1
     mov    x2,x22
     bl .swap   
     add    x22,x22,1
     b  loop_permute

exit_permute:
     ldp    x29,x30,[sp],32
     ret

.swap:

     stp    x29,x30,[sp,-32]!
     add    x29,sp,0

     adr    x0,string_str

     ldrb   w24,[x0,x1]
     mov    w25,w24
     ldrb   w26,[x0,x2]
     strb   w26,[x0,x1]
     strb   w25,[x0,x2] 

     ldp    x29,x30,[sp],32
     ret