Extremely Active Member
     
Group: Moderators
Posts: 725
Member No.: 11
Joined: 16-May 04

|
For my next dumb question.....
I'm trying to set up an array of variables defined by a structure. For this example I'll use the simple POINT structure.
| CODE | .DATA?
TPos POINT 10 dup (<>) buffr db 512 dup (?)
.CODE
mov TPos[0].x,1 mov TPos[0].y,2 mov TPos[1].x,3 mov TPos[1].y,4 mov TPos[2].x,5 mov TPos[2].y,6 invoke wsprintf,addr buffr,SADD("%lx %lx"),TPos[0].x,TPos[0].y invoke MessageBox, 0, addr buffr, 0,0 invoke wsprintf,addr buffr,SADD("%lx %lx"),TPos[1].x,TPos[1].y invoke MessageBox, 0, addr buffr, 0,0 invoke wsprintf,addr buffr,SADD("%lx %lx"),TPos[2].x,TPos[2].y invoke MessageBox, 0, addr buffr, 0,0 |
These are the values printed out:
| QUOTE | | 50301 60000 503 600 5 6 |
Clearly not what I had intended...
A portion of the Listing follows:
| QUOTE | 000001BB C7 05 00000220 R mov TPos[0].x,1 00000001 000001C5 C7 05 00000224 R mov TPos[0].y,2 00000002 000001CF C7 05 00000221 R mov TPos[1].x,3 00000003 000001D9 C7 05 00000225 R mov TPos[1].y,4 00000004 000001E3 C7 05 00000222 R mov TPos[2].x,5 00000005 000001ED C7 05 00000226 R mov TPos[2].y,6 00000006 |
Looking at the listing, the addresses make no sense to me... The values are being overlapped at 1 byte intervals. The results are so ridiculously wrong, that I must have no idea what I am doing. I tried "dword ptr" all over the place, and many other things. Everything gives the same answers.
Clearly I've not defined TPos correctly, doesn't MASM know how big POINT is?
OK, now one more question...
This was just preparation for what I really wanted to do... I want to allocate memory using GlobalAlloc, and then, overlay the definition of an array of structured items.
How does one reference an element of this kind of array?
Say I want to reference the 15th array element, the item called x. My best guess is to put the starting address in EBX and reference [EBX][15].x. Is this correct?
I have been unable to find any code in any book or tutorial or in any of the hundreds of example asm programs I have...
|