The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ragdog on February 28, 2010, 09:50:39 AM

Title: Fill Struct
Post by: ragdog on February 28, 2010, 09:50:39 AM
Hi

Can i fill this struct over a Procedur

Example:

MyStruct STRUCT   ; sizeof = 1
   szEnable   BOOLEAN   ?
MyStruct ENDS


MYProc  proc _handle:DWORD,bEnabled:DWORD

mov [pxxx.szEnable],bEnabled
...
..
.
ret
MYProc endp

Greets,
Title: Re: Fill Struct
Post by: Ghandi on February 28, 2010, 09:59:34 AM

MyStruct STRUCT   ; sizeof = 1
   szEnable   BOOLEAN   ?
MyStruct ENDS


.data
pxxx MyStruct <>

.code
MYProc  proc _handle:DWORD,bEnabled:DWORD
mov eax,bEnabled
mov pxxx.szEnable,al
...
...
...
ret
MYProc endp



This is assuming that you are using pxxx as a global variable. You can't move a value directly from memory to memory, unless you use esi/esi and the string operands (movsb/movsw/movsd) and for a boolean value i dont see any benefits from doing that so it simply places the bEnabled value in eax/al before storing it in the variable member.

If you used a DWORD instead of a BOOLEAN, you could also use push/pop to achieve the same thing.

HR,
Ghandi
Title: Re: Fill Struct
Post by: ragdog on February 28, 2010, 10:18:29 AM
Thanks for you reply

I have try 1 and 2 solution i have an error messages

error A2070: invalid instruction operands
One or more operands were not valid for the instruction they were specified with.

The first have i allready try it

Edit:

Yes with al Works fine :U