#1
  1. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95

    dissassembled code questions


    This is part of a function that does this:
    for(int i = 0; i < num; i++)
    local_buf[i] = arg_buf[i];

    //here we load the address of the local buffer into EAX
    1) 0x804837d <func+33>: lea 0xffffff28(%ebp),%eax
    //then we move this address into EDX
    2) 0x8048383 <func+39>: mov %eax,%edx
    //then we add the value of a local counter @ address 0xffffff24(%ebp) to EDX to get the offset inside the local char buffer
    3) 0x8048385 <func+41>: add 0xffffff24(%ebp),%edx
    //then we move the value of the local counter into EAX, OVERWRITING THE STORED ADDRESS OF THE LOCAL BUFFER
    4) 0x804838b <func+47>: mov 0xffffff24(%ebp),%eax

    Questions:
    -in step 1 what is the point of loading the address into EAX just so we can move it into EDX? why not just do this instead:
    "lea 0xffffff28(%ebp), %edx"? am i missing something? b/c it seems as tho its pointless, especially since we also overwrite
    that value in EAX anyways in step 4, yes?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    -in step 1 what is the point of loading the address into EAX just so we can move it into EDX? why not just do this instead:
    "lea 0xffffff28(%ebp), %edx"?

    Depends on the instruction set and CPU architecture. Maybe there's no instruction to load into edx directly.
  4. #3
  5. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    i tried this,
    asm("lea 0xffffff28(%ebp), %edx");
    and it compiled and executed correctly, any other ideas? or is it possible that the compiler is just retarded?:D
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    56
    Rep Power
    12
    Just a question, but is (%ebp) the same as [ebp] in intel?
  8. #5
  9. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    yes its dereferencing the register
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    What happens when you add different optimization options. I presume you compiled this without the -O option. Try compiling it with different optimization levels -O1, -O2, -O3 and see what happens :)

IMN logo majestic logo threadwatch logo seochat tools logo