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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:19:45+00:00 2026-06-18T01:19:45+00:00

Given this code: #include <stdio.h> int main(int argc, char **argv) { int x =

  • 0

Given this code:

#include <stdio.h>

int main(int argc, char **argv)
{
    int x = 1;
    printf("Hello x = %d\n", x);
}

I’d like to access and manipulate the variable x in inline assembly. Ideally, I want to change its value using inline assembly. GNU assembler, and using the AT&T syntax.

  • 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-18T01:19:46+00:00Added an answer on June 18, 2026 at 1:19 am

    In GNU C inline asm, with x86 AT&T syntax:
    (But https://gcc.gnu.org/wiki/DontUseInlineAsm if you can avoid it).

    // this example doesn't really need volatile: the result is the same every time
    asm volatile("movl $0, %[some]"
        : [some] "=r" (x)
    );
    

    after this, x contains 0.

    Note that you should generally avoid mov as the first or last instruction of an asm statement. Don’t copy from %[some] to a hard-coded register like %%eax, just use %[some] as a register, letting the compiler do register allocation.

    See https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html and https://stackoverflow.com/tags/inline-assembly/info for more docs and guides.


    Not all compilers support GNU syntax.
    For example, for MSVC you do this:

    __asm mov x, 0 and x will have the value of 0 after this statement.

    Please specify the compiler you would want to use.

    Also note, doing this will restrict your program to compile with only a specific compiler-assembler combination, and will be targeted only towards a particular architecture.

    In most cases, you’ll get as good or better results from using pure C and intrinsics, not inline asm.

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

Sidebar

Related Questions

In the following code: #include<stdio.h> int main(int argc,char *argv[]){ int index; for(index = 0;
Given this C code compiled with gcc 4.3.3 #include <stdio.h> #include <stdlib.h> int main(int
Given this code : #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main(void) { int
#include cv.h #include highgui.h #include <stdio.h> int main(int argc, char* argv[]){ cvNamedWindow(Window1, CV_WINDOW_AUTOSIZE); IplImage*
How exactly does fork() work? The following code #include <stdio.h> int main (int argc,
Given this code : #include <stdio.h> #include <assert.h> void print_number(int* somePtr) { assert (somePtr!=NULL);
I have the following piece of code: #include <stdio.h> int main ( int argc,
Could anyone please explain why this code compiles : #include <stdio.h> #include <string.h> int
This is my code: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h> int num_mezzo_1(int
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:

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.