NO

Author Topic: inline asm & struct  (Read 3762 times)

quiveror

  • Guest
inline asm & struct
« on: September 14, 2004, 08:21:51 AM »
Hello,
Suppose I have
Code: [Select]

typedef struct { int i,j,k,l; } A;
A *pa = &(A){10,20,30,40};
...
__asm mov eax,[pa]

after that I want to dereference member k in location pointed to by eax. So I write (I really dont know whether this is the correct way or not) :
Code: [Select]

__asm mov ecx,[eax+A.k-A]

now I think that the expr A.k-A should better be implement with a macro so I write :
Code: [Select]

#define mem(s,m) s.m-s
__asm mov ecx,[eax+mem(A,k)]

After using the macro, I got an error. I try to preprocess the code (pocc -e) and found that the above got expanded into
Code: [Select]

__asm mov ecx,[eax+ A . k - A]
// note the space between A, dot and k

I guess that in asm statement, there'd be no space allowed in a literal (identifier.member in this case) but I think it make the use of the above macro possible. What do you think about this? Any workaround?

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: inline asm & struct
« Reply #1 on: September 14, 2004, 01:41:46 PM »
Hello,

Your approach looks fine to me. I have noticed a few times before that the preprocessor inserts extra spaces. The assemblers way of handling structure references looks really stupid. It should of course also handle "struct . member", with spaces. I will fix this to the next beta release of 2.90 - maybe you can do without the macro for a few days?

Pelle
/Pelle