Results 1 to 3 of 3

Thread: AT&T inline: local variables

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    53

    AT&T inline: local variables

    Hello, been looking at tutorial on the web about using local variables with AT&T inline assembly in gcc. And i cant figure it out how to use the output/input/clobber operators..

    The code below works fine when declaring the variables as globals. But i would prefer them as local. So if anyone can fix the below code to work with local variable would hopefully help me draw a logical conclusion to get me understand how to use local variable.

    Cheers!
    Code:
    unsigned int cpu_info, cpu_sse3, cpu_info_amd;
    asm
    (
    "movl $0x1, %eax\n"
    "cpuid\n"
    "movl %edx, _cpu_info\n" //test
    "movl %ecx, _cpu_sse3\n"
    "movl $0x80000001, %eax\n"
    "cpuid\n"
    "movl %edx, _cpu_info_amd\n"
    );
    You are reading my signature! :-)

    My WIP site

    Three Great bands:
    Beseech
    Meshuggah
    Opeth

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    53

    Re: AT&T inline: local variables

    Never mind, manage to solve it. The little thing that stop me before was that all eax, edc, ecx required double %% character, even when i didn´t write to the local variables.

    Code:
        asm
        (
            "movl $0x1, %%eax\n\t"
            "cpuid\n\t"
            "movl %%edx, %0\n\t"
            "movl %%ecx, %1\n\t"
            "movl $0x80000001, %%eax\n\t"
            "cpuid\n\t"
            "movl %%edx, %2\n\t"
            : "=g" (cpu_info), "=g" (cpu_sse3), "=g" (cpu_info_amd)
        );
    You are reading my signature! :-)

    My WIP site

    Three Great bands:
    Beseech
    Meshuggah
    Opeth

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: AT&T inline: local variables

    As far as I understand, you only need to use %% when you have used at least one of the three ":" lines. Its got something to do with how gcc resolves the register names.

    I'm having much trouble with inline AT&T in gcc also.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width