News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

A quick question & answer #2 pre processing things at building time

Started by LordAdef, February 07, 2019, 08:44:19 AM

Previous topic - Next topic

LordAdef

Quote  Dim MyRect() As RECT
  For_ ecx=0 To 99
        mov MyRect(ecx, left), Rand(100)
        mov MyRect(ecx, bottom), Rand(100)
  Next
I understand you masmBasic, clear. 
In terms of Masm, I would imagine 
1.alloc the sizeof my myStruct 
2. use "assume" the ptr as myStruct 
Does that make sense, right? Is there another way in masm/masm32?

jj2007

There are various ways to achieve that, for example
.data?
TheRect RECT 20 dup(<>)

.code
start:
  mov esi, offset TheRect
  mov ecx, 5  ; rectangle #5
  imul eax, ecx, RECT
  mov edx, [esi+eax.RECT.bottom]

aw27

mov esi, offset TheRect
mov edx, (RECT PTR [esi[5*sizeof RECT]]).bottom  :t

jj2007

Nice :t

Here are two more:
include \masm32\include\masm32rt.inc ; pure Masm32

MyRect equ [esi.RECT] ; equates are a nice option

Rect MACRO index, element
  if (opattr index) eq 36
EXITM <TheRect[index*RECT][RECT.element]>
  else
imul eax, index, RECT ; register or memvar
add eax, offset TheRect
exitm <[eax.RECT.&element]>
  endif
ENDM

.data
TheRect RECT 5 dup (<>)
.code
start:

  mov esi, offset TheRect
  m2m ebx, 5

  mov MyRect.bottom[5*RECT], 100
  print str$(Rect(ebx, bottom)), 9, "Rect(ebx, bottom)", 13, 10
  mov edx, Rect(ebx, bottom)
  inc edx
  mov Rect(ebx, bottom), edx
  print str$(Rect(ebx, bottom)), 9, "Rect(ebx, bottom)", 13, 10
  inc Rect(ebx, bottom)
  inkey str$(Rect(5, bottom)), 9, "Rect(5, bottom)", 13, 10
  exit

end start