From: brennan AT mack DOT rt66 DOT com (Brennan "The Rev. Bas" Underwood) Newsgroups: comp.os.msdos.djgpp Subject: Re: ASM - Accessing structures Date: 11 Nov 1996 15:11:01 -0700 Organization: Rasterfari Lines: 50 Message-ID: <56889l$ib8@mack.rt66.com> References: <199611101834 DOT MAA26637 AT ghgcorp DOT ghgcorp DOT com> NNTP-Posting-Host: mack.rt66.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp In article <199611101834 DOT MAA26637 AT ghgcorp DOT ghgcorp DOT com>, Bachtel wrote: >Could Brennan, if he's watching this, please tell me also how to >access structures in extended asm? Unless I'm a complete idiot (by no >means a remote possibility:), it is not explained in the info pages. >I'm trying to translate sliver.asm for Mr. Ogles, and this is >stopping me. Heeeeeeeeeeeeeeeeeeeeeeeere I come to save the DAY!!! Hopefully. Since a struct is just a pile of memory, you need to know the location of the beginning of the struct and the offset of the element you want. The difficulty of this goes up (slightly) since gcc likes to pad structures, so you can't just count bytes (unless you __attribute__((packed)) everything, which is going to slow down your accesses, which asm won't compensate for, so don't do that.) In C you can get the address of a struct element via &structname.element. You can get the offset in bytes via ((int)&structname.element - (int)&structname) You should probably have the program calculate these offsets at startup, in case the structs ever change. Then, armed with the offset: movl $_mystruct, %%eax movl $_element1offset, %%ebx movb (%%eax,%%ebx), %%cl /* or something to that effect */ That's not the most efficient way to do the access, but hopefully this gets the idea across. If the structs never change, you could calculate the offsets once and build them into the access: (pretend 16 is the offset) movl $_mystruct, %%eax movb 16(%%eax), %%cl That's how gcc (usually) does it, since it has intimate knowledge of the struct internals. And, if it's a static struct (not likely) movb _mystruct+16, %%cl --Brennan -- brennan AT rt66 DOT com | "Developing for Windows is not fun." -- John Carmack Riomhchlaraitheoir| Rasterfarian |