www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Inline Assembler

reply Michael <Michael_member pathlink.com> writes:
Hello, I was just wondering if there is a way to use structures in inline
assembler... what I mean is:

struct st {
int x, y;

st my_struct;

asm {
mov EAX, my_struct.x;

I know I could use

asm {
mov EAX, [my_struct+4];

But I don't trust I could avoid padding issues and everything.

Any opinions, or solutions, are very welcome.
Aug 11 2004
parent reply Michael <Michael_member pathlink.com> writes:
Sorry meant to use .y in my example (hence [my_struct+4])

I'm doing this now, and it is working fine, but I remember reading that D will
shuffle the contents of struct for efficiency...


Alright just found out about StructName.member.offset, that should much safer, I
Aug 11 2004
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
nope, D only shuffles class members for efficiency.  structs are left as
they are, as they are often used to "memberize" memory-mapped hardware, file
data etc.

but using the struct.x should be fine, and you shouldn't have to use the
offset.  it's all struct members compile to anyway - an offset.
Aug 11 2004