When you jump and link in func, you execute the func2 function, and the return address ($ ra) is set to the line immediately after the jump and link (PC + 4). Inside the func2 routine, you immediately return to the position stored at the return address (sll in func). After the change, you again try to go to the return address, which is sll in func, which leads to an infinite loop.
In other words, when you make consecutive subroutine calls, you need to save and restore the return address before and after the subroutine call, respectively.
foo:
You also need to make sure your โendโ is marked as a label (add a colon after it).
source share