error: error: can't find a register in class BREG' while reloading`asm' - Linux

This is a discussion on error: error: can't find a register in class BREG' while reloading`asm' - Linux ; Hi, The sample C program: #include #define WORD_EAX 0 #define WORD_EBX 1 #define WORD_ECX 2 #define WORD_EDX 3 #define WORD_NUM 4 #define INITIAL_APIC_ID_BITS 0xFF000000 int get_APICID(){ unsigned int words[WORD_NUM]; unsigned int reg = 1; __asm__ ("pushl %%ebx \n\t" /* save ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: error: error: can't find a register in class BREG' while reloading`asm'

  1. error: error: can't find a register in class BREG' while reloading`asm'

    Hi,

    The sample C program:

    #include
    #define WORD_EAX 0
    #define WORD_EBX 1
    #define WORD_ECX 2
    #define WORD_EDX 3
    #define WORD_NUM 4

    #define INITIAL_APIC_ID_BITS 0xFF000000

    int get_APICID(){

    unsigned int words[WORD_NUM];
    unsigned int reg = 1;
    __asm__ ("pushl %%ebx \n\t" /* save %ebx */
    "cpuid \n\t"
    "movl %%ebx, %1 \n\t" /* save what cpuid
    just put in %ebx */
    "popl %%ebx \n\t" /* restore the
    old %ebx */
    : "=a" (words[WORD_EAX]), /* output */
    "=b" (words[WORD_EBX]),
    "=c" (words[WORD_ECX]),
    "=d" (words[WORD_EDX])
    : "a" (reg)); /*
    input */

    return ((words[WORD_EBX] & INITIAL_APIC_ID_BITS) >>
    24);
    }

    found at : http://sam.zoy.org/blog/2007-04-13-s...ode-have-inlin...
    but still i am getting an error: error: can't find a register in class
    `BREG' while reloading `asm'
    Could you suggest where did i go wrong ? even though the site says its
    correct program? Even though i am getting the same error.

    Thanks in advance for your help.

  2. Re: error: error: can't find a register in class BREG' whilereloading `asm'

    On Jan 30, 6:18 am, Neel wrote:
    > Hi,
    >
    > The sample C program:
    >
    > #include
    > #define WORD_EAX 0
    > #define WORD_EBX 1
    > #define WORD_ECX 2
    > #define WORD_EDX 3
    > #define WORD_NUM 4
    >
    > #define INITIAL_APIC_ID_BITS 0xFF000000
    >
    > int get_APICID(){
    >
    > unsigned int words[WORD_NUM];
    > unsigned int reg = 1;
    > __asm__ ("pushl %%ebx \n\t" /* save %ebx */
    > "cpuid \n\t"
    > "movl %%ebx, %1 \n\t" /* save what cpuid
    > just put in %ebx */
    > "popl %%ebx \n\t" /* restore the
    > old %ebx */
    > : "=a" (words[WORD_EAX]), /* output */
    > "=b" (words[WORD_EBX]),
    > "=c" (words[WORD_ECX]),
    > "=d" (words[WORD_EDX])
    > : "a" (reg)); /*
    > input */
    >
    > return ((words[WORD_EBX] & INITIAL_APIC_ID_BITS) >>
    > 24);
    >
    > }
    >
    > found at :http://sam.zoy.org/blog/2007-04-13-s...ode-have-inlin...
    > but still i am getting an error: error: can't find a register in class
    > `BREG' while reloading `asm'
    > Could you suggest where did i go wrong ? even though the site says its
    > correct program? Even though i am getting the same error.
    >
    > Thanks in advance for your help.


    What platform are you compiling on? This is x86/i386 code and won't
    work on amd64 platforms or anything but 32-bit x86.

    DS

  3. Re: error: error: can't find a register in class BREG' while reloading `asm'

    Neel wrote:
    >
    >The sample C program:
    >
    >#include
    >#define WORD_EAX 0
    >#define WORD_EBX 1
    >#define WORD_ECX 2
    >#define WORD_EDX 3
    >#define WORD_NUM 4
    >
    >#define INITIAL_APIC_ID_BITS 0xFF000000
    >
    >int get_APICID(){
    >
    > unsigned int words[WORD_NUM];
    > unsigned int reg = 1;
    > __asm__ ("pushl %%ebx \n\t" /* save %ebx */
    > "cpuid \n\t"
    > "movl %%ebx, %1 \n\t" /* save what cpuid
    >just put in %ebx */
    > "popl %%ebx \n\t" /* restore the
    >old %ebx */
    > : "=a" (words[WORD_EAX]), /* output */
    > "=b" (words[WORD_EBX]),
    > "=c" (words[WORD_ECX]),
    > "=d" (words[WORD_EDX])
    > : "a" (reg)); /*
    >input */
    >
    > return ((words[WORD_EBX] & INITIAL_APIC_ID_BITS) >>
    >24);
    >}
    >
    >found at : http://sam.zoy.org/blog/2007-04-13-s...ode-have-inlin...
    >but still i am getting an error: error: can't find a register in class
    >`BREG' while reloading `asm'
    >Could you suggest where did i go wrong ?


    Yes. You didn't copy the program correctly. Look more carefully at the
    second example in the web site, especially at the part where you have "=b".

    Remember that the whole problem with the "simple" example is that the ebx
    register cannot be used in PIC code. Therefore, any use of =b in an output
    list won't work.
    --
    Tim Roberts, timr@probo.com
    Providenza & Boekelheide, Inc.

  4. Re: error: error: can't find a register in class BREG' whilereloading `asm'

    On Jan 31, 12:44 pm, Tim Roberts wrote:
    > Neel wrote:
    >
    > >The sample C program:

    >
    > >#include
    > >#define WORD_EAX 0
    > >#define WORD_EBX 1
    > >#define WORD_ECX 2
    > >#define WORD_EDX 3
    > >#define WORD_NUM 4

    >
    > >#define INITIAL_APIC_ID_BITS 0xFF000000

    >
    > >int get_APICID(){

    >
    > > unsigned int words[WORD_NUM];
    > > unsigned int reg = 1;
    > > __asm__ ("pushl %%ebx \n\t" /* save %ebx */
    > > "cpuid \n\t"
    > > "movl %%ebx, %1 \n\t" /* save what cpuid
    > >just put in %ebx */
    > > "popl %%ebx \n\t" /* restore the
    > >old %ebx */
    > > : "=a" (words[WORD_EAX]), /* output */
    > > "=b" (words[WORD_EBX]),
    > > "=c" (words[WORD_ECX]),
    > > "=d" (words[WORD_EDX])
    > > : "a" (reg)); /*
    > >input */

    >
    > > return ((words[WORD_EBX] & INITIAL_APIC_ID_BITS) >>
    > >24);
    > >}

    >
    > >found at :http://sam.zoy.org/blog/2007-04-13-s...ode-have-inlin...
    > >but still i am getting an error: error: can't find a register in class
    > >`BREG' while reloading `asm'
    > >Could you suggest where did i go wrong ?

    >
    > Yes. You didn't copy the program correctly. Look more carefully at the
    > second example in the web site, especially at the part where you have "=b".
    >
    > Remember that the whole problem with the "simple" example is that the ebx
    > register cannot be used in PIC code. Therefore, any use of =b in an output
    > list won't work.
    > --
    > Tim Roberts, t...@probo.com
    > Providenza & Boekelheide, Inc.


    Yes, thanks for pointing out. I did the change instead of using =b i
    used
    something like:

    int get_APICID(){

    unsigned int words[WORD_NUM];
    unsigned int reg = 1;
    __asm__ ("pushl %%ebx \n\t" /* save %ebx */
    "cpuid \n\t"
    "movl %%ebx, %esi \n\t" /* save what
    cpuid
    just put in %ebx */
    "popl %%ebx \n\t" /* restore the
    old %ebx */
    : "=a" (words[WORD_EAX]), /* output */
    "=S" (words[WORD_EBX]),
    "=c" (words[WORD_ECX]),
    "=d" (words[WORD_EDX])
    : "a" (reg)); /*
    input */

    return ((words[WORD_EBX] & INITIAL_APIC_ID_BITS) >>
    24))

    And it works fine ;-))

    Njoy,
    Neel

+ Reply to Thread