Please help... newbie problems loading struct array with mixed data types

Started by iaNac, October 04, 2006, 02:21:27 AM

Previous topic - Next topic

PBrennick

Ratch,
That looks right to me, also.  I think that was what drizz was trying to do.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

drizz

Quote from: PBrennick on October 06, 2006, 12:08:15 PMI fail to see how that could be right.  He is creating an array of 11 pointers.  Your method would result in all calculations except 0 being outside the array.  Please explain.
He is creating an array of 11 structures, not 11 structure pointers.
"LOCAL   cri[11]:PTR CRI" would be 11 structure pointers.
When accessing elements of an array calculation for offset must be done
because square brackets in asm dont have the same meaning as square brackets in HLLs.

Step By Step Examples:
byte array
local barray[100]:byte
mov al,barray[1*(sizeof byte)]
mov al,barray[2*(sizeof byte)]

optionally instead of "*sizeof byte" you can use "*TYPE barray"

word array
local warray[100]:word
mov ax,warray[1*(sizeof word)]
mov ax,warray[2*(sizeof word)]

optionally instead of "*sizeof word" you can use "*TYPE warray"

dword array
local dwarray[100]:dword
mov eax,dwarray[1*(sizeof dword)]
mov eax,dwarray[2*(sizeof dword)]

optionally instead of "*sizeof dword" you can use "*TYPE dwarray"

struct array
local structarray[100]:SOMESTRUCT
mov eax,structarray[1*(sizeof SOMESTRUCT)].element
mov eax,structarray[2*(sizeof SOMESTRUCT)].element

optionally instead of "*sizeof SOMESTRUCT" you can use "*TYPE structarray"


The truth cannot be learned ... it can only be recognized.

drizz

for accessing structure elements in a loop:
; >>>>> Store Fluid Volumes...
xor ecx,ecx
xor esi,esi
mov eax,1000       ; 1 liter default for all drugs
.while ecx<NumOfDrugs ; still 4
; PrintDec ecx, "Fluid Vol Loop"
mov cri[esi].FluidVol, eax
add esi,sizeof CRI
.endw
The truth cannot be learned ... it can only be recognized.

Ratch

drizz,

     You don't need to use 'sizeof' or 'type' all the time.  If you want to code the size of a byte, you can code MOV AL,5*BYTE instead of MOV AL,5*(sizeof byte)] .  Similiarly, 2*(size of SOMESTRUCT) can be coded as 2*SOMESTRUCT.  Ratch

drizz

i somehow knew you would write that :), Yes i know (i just forgot to write the third option).
its my personal preference to use sizeof, as i use it in C,C++ too.
everyone his own  :P
The truth cannot be learned ... it can only be recognized.

iaNac

Ratch - I finally had time to study your example and found it extremely helpful.  I got a lot out of it!

Thanks again - iaNac