0
HPSTART:    CMP EBX, 1       // if n = 1
            JNE HPERMUT
            MOV EDX, N
INSERT:     MOV ECX, Perm[4320 + EDX * 4]
            MOV Perm[EDI * 4], ECX
            INC EDI
            DEC EDX
            TEST EDX, EDX
            JNZ INSERT
            RET

HPERMUT:    XOR ESI, ESI         //   ELSE ,     i = 0
HLOOP:      CMP ESI, EBX         // i < N     for (i = 0; i < n; i++)
            JE ITEREND
            PUSH ESI
            DEC EBX          
            CALL HPSTART
           

This is a piece of a code I'm working on.

EBX (max value 6) starts at 6.

While stepping over the CALL HPSTART line I would've expected to see the next statement pointer go back to hpstart and keep doing the whole thing until the last recursive call where EBX is 1 and then start backtracking to the the first function call (I didn't include the rest of the function).

Instead it instantly did all the recursive calls (EBX was correctly set to 1 and the values were correctly printed into the array) and went directly to the next line (MOV EAX, EAX).

What happened there? Does a compiled code calculate the recursive calls before executing?

This is done with _asm in visual studio

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
JustJohn
  • 59
  • 1
  • 7

0 Answers0