Access class fields from asm
Manfred Hansen
m.hansen at kielnet.net
Fri Jun 22 11:38:28 PDT 2007
Carl Volhard wrote:
> How can i access non-static class fields?
> The Code in the D-Specification doesn't work for me.
> I've tried:
>
> public class FooBar {
> public int b = 8;
> }
>
> FooBar foo = new FooBar();
> FooBar *bar = &foo;
> asm{
> mov EBX, [bar];
> mov EAX, FooBar.b[EBX]; //<- Line 65
> }
>
> and got following compile errors:
>
>
> ...Examples.d(65): Error: 'this' is only allowed in non-static member
> ...Examples.d(65): Error: this for b needs to be type FooBar not type int
> ...Examples.d(65): bad type/size of operands 'this.b'
I think it should work too.
Here is my solution:
import tango.io.Stdout;
public class FooBar {
public int b = 8;
}
void main() {
int c;
FooBar foo = new FooBar();
asm {
mov EBX,[foo];
mov ECX,dword ptr[EBX+8];
mov c,ECX;
}
Stdout("c: ")(c).newline;
}
More information about the Digitalmars-d-learn
mailing list