When adding a WriteDec and CRLF calls under a recursive procedure, it goes into an infinite loop.
- My motivation is to print out each time the value of eax and crlf right after the right shift.
- When reaching 0, it appears that there are infinite recursive calls because it keeps on printing 0's.
- I was under the impression that it shouldn't be the case since ZF = 1 first time eax = 0 and therefore it jumps to skip label which ends the recursion.
The following code causes an infinite loop when EAX register = 0
.code
MAIN PROC
mov ecx, 10
L1:
push 10
call f1
call exitProcess
main ENDP
f1 PROC
push ebp
mov ebp, esp
sub esp, 4
mov eax, [ebp+8]
shr eax, 1
call WriteDec
call CRLF
mov [ebp-4], eax
jz skip
call f1
skip:
mov eax, [ebp+8]
call WriteDec
call CRLF
; ** comment out ** mov ebp, [ebp]
mov esp, ebp
pop ebp
ret 4
f1 ENDP
END MAIN
Expected result:
5
2
1
0
1
2
5
10