What does the assembler instruction STRUCT do exactly? And how does it work?

for example:


SYSTEMTIME STRUCT
wYear WORD ?
wMonth WORD ?
wDayOfWeek WORD ?
wDay WORD ?
wHour WORD ?
wMinute WORD ?
wSecond WORD ?
wMilliseconds WORD ?
SYSTEMTIME ENDS
Posted on 2002-01-20 13:00:25 by TCT
Hmm, me neither, haven't asked that question myself, maybe i'll *********** the program, and check what it actually does...:)

How does it work? (I'm not sure what you meant) you can do something like this:

mov ax, SystemTime.wSecond

ax now contains the wSecond value
Posted on 2002-01-20 14:21:05 by stryker
watch also this thread to understand my question.

My question belongs to the work of the compiler.
Because I want to know how I have to use variables defined with STRUCT (and some other instructions).

Unfortunately is the mode of operation of the compiler a less described chapter so that it is hard for new programmers to use it with less effort.
Posted on 2002-01-20 14:40:46 by TCT
>>My question belongs to the work of the compiler.

Do you want to know how the compiler works on structures, how it operates? if that's what you want, im sorry, i really don't know the answer. Better ask betov who created SpAsm.

>>Because I want to know how I have to use variables defined with STRUCT (and some other instructions).

You mean! if you want to create your own structs, you want to know how you should defined your variables whether should it be a DWORD, WORD...? If yes, it really depends on what you actually want with your data.

>>Unfortunately is the mode of operation of the compiler a less described chapter so that it is hard for new programmers to use it with less >>effort.

hmm, i don't think so! it really depends on the compiler's implementation.

:)
Posted on 2002-01-20 15:21:59 by stryker
Let me see if I have got your question right, a STRUCT in assembler does much the same as in most other languages, it defines the relationship of a sequence of other data types as they will be placed in memory if the definition is used.


POINT STRUCT
x DWORD ?
y DWORD ?
POINT ENDS

This format defines 8 bytes in sequence as 2 times 4 bytes. When you use a STRUCT in your code, the "prototype" of combined data elements is arranged in memory as 8 bytes made up of 2 times 4 bytes.

It gives the assembler the means of addressing the elements in the struct in this order so if you set the liner of code,


LOCAL Pt:POINT

Then use the following,

mov Pt.x, eax
mov Pt.y, ecx

The assembler copies the content of the EAX register into the first 4 bytes of the allocated memory for the struct and the contents of ECX into the second 4 bytes. The important thing is here is that you can refer to the allocated memory of each element by name instead of having to address it by start address plus offset.

Regards,

hutch@movsd.com
Posted on 2002-01-20 17:12:09 by hutch--
Thanks all

I think now I can use STRUCT without problems.:)
But do also watch the other thread.
Posted on 2002-01-21 03:40:25 by TCT
the advantage of a struc is That you can create large
defined arrays...

please look
here
Posted on 2002-01-21 05:28:14 by mob