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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:22:42+00:00 2026-05-19T00:22:42+00:00

Question: How can I access a member variable in assembly from within a non-POD

  • 0

Question: How can I access a member variable in assembly from within a non-POD class?


Elaboration:

I have written some inline assembly code for a class member function but what eludes me is how to access class member variables. I’ve tried the offsetof macro but this is a non-POD class.

The current solution I’m using is to assign a pointer from global scope to the member variable but it’s a messy solution and I was hoping there was something better that I dont know about.

note: I’m using the G++ compiler. A solution with Intel syntax Asm would be nice but I’ll take anything.

example of what I want to do (intel syntax):

class SomeClass
{
  int* var_j;
  void set4(void)
  {
    asm("mov var_j, 4"); // sets pointer SomeClass::var_j to address "4"
  }
};

current hackish solution:

int* global_j;
class SomeClass
{
  int* var_j;
  void set4(void)
  {
    asm("mov global_j, 4"); // sets pointer global_j to address "4"
    var_j = global_j;       // copy it back to member variable :(
  }
};

Those are crude examples but I think they get the point across.

  • 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-19T00:22:43+00:00Added an answer on May 19, 2026 at 12:22 am

    This is all you need:

    __asm__ __volatile__ ("movl $4,%[v]" : [v] "+m" (var_j)) ;
    

    Edited to add: The assembler does accept Intel syntax, but the compiler doesn’t know it, so this trick won’t work using Intel syntax (not with g++ 4.4.0, anyway).

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

Sidebar

Related Questions

this question can create a misunderstanding: I know I have to use CSS to
Following up from this question: How can I unlock a file that is locked
I have a question regarding inheritance in Java. If I have this base class
Question Can I build a image database/library that has an e-commerce style checkout system
Simple question: Can a swing frame be completely modal ( block all others windows
Simple question: Can I mix in my desktop application Java and JavaFX Script code?
Here is the question: Can TortoiseSvn work on Windows 2008 without turning off User
We are using SQL Server 2005, but this question can be for any RDBMS
This is a question you can read everywhere on the web with various answers:
[The only similar question I can find was answered long ago and contains a

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.