Is there any problem with how I have this set up? When I go to access an 'element' of the array, I get some strange values..





.data
FVX struct
x REAL4 0.0
y REAL4 0.0
z REAL4 0.0
FVX ends
SIZEOFFVX EQU sizeof FVX

FFC struct
glF1 dd 0
glF2 dd 0
glF3 dd 0
glF4 dd 0
FFC ends
SIZEOFFFC EQU sizeof FFC

.data?
QWT REAL8 ?
FO DWORD ? ;pointer for file object
SizeRead DWORD ?
vObj DWORD ? ;pointer for FVX vertex structure
fObj DWORD ?




NOTE: when I move fObj to a different physical location - like two above vObj definition, I get different messed-up value when accessing an element of the struct array




heapallocate proc

invoke GetProcessHeap
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,360000*sizeof DWORD
mov [FO],eax ;the actual file object (3d object data to load into for drawing)

invoke GetProcessHeap
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,4096*sizeof FVX ;up to 4096 of vertices
mov [vObj], eax ;move address into vObj variable

invoke GetProcessHeap
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY,4096*sizeof FFC
mov [fObj], eax ;face pointer object (glF1,glF2,glF3{...,glF4})

ret
heapallocate endp

Posted on 2004-01-30 11:48:50 by drarem



FFC struct
glF1 dd 0
glF2 dd 0
glF3 dd 0
glF4 dd 0
FFC ends
SIZEOFFFC EQU sizeof FFC

.data?

; pointer to an array of objects
fObj DWORD ?


.code

invoke GetProcessHeap
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY,4096*sizeof FFC
mov [fObj], eax ;face pointer object (glF1,glF2,glF3{...,glF4})

In that case, the following is wrong:
	mov eax,EL

fstp [fObj.FFC.glF1+eax]
The x86 processors cannot use data pointers directly from memory. You need to load the pointer in fObj into a register, and you also need to scale the index to get the proper address:


mov ecx,fObj ; copy the object address into a register
mov eax,EL ; get index
imul eax,SIZEOFFFC ; [b]scale[/b] the index by object size, can optimize with SHL
fstp [ecx + eax].FFC.glF1 ; store data
Posted on 2004-01-30 13:53:09 by tenkey
Posted on 2004-01-30 16:51:47 by arkane
Its time for you to look at OOP.
Posted on 2004-01-31 01:56:55 by Homer
drarem,

What tenkey means to say is that unlike the M68000 CPUs, the INTEL CPUs cannot do a memory to memory transfer. So you have to put the contents into a register first, and then put the register contents into a memory location. By the way, did I not show you in previous posts that it is unnecessary to use SIZEOF FFC? Just use FFC as a size variable. And sizeof DWORD can be shortened to just DWORD. Ratch






.DATA
FFC struct
glF1 dd 0
glF2 dd 0
glF3 dd 0
glF4 dd 0
FFC ends
.DATA?
fObj DWORD ? ;pointer to an array of FFC structures
SOMEWHERE DWORD ?

.CODE
MAIN:
MOV EAX,[fObj] ;fObj = pointer to HeapAlloc memory, EAX is your memory location
MOV ECX,[EAX.FFC.glF3+9*FFC] ;ECX = DWORD glF3 of the 10th FFC structure within allocated memory
MOV [SOMEWHERE],ECX

INVOKE ExitProcess,0
Posted on 2004-01-31 18:15:23 by Ratch
thank you all!!! I should have known, it was a memory to memory transfer. Thanks for the link arkane,
and the info, Ratch =)

The object I draw is more recognizable, not much to report on and probably a problem so simple I am overlooking it, will post updates when available.

OOP in assembly? there's more to it than what I am doing?
Posted on 2004-02-01 06:25:08 by drarem