Understanding of how for loops in C relate to IA32 machine code -


foo: pushl %ebp movl %esp,%ebp  movl 12(%ebp),%ecx  xorl %eax,%eax  movl 8(%ebp),%edx  cmpl %ecx,%edx jle .l3  .l5: addl %edx,%eax  decl %edx cmpl %ecx,%edx  jg .l5  .l3: leave ret 

i know xorl indicator of cycle (int i=0), can't understand rest of code... can give me hint?

thanks!

function foo has 2 parameters, let's call them x , y.

foo:                   # foo(x, y)     pushl %ebp     movl %esp,%ebp      movl 12(%ebp),%ecx # ecx = y     xorl %eax,%eax     # eax = 0     movl 8(%ebp),%edx  # edx = x     cmpl %ecx,%edx     # while (ecx < edx) {     jle .l3  .l5:     addl %edx,%eax     #     eax += edx     decl %edx          #     edx--     cmpl %ecx,%edx     # }     jg .l5  .l3:     leave     ret                # return eax 

hope helps.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -