digitalmars.D.bugs - Setting class variable from inline assembly
- pmoore (21/21) May 20 2006 Hi,
- Thomas Kuehne (43/64) May 21 2006 -----BEGIN PGP SIGNED MESSAGE-----
- Thomas Kuehne (11/25) May 21 2006 -----BEGIN PGP SIGNED MESSAGE-----
- pmoore (6/32) May 22 2006 Thomas,
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
-----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
-----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
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