tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Crutches_for_TCC_inline_Asm


From: Daniel Glöckner
Subject: Re: [Tinycc-devel] Crutches_for_TCC_inline_Asm
Date: Fri, 14 Jul 2017 16:51:15 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

On Fri, Jul 14, 2017 at 10:07:55AM +0300, ANDY TAKKER wrote:
> As I see, there are no good teaches among tinycc-devel.

Yeah, I know, I studied maths and cs, not pedagogy.

> So, let's go on. Next program compiling well, but
> linking bad.

>    asm ( "mov %eax, a" );

Linking fails because it expects to find a symbol called "a" but
local variables can not be found in the symbol table.

> The next program compiling well, linking well,
> but brings bad results.


> unsigned int a = 0;
> 
>  int   main()
> {
> 
> unsigned int a;
> b:
>    asm ( "cpuid" );
>    asm ( "rdtsc" );
>    asm ( "mov %eax, a" );
>   printf("%d\n", a);
> goto b;
> }

You should have guessed by now that it will store the value
in the global variable.

> A big piece of work has been done. But
> who really need this heap of trash:

As I wrote in my last eMail, the TCC inline assembler tries to be
compatible to GCC. If you are unhappy with that, use another
compiler.

Did you read the GCC documentation for the inline assembler syntax?
Did you understand it?
Then you should know that the correct way to to it is:

int   main()
{
        unsigned int a;
        int junk1, junk2, junk3;
b:
        asm ( "cpuid\n"
              "rdtsc"
              : "=a"(a), "=b"(junk1), "=c"(junk2), "=d"(junk3));
        printf("%u\n", a);
        goto b;
}

> Of couse, Fabrice will never patch TCC. Because of because.
> It is life.

No. It's because Fabrice has left the project years ago.
And it does not need patching. It behaves as intended.

Best regards,

  Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]