digitalmars.D.learn - Access class fields from asm
- Carl Volhard (15/15) Jun 22 2007 How can i access non-static class fields?
- BCS (10/11) Jun 22 2007 try somthing like this (I haven't even tried to compile this)
- Carl Volhard (6/24) Jun 28 2007 Curiously this way works
- Deewiant (4/13) Jun 28 2007 Ah, that'll be this then: http://d.puremagic.com/issues/show_bug.cgi?id=...
- Manfred Hansen (17/38) Jun 22 2007 I think it should work too.
- Carl Volhard (6/6) Jun 26 2007 Hello and thanks so far.
- Deewiant (5/10) Jun 26 2007 This looks like a bug to me, as 8 is the offsetof of the field. You shou...
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'
Jun 22 2007
Reply to Carl,How can i access non-static class fields?try somthing like this (I haven't even tried to compile this) public class FooBar { public int b = 8; } FooBar foo = new FooBar(); // foo is a pointer asm{ mov EBX, foo; // load by value mov EAX, [EBX+FooBar.b.offsetof]; //offset from pointer }
Jun 22 2007
Curiously this way works
foo.b.offsetof
although the documentation says
FooBar.b.offsetof
is the correct way. But this code generates the following compile errors:
Error: 'this' is only allowed in non-static member functions, not main
Error: this for b needs to be type FooBar not type int
BCS Wrote:
Reply to Carl,
How can i access non-static class fields?
try somthing like this (I haven't even tried to compile this)
public class FooBar {
public int b = 8;
}
FooBar foo = new FooBar(); // foo is a pointer
asm{
mov EBX, foo; // load by value
mov EAX, [EBX+FooBar.b.offsetof]; //offset from pointer
}
Jun 28 2007
Carl Volhard wrote:
Curiously this way works
foo.b.offsetof
although the documentation says
FooBar.b.offsetof
is the correct way. But this code generates the following compile errors:
Error: 'this' is only allowed in non-static member functions, not main
Error: this for b needs to be type FooBar not type int
Ah, that'll be this then: http://d.puremagic.com/issues/show_bug.cgi?id=515
--
Remove ".doesnotlike.spam" from the mail address.
Jun 28 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;
}
Jun 22 2007
Hello and thanks so far. The first version with the offset does not work. I got the same compile errors. The second version works. But I don't understand why I have to add 8 Bytes to the address? What information fills the first 2 words? Is there an option to access the fields without counting the offset? (like in the first Version, only for non-static fields?) greetings Carl Volhard
Jun 26 2007
Carl Volhard wrote:Hello and thanks so far. The first version with the offset does not work. I got the same compile errors. The second version works. But I don't understand why I have to add 8 Bytes to the address? What information fills the first 2 words?This looks like a bug to me, as 8 is the offsetof of the field. You should file it in the 'Zilla. You should be able to find information on class structure at abi.html in the documentation.
Jun 26 2007









Deewiant <deewiant.doesnotlike.spam gmail.com> 