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 8012829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:27:11+00:00 2026-06-04T19:27:11+00:00

I am trying to let the inline assembler copy some values into specific registers

  • 0

I am trying to let the inline assembler copy some values into specific registers but it only complains. This is a short version of the code that will trigger the error:

asm("" :: "r0" (value));
asm("" :: "a1" (value));

Both lines will trigger:

Error: matching constraint references invalid operand number

So how do I specify the register to take directly?
I know i could introduce names for the values and then copy them by my own but I would like to avoid this as this code would be shorter and more readable.

Why I am asking
Currently I am working on some syscalls. I want to use a syscall macro like this:

#define SYSCALL0(NUMBER) asm("swi #" STRINGIFY(NUMBER));
#define SYSCALL1(NUMBER, A) asm("swi #" STRINGIFY(NUMBER) :: "r0"(A));
#define SYSCALL2(NUMBER, A, B) asm("swi #" STRINGIFY(NUMBER) :: "r0"(A), "r1"(B));
...

As you can see this fits neatly on on line.
Of course I could do something like:

#define SYSCALL1(NUMBER, A) register type R0 asm("r0") = A;
                            SYSCALL0(NUMBER)

but then I would have to convert A to type to get no type errors or give type correctly everytime I use the macro in different functions.

  • 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-06-04T19:27:12+00:00Added an answer on June 4, 2026 at 7:27 pm

    With GCC, there is a shortcut:

    register long r0 asm ("r0");
    

    Then r0 “aliases” that register.

    Combine that with a statement expression, and you can even get r0 as a “return value”.

    #define SYSCALL1(NUMBER,A) ({\
      register long r0 asm("r0") = (long) (A); \
      asm("swi #" STRINGIFY(NUMBER) : "=r"(r0) : "r"(r0) : "memory"); \
      r0; })
    

    (I have no idea if the clobber is legitimate or not, the uClibc syscall implementation has that though.)

    See extended assembly and local reg vars.

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

Sidebar

Related Questions

I'm trying to let users type in date and time values into an input
I've got this odd problem with jQuery. I'm trying to let the change of
I'm trying to run this code: let coins = [50, 25, 10, 5, 2,1]
I'm trying to let the user input commands at a console using raw_input(), this
Hi could some one please take a look at this and let me know
I am trying to let GoogleBot login to my website and bypass the authentication.
I'm trying to let a user "make his own service". most direct method I
I am using the jQuery Datepicker( http://keith-wood.name/datepick.html ). I am trying to let the
Trying to avoid the SomethingManager trap here... Let's say I'm going to write a
Let's say i have a Domain Model that im trying to make compatible with

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.