Setting class variable from inline assembly
Thomas Kuehne
thomas-dloop at kuehne.cn
Sun May 21 12:36:12 PDT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
pmoore schrieb am 2006-05-20:
> Hi,
>
> It seems that within inline assembly I can read a class variable but I can't set
> it. Is this a bug or is there a good reason for this?
>
> uint myvar;
>
> void main()
> {
> }
>
> class AClass
> {
> uint myvar2;
>
> this()
> {
> asm
> {
> mov EAX,myvar;
> mov myvar,EAX; // this is fine
>
> mov EAX,myvar2; // no problem reading
> mov myvar2,EAX; // doesn't compile - bad type/size of operands 'mov'
> }
> }
> }
mov EAX,myvar2; seems to move the offset of myvar2 - not the value:
# import std.stdio;
#
# class C{
# int i;
#
# void foo(){
# int x;
#
# asm{
# mov EAX, i;
# mov x, EAX;
# }
#
# writefln("%s at 0x%X -> 0x%X, %s", i, &i, x, x);
# writefln("offset of i: %s", i.offsetof);
# }
# }
#
# int main(){
# C c = new C();
# c.foo();
#
# return 0;
# }
What you are looking for is:
# void* p = this;
#
# asm{
# mov EBX, p;
# mov EAX, [EBX+myvar2];
# // something productive here
# mov [EBX+myvar2], EBX;
# }
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFEcM7G3w+/yD4P9tIRAjUDAJ9vyYOkcV4X1qbcE/nikRiTZtAXJgCgnTIq
+5laF38kL5siYeMLXgFrXQk=
=SsL3
-----END PGP SIGNATURE-----
More information about the Digitalmars-d-bugs
mailing list