This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Machine Instruction encoding


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]