Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6912331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:04:42+00:00 2026-05-27T09:04:42+00:00

I’ve run into a problem while compiling a package around, I am not really

  • 0

I’ve run into a problem while compiling a package around, I am not
really a good coder, but I tried fixing it for my self, and it still won’t compile.
This is the original bit of code.:

#ifdef __GNUC__
asm("and $3, %%ecx;"
"shl $3 ,%%ecx;"
"ror %%cl, %0"
: "=r" (value)
: "r" (value), "c" (address));
#else

The error is .:

GBAinline.h:139: error: impossible register constraint in ‘asm’
( ifdef line is 138 )

And this is how I tried to make it look.:

#ifdef __GNUC__
asm ("and $3 %%ecx,shl $3 %%ecx,ror %%cl, %0" : "=r" (value): "r" (value), "c" (address));

#else

Still, it would not work. It’s a gba emulator before anyone ask, VBA, and this is
part of GBAinline.h . This assembler is making me crazy already.

Edit.: The problem above was handled fine, I just was not paying attention to which
compiler I was using.
But now I get this error on this bit of code from a header file, I’ve put it on pastebin,
to keep things here a bit more tidy… ( Sorry if this is wrong, i can change that later )

This is the header that has the lines that results in errors.:
http://pastebin.com/k3D4cg0d

And this is the C file it refers to.:
http://pastebin.com/Ymg1X5dg

This is giving an error like this.:

/var/tmp/cc3zA0lH.s: Assembler messages: /var/tmp/cc3zA0lH.s:69: Error: bad instruction `sw $3,0(r3)',

And so on for the rest of those lines.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:04:43+00:00Added an answer on May 27, 2026 at 9:04 am

    That inline assembly is buggy:

    1. It uses multi-line strings which effectively concatenate. Without \n all appears on one line. Whether your assembler accepts statements separated by semicolons makes all the difference there … some may not.
    2. It specifies the same variable as input/output constraint instead of using "+r"(value) as ordinarily suggested for this situation.

    Without seeing the rest of the code it’s not quite clear why the inline assembly statement looks the way it does; Personally, I’d suggest to write it like:

    asm("ror %%cl, %0" : "+r"(value) : "c"((((uintptr_t)address) & 3) << 3)));
    

    because there’s little need to do the calculation itself in assembly. The uintptr_t (from <stdint.h>) cast makes this 32/64bit agnostic as well.

    Edit:

    If you want it for a different CPU but x86 / x64, then it obviously needs to be different … For ARM (not Thumb2), it’d be:

    asm("ROR %0, %0, %1" : "+r"(value) : "r"((((uintptr_t)address) & 3) << 3)));
    

    since that’s how the rotate instruction there behaves.

    Edit (add reference):

    Regarding the operation performed here as such, this blog post gives an interesting perspective – namely, that the compiler is quite likely to create the same output for:

    (a >> shift | a << (8 * sizeof(a) - shift))
    

    as for the x86 inline

    asm("ror %%cl, %0" : "+r"(a) : "c"(shift))
    

    Testing this:

    #include <stdint.h>
    
    int main(int argc, char **argv)
    {
        unsigned int shift = (int)((((uintptr_t)argv) & 3) << 3);
        unsigned int a = argc;
    #ifdef USE_ASM
        /*
         * Mark the assembly version with a "nop" instruction in output
         */
        asm("nop\n\t"
            "ror        %%cl, %0" : "+r"(a) : "c"(shift));
        return a;
    #else
        return (a >> shift | a << (8 * sizeof(a) - shift));
    #endif
    }
    

    Compile / disassemble it:

    $ gcc -DUSE_ASM -O8 -c tf.c; objdump -d tf.o
    
    tf.o:     file format elf64-x86-64
    
    Disassembly of section .text:
    
    0000000000000000 :
       0:   83 e6 03                and    $0x3,%esi
       3:   8d 0c f5 00 00 00 00    lea    0x0(,%rsi,8),%ecx
       a:   90                      nop
       b:   d3 cf                   ror    %cl,%edi
       d:   89 f8                   mov    %edi,%eax
       f:   c3                      retq
    $ gcc -O8 -c tf.c; objdump -d tf.o
    
    tf.o:     file format elf64-x86-64
    
    Disassembly of section .text:
    
    0000000000000000 :
       0:   83 e6 03                and    $0x3,%esi
       3:   8d 0c f5 00 00 00 00    lea    0x0(,%rsi,8),%ecx
       a:   d3 cf                   ror    %cl,%edi
       c:   89 f8                   mov    %edi,%eax
       e:   c3                      retq

    Ergo, this inline assembly is unnecessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.