www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Setting class variable from inline assembly

reply pmoore <pmoore_member pathlink.com> writes:
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'
}
}
}
May 20 2006
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----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: What you are looking for is: Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEcM7G3w+/yD4P9tIRAjUDAJ9vyYOkcV4X1qbcE/nikRiTZtAXJgCgnTIq +5laF38kL5siYeMLXgFrXQk= =SsL3 -----END PGP SIGNATURE-----
May 21 2006
parent reply Thomas Kuehne <thomas-dloop kuehne.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thomas Kuehne schrieb am 2006-05-21:
 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?
 What you are looking for is:








The last line should have been: mov [EBX+myvar2], EAX; Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEcM/F3w+/yD4P9tIRArUYAJ92IWIxHqfnsRYg86NQvRABJhXfrACePP8P ElcidKuVewNvYMjXQqQoOjo= =nNmk -----END PGP SIGNATURE-----
May 21 2006
parent pmoore <pmoore_member pathlink.com> writes:
Thomas,

You are right. Now that I think about it again it would be impossible for the
compiler to know at runtime what the address of a class local variable would be
so it makes sense to be an offset.

Thanks for taking the time to point this out.


In article <1qv6k3-m9f.ln1 birke.kuehne.cn>, Thomas Kuehne says...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thomas Kuehne schrieb am 2006-05-21:
 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?
 What you are looking for is:








The last line should have been: mov [EBX+myvar2], EAX; Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFEcM/F3w+/yD4P9tIRArUYAJ92IWIxHqfnsRYg86NQvRABJhXfrACePP8P ElcidKuVewNvYMjXQqQoOjo= =nNmk -----END PGP SIGNATURE-----
May 22 2006