D Inline Assembler: access to a static variable

I am having problems accessing a static variable with Inline Assembler in the programming language D. The documentation says that I need to access local variables using

mov EAX, var[EBP]; //or mov EAX, var;

and class variables with

mov EBX, this;
mov EAX, var[EBX];

But it does not document how to access a static variable. Here is my code that causes the error:

module test;

static int A = 1234;

static void SetA()
{
    asm
    {
        mov A, 5432; //compiles, but throws an error
        //tried it with "mov dword ptr [A], 5432; too
    }
}

I really need a “global storage” method for integers available from both assembler and D, I would be very happy for any help with this (or an alternative way).

+5
source share
2 answers

- D2. __gshared "" .

:

module test;

__gshared int A = 1234;

void SetA()
{
    asm
    {
        mov A, 5432;
    }
}

unittest
{
    SetA();
    assert(A == 5432);
}
+4

. static on A , . .

D . __gshared, , . TLS .

, :

module test;

/*static*/ int A = 1234;

/*static*/ void SetA()
{
    int a;

    asm
    {
        mov a, 5432;
    }

    A = a;
}

: __gshared, . CyberShadow.:)

+2

All Articles