Fwd: error in variable dereferencing

Andrew Haley aph@redhat.com
Fri Apr 21 16:29:00 GMT 2006


Thibaud GUERIN writes:
 > On 4/22/06, Andrew Haley <aph@gcc.gnu.org> wrote:
 > > Thibaud GUERIN writes:
 > >  > On 4/21/06, Andrew Haley <aph@gcc.gnu.org> wrote:
 > >  > > Thibaud GUERIN writes:
 > >  > >  > >
 > >  > >
 > >  > > OK, so we've got rid of the asms and casting away const, and the code
 > >  > > still doesn't work.
 > >  > >
 > >  > > So, your code is now, at last, legal C.  Let's have a look at the
 > >  > > assembly code generated for my_own_printf (use gcc -S).  Be sure to
 > >  > > include the exact command line you used.
 > >
 > >  > my_own_printf:
 > >
 > > Args are just below sp.
 > >
 > >  >      pushl   %ebp
 > >  >      movl    %esp, %ebp
 > >
 > > ebp points to:  frame, retaddr, arg0
 > >
 > >  >      subl    $8, %esp
 > >  >      leal    8(%ebp), %eax
 > >
 > > eax contains ebp+8: it points to arg0
 > >
 > >  >      movl    %eax, -4(%ebp)
 > >
 > > save eax on the stack
 > >
 > >  >      movl    -4(%ebp), %eax
 > >
 > > restore it
 > >
 > >  >      movl    (%eax), %eax
 > >
 > > load eax from arg0
 > >
 > >  >      cmpl    8(%ebp), %eax
 > >
 > > compare eax with the memory at ebp+8
 > >
 > >  >      jne     .L33
 > >
 > > So, the memory word at ebp+8 is compared with the memory at ebp+8.
 > >
 > > Do you have a debuuger that can single-step through this code, one
 > > insn at a time?
 > 
 > Sorry no debugger... this is a part of the 1st program running (well
 > ... trying to run)

Well, we've established that whetever is wrong, it's not the code gcc
generates for this routine.  It's correct, as you can see.

 > The only debug ways usable in the code right now are some things like :
 > i = (long)(fmt);
 > __asm__ volatile ("mov %0, %%eax\n":: "m"(i));
 > __asm__ volatile ("l1: jmp l1");
 > 
 > which are really dirty i agree...

Thay're also wrong, becasue they don't clobber eax.

Andrew.



More information about the Gcc-help mailing list