Hello!! How do I represent data structures on MASM32??

Started by juancabot, October 12, 2005, 01:31:35 PM

Previous topic - Next topic

juancabot

Hello!!

I would want how do I represent data structures on MASM32? Which is the respect code??

Thanks!!

rags

Hi Juancaobt, welcome to the forum.

First off, try looking in the masm32 help file that came with the masm package.
Look for STRUCT, and it should explain it to you there.
If you are still having problems come back, and we'll try to help.
rags
God made Man, but the monkey applied the glue -DEVO

dsouza123

Examples from windows.inc, part of MASM32.


POINT STRUCT
  x  DWORD ?
  y  DWORD ?
POINT ENDS

NMHDR STRUCT
    hwndFrom    DWORD ?
    idFrom      DWORD ?
    code        DWORD ?
NMHDR ends

NMREBARCHILDSIZE STRUCT
  hdr       NMHDR       <>
  uBand     DWORD       ?
  wID       DWORD       ?
  rcChild   RECT        <>
  rcBand    RECT        <>
NMREBARCHILDSIZE ENDS


To use the POINT struct in a program.

.data
  apt POINT <30,50>  ; initialize both items
  bpt POINT <?,40>    ; initialize only the second
  cpt POINT <?,?>
  dpt POINT <>
 
.code
  mov bpt.x, eax   ; copy eax into x item of bpt struct
  invoke TextOut,hdc,bpt.x,bpt.y,ADDR AppName,eax

Also some of the tutorials use the structs declared in windows.inc
for example  MOUSE.ASM from TUTE07

diablo2oo2

i prefer to use structure with registers.

...
mov esi,offset bpt
assume esi:ptr POINT
mov [esi].y,eax
...
assume esi:nothing
...


the compiled code is shorter then. (i know it doesnt make much sense in general, but i like it small and beautiful, in general i prefer to use registers...)

QvasiModo

Quote from: diablo2oo2 on October 12, 2005, 08:54:34 PM
the compiled code is shorter then.

Not if you include the size of "mov esi, offset bpt"...  :wink

diablo2oo2

Quote from: QvasiModo on October 12, 2005, 10:30:23 PM
Quote from: diablo2oo2 on October 12, 2005, 08:54:34 PM
the compiled code is shorter then.

Not if you include the size of "mov esi, offset bpt"...  :wink

lol, of cause it will be shorter when you use the structure a lot and not only one entry like in my example.

dsouza123

Another data structure is the array.

.data
  hold dd 64 dup (0)   ; an array of 64 dwords initialized with zeros

a related one is the (zero terminated) string

  szStr db "ABCDEFGHIJKL",0  ; a 13 byte, 12 characters + 1 zero valued char string

QvasiModo

Quote from: diablo2oo2 on October 13, 2005, 07:23:57 PM
lol, of cause it will be shorter when you use the structure a lot and not only one entry like in my example.

I know, just pulling your leg there :bg