What is this code doing exactly?

mystery:
pushl %ebp
movl %esp, %ebp
subl $20, %esp
movl $0, -4(%ebp)
jmp .L2
.L3:
movl -4(%ebp), %eax
sall $2, %eax
addl 8(%ebp), %eax
movl (%eax), %eax
cmpl 16(%ebp), %eax
jne .L4
movl $1, -20(%ebp)
jmp .L6
.L4:
addl $1, -4(%ebp)
.L2:
movl -4(%ebp), %eax
cmpl 12(%ebp), %eax
jl .L3
movl $0, -20(%ebp)
.L6:
movl -20(%ebp), %eax
leave
ret

Sounds like a class problem.

On a piece of paper create rows

Passed Arguments
[16]
[12]
[8]
[4]
[0]
[-4]
[-8]
[-12]
[-16]
[-20]
Temporaries

Mark which one of these is your return address, and your passed in arguments, your temporary local arguments and then single-step your code!

Anything else before you do that would be doing your homework for you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.