# Confusion on pop for recursive assembly code

I'm confused on what happens during POP. When POP LR happens does that change the PC to the location of LR, which would be sumi. If it does take it back to sumi wouldn't that just take the recursion even further?

c++:

int sumi(int n) {
if(n == 0)
return 0;
else
return n+sumi(n-1);
}


assembly:

sumi:
CMP R2,#0 ; n is R2
BNE else

then:
MOV R0,#0 ; result in R0
BX LR

else:
PUSH LR
PUSH R2
SUB R2,R2,#1
BL sumi
POP R2
POP LR
BX LR

• I'm voting to close this question as off-topic because this is a pure software question. – DoxyLover Feb 13 '17 at 6:51
• These very low-level programming questions tend to be accepted on EE. – Wouter van Ooijen Feb 13 '17 at 7:40