The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: xroot on August 16, 2007, 04:29:37 PM

Title: Access Structure Arrays
Post by: xroot on August 16, 2007, 04:29:37 PM
Hi,
I am getting this error message A2070: invalid instruction operands

foo Struct
     vName byte 10 dup (?)
     Value byte 50 dup (?)
foo Ends

Main Proc
local info[5]:Foo
            mov eax,K                                         Index of field
            mov ecx,SIZEOF Foo
            mul ecx
            mov info[eax].vName,offset Tmp    <==On this line I get error A2070: invalid instruction operands

What am missing or doing wrong.
Thanks
Title: Re: Access Structure Arrays
Post by: Jimg on August 16, 2007, 08:03:33 PM
you need to give it a size, eg:
mov dword ptr info[eax].vName,offset Tmp 

however, from the definition in foo, I'm not sure what you wanted to store here, certainly not 10 bytes.
If you wanted to get the actual string from the buffer Tmp into the 10 byte buffer vName, then you have to do a copy of some kind.
Title: Re: Access Structure Arrays
Post by: evlncrn8 on August 16, 2007, 11:14:45 PM
well, if you have to do this then your struct design is wrong

mov info[eax].vName,offset Tmp

should really be...

foo Struct
     vName LPVOID ?
     Value byte 50 dup (?)
foo Ends

and you'd access it like...

mov info.foo.Value, offset Tmp

which should compile quite fine
that way if you change the struct, like adding more to it, or restructuring it it wont break...

really you should design the struct for the purpose you intend to use it for...