The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: RuiLoureiro on May 26, 2011, 08:25:46 PM

Title: Structure problem
Post by: RuiLoureiro on May 26, 2011, 08:25:46 PM
I have the following struct

MODE struct
   pAAA    dd ?
   pBBB    dd ?
   kData   db 256 dup (?)
   pCCC    dd ?
MODE ends

and the buffer is defined as:

LENX       equ sizeof MODE
Buffer     db LENX*1000 dup (?)

If ESI points to the Buffer somewhere
how do i get the entry point to kData (in ESI or in EDI,...)

Its all, thank you
Title: Re: Structure problem
Post by: jj2007 on May 26, 2011, 08:35:47 PM
mov eax, 123 ; member #123
imul eax, eax, LENX
add eax, offset Buffer
mov [eax.MODE.kData], 123
Title: Re: Structure problem
Post by: qWord on May 26, 2011, 08:37:34 PM
lea edi,Buffer[N*SIZEOF MODE]    ; edi points to some element (MODE) in array
mov [edi].MODE.kData[0],1        ; set first byte of kData
lea esi,[edi].MODE.kData[0]      ; esi = pointer to first byte
Title: Re: Structure problem
Post by: jj2007 on May 26, 2011, 08:44:12 PM
... provided that N is an immediate - an unlikely case for an array with 1,000 members :wink
Title: Re: Structure problem
Post by: mineiro on May 27, 2011, 03:34:42 AM

mov eax,"seno"
lea esi, Buffer
assume esi:ptr MODE
lea edi, [esi].kData   ;entry point, index 0
stosd
lea edi, [esi].kData + 1 * sizeof MODE  ;index 1
stosd
assume esi:nothing



mov eax,"seno"
lea edi, Buffer.MODE.kData + 0 * sizeof MODE
stosd
Title: Re: Structure problem
Post by: RuiLoureiro on May 27, 2011, 01:45:58 PM
@@qWord: exactly what i want   :wink

@@jj:  :thumbu

@@mineiro: i assume i dont like to use ASSUME !  :green2

thanks all