Is the code associated to the .L2 label of assembly code called procedurally in this segment?

StackOverflow https://stackoverflow.com/questions/9197221

  •  18-05-2021
  •  | 
  •  

Question

I am trying to analyse the following code in assembly.

sub $48, %esp
mov $56, 44(%esp)
mov $3, 40(%esp)
mov $0, 36(%esp)
mov 44(%esp), %eax
mov %eax, 32(%esp)
jmp .L2
.L3:
mov 32(%esp), %eax
sub 40(%esp), %eax
mov %eax, 32(%esp)
add $1, 36(%esp)
.L2:
mov 32(%esp), %eax
cmp 40(%esp), %eax
ja .L3
mov 36(%esp),%eax
mov 32(%esp),%edx

If my understanding is clear, the first 6 lines are called normally, and then the program jumps to .L2: and executes the code. If R[eax] == R[40 + R[esp], then the code will go to .L3.

My question is about what happens after this. Is .L3 executed and then the code goes to .L2 because it is right after it, or does it automatically jumps to the last two lines after executing .L3?

Additionally, I could use some tips about reading assembly code; I am trying to find the final values of eax and edx.

Thank you

Was it helpful?

Solution

You are correct: after jumping to .L3, all 6 instructions between there and ja .L3 will be executed in order, and that process will repeat itself until the conditional jump isn't taken.

Sounds like you're doing fine reading the code :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top