public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Machine Instruction encoding
@ 2004-03-22  8:20 sashti srinivasan
  2004-03-22  8:20 ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: sashti srinivasan @ 2004-03-22  8:20 UTC (permalink / raw)
  To: gcc-help

Hello All,
 
   The following is a line in rtems' timer driver
 source.
     asm volatile(".byte 0x0F, 0x31" : "=A" (result));
   
   RTEMS mailing list clarified me saying that it is
encoding of pentium rdtsc instruction.  Please tell me
how the above statement differs from the one below.

         asm("rdtsc result");
 (Assuming the instruction mnemonic is correct)
 
   Only thing I found from gnu documentation for gcc
 that '=' specifies that result is a output of the
 instruction.  According to the document, there must
 be an instruction pnemonic string first inside the
 paranthesis.  But there is the directive .byte
 there.  Does this mean the opcode directly?
 
   The document also says that the arguments can be
 referred like %0, %1 etc.  But there is nothing like
 this here.  Is it because, since there is only one
 operand, it is assumed to follow the opcode?

   Any other reference than info pages of gcc provides
more details?
    
   Please clear my doubts.
 
 With Best Regards
 Srinivasan


________________________________________________________________________
Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more. 
Go to: http://in.insurance.yahoo.com/licspecial/index.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Machine Instruction encoding
  2004-03-22  8:20 Machine Instruction encoding sashti srinivasan
@ 2004-03-22  8:20 ` Ian Lance Taylor
  2004-03-24 11:25   ` sashti srinivasan
  0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2004-03-22  8:20 UTC (permalink / raw)
  To: sashti srinivasan; +Cc: gcc-help

sashti srinivasan <svasn_tcpip@yahoo.co.in> writes:

>    The following is a line in rtems' timer driver
>  source.
>      asm volatile(".byte 0x0F, 0x31" : "=A" (result));
>    
>    RTEMS mailing list clarified me saying that it is
> encoding of pentium rdtsc instruction.  Please tell me
> how the above statement differs from the one below.
> 
>          asm("rdtsc result");
>  (Assuming the instruction mnemonic is correct)

First I'll note that the assembly instruction rdtsc does not take an
argument.  The only legal asm would be asm ("rdtsc").  I assume that
the RTEMS example uses ".byte" because it was written before all
assemblers supported rdtsc.  Or something like that.

The difference between the plan asm and the one which appears above is
that the one which appears above explicitly states that the
instruction stores a result into %eax/%edx, and gcc will store that
value into the variable "result".

>    Only thing I found from gnu documentation for gcc
>  that '=' specifies that result is a output of the
>  instruction.  According to the document, there must
>  be an instruction pnemonic string first inside the
>  paranthesis.  But there is the directive .byte
>  there.  Does this mean the opcode directly?

In this case .byte is the instruction mnemonic.  The '=' does indeed
specify the result of the instruction.

>    The document also says that the arguments can be
>  referred like %0, %1 etc.  But there is nothing like
>  this here.  Is it because, since there is only one
>  operand, it is assumed to follow the opcode?

No.  The instruction takes no operand.  The instruction always stores
its value into %eax/%edx.  See the Intel documentation, which is
available on the web.

Ian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Machine Instruction encoding
  2004-03-22  8:20 ` Ian Lance Taylor
@ 2004-03-24 11:25   ` sashti srinivasan
  2004-03-24 13:44     ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: sashti srinivasan @ 2004-03-24 11:25 UTC (permalink / raw)
  To: Ian Lance Taylor, gcc-help

 --- Ian Lance Taylor <ian@wasabisystems.com> wrote: >
sashti srinivasan <svasn_tcpip@yahoo.co.in> writes:
> 
> >    The following is a line in rtems' timer driver
> >  source.
> >      asm volatile(".byte 0x0F, 0x31" : "=A"
> (result));
> >    
> >    RTEMS mailing list clarified me saying that it
> is
> > encoding of pentium rdtsc instruction.  Please
> tell me
> > how the above statement differs from the one
> below.
> > 
> >          asm("rdtsc result");
> >  (Assuming the instruction mnemonic is correct)
> 
> First I'll note that the assembly instruction rdtsc
> does not take an
> argument.  The only legal asm would be asm
> ("rdtsc").  I assume that
> the RTEMS example uses ".byte" because it was
> written before all
> assemblers supported rdtsc.  Or something like that.
> 
> The difference between the plan asm and the one
> which appears above is
> that the one which appears above explicitly states
> that the
> instruction stores a result into %eax/%edx, and gcc
> will store that
> value into the variable "result".
> 
> >    Only thing I found from gnu documentation for
> gcc
> >  that '=' specifies that result is a output of the
> >  instruction.  According to the document, there
> must
> >  be an instruction pnemonic string first inside
> the
> >  paranthesis.  But there is the directive .byte
> >  there.  Does this mean the opcode directly?
> 
> In this case .byte is the instruction mnemonic.  The
> '=' does indeed
> specify the result of the instruction.
> 
> >    The document also says that the arguments can
> be
> >  referred like %0, %1 etc.  But there is nothing
> like
> >  this here.  Is it because, since there is only
> one
> >  operand, it is assumed to follow the opcode?
> 
> No.  The instruction takes no operand.  The
> instruction always stores
> its value into %eax/%edx.  See the Intel
> documentation, which is
> available on the web.
> 
> Ian 
Hello,
   Lots of thanks for the clarifications.  Sorry for
further simple doubts.  The rdtsc instruction stores
the value(of time) in registers eax and edx, and you
have said that compiler puts data from these registers
into the variable 'result'.  But we are not specifying
the registers(eax,edx) in this statement.  How the
compiler knows that variable 'result' should be
updated based on these registers?(eax,edx do not
figure in this statement).

    If these are documented anywhere, please give me
pointers.

With Regards
Srinivasan


________________________________________________________________________
Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more. 
Go to: http://in.insurance.yahoo.com/licspecial/index.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Machine Instruction encoding
  2004-03-24 11:25   ` sashti srinivasan
@ 2004-03-24 13:44     ` Ian Lance Taylor
  2004-03-28  3:16       ` movl $1f sashti srinivasan
  0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2004-03-24 13:44 UTC (permalink / raw)
  To: sashti srinivasan; +Cc: gcc-help

sashti srinivasan <svasn_tcpip@yahoo.co.in> writes:

> > >    The following is a line in rtems' timer driver
> > >  source.
> > >      asm volatile(".byte 0x0F, 0x31" : "=A"
> > (result));

...

>    Lots of thanks for the clarifications.  Sorry for
> further simple doubts.  The rdtsc instruction stores
> the value(of time) in registers eax and edx, and you
> have said that compiler puts data from these registers
> into the variable 'result'.  But we are not specifying
> the registers(eax,edx) in this statement.  How the
> compiler knows that variable 'result' should be
> updated based on these registers?(eax,edx do not
> figure in this statement).
> 
>     If these are documented anywhere, please give me
> pointers.

The compiler knows that the results winds up in %eax/%edx due to use
of the constraint 'A' on the value to be stored into result.  This is
documented, sort of, here:

http://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html#Machine%20Constraints

Look for "Intel 386".

Ian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* movl $1f
  2004-03-24 13:44     ` Ian Lance Taylor
@ 2004-03-28  3:16       ` sashti srinivasan
  2004-03-29  5:22         ` Falk Hueffner
  0 siblings, 1 reply; 6+ messages in thread
From: sashti srinivasan @ 2004-03-28  3:16 UTC (permalink / raw)
  To: gcc-help

Hello,
     I am sorry if my doubt is not appropriate here. 
A line from linux source is:

   movl $1f, %1 /*Save EIP*/

  May anyone explain me how this instruction saves
EIP?  (%1 is the structure member holding eip).  My
doubt is, what is this $1f and how it copies eip to
%1.

With Regards.
Srinivasan

________________________________________________________________________
Yahoo! India Insurance Special: Be informed on the best policies, services, tools and more. 
Go to: http://in.insurance.yahoo.com/licspecial/index.html

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: movl $1f
  2004-03-28  3:16       ` movl $1f sashti srinivasan
@ 2004-03-29  5:22         ` Falk Hueffner
  0 siblings, 0 replies; 6+ messages in thread
From: Falk Hueffner @ 2004-03-29  5:22 UTC (permalink / raw)
  To: sashti srinivasan; +Cc: gcc-help

sashti srinivasan <svasn_tcpip@yahoo.co.in> writes:

> A line from linux source is:
>
>    movl $1f, %1 /*Save EIP*/
>
>   May anyone explain me how this instruction saves
> EIP?  (%1 is the structure member holding eip).  My
> doubt is, what is this $1f and how it copies eip to
> %1.

It's the next label called '1' in forward direction. See your
assembler manual.

-- 
	Falk

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-03-27 13:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-22  8:20 Machine Instruction encoding sashti srinivasan
2004-03-22  8:20 ` Ian Lance Taylor
2004-03-24 11:25   ` sashti srinivasan
2004-03-24 13:44     ` Ian Lance Taylor
2004-03-28  3:16       ` movl $1f sashti srinivasan
2004-03-29  5:22         ` Falk Hueffner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).