The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: juancabot on October 12, 2005, 01:31:35 PM

Title: Hello!! How do I represent data structures on MASM32??
Post by: juancabot on October 12, 2005, 01:31:35 PM
Hello!!

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

Thanks!!
Title: Re: Hello!! How do I represent data structures on MASM32??
Post by: rags on October 12, 2005, 02:58:54 PM
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
Title: Re: Hello!! How do I represent data structures on MASM32??
Post by: dsouza123 on October 12, 2005, 05:54:51 PM
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
Title: Re: Hello!! How do I represent data structures on MASM32??
Post by: diablo2oo2 on October 12, 2005, 08:54:34 PM
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...)
Title: Re: Hello!! How do I represent data structures on MASM32??
Post by: 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
Title: Re: Hello!! How do I represent data structures on MASM32??
Post by: diablo2oo2 on October 13, 2005, 07:23:57 PM
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.
Title: Re: Hello!! How do I represent data structures on MASM32??
Post by: dsouza123 on October 13, 2005, 08:36:42 PM
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
Title: Re: Hello!! How do I represent data structures on MASM32??
Post by: QvasiModo on October 13, 2005, 09:01:30 PM
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