The MASM Forum

General => The Campus => Topic started by: gelatine1 on June 25, 2014, 07:15:57 PM

Title: dp in data segment
Post by: gelatine1 on June 25, 2014, 07:15:57 PM
Hello, this is a very stupid question but I just can't figure it out. How should I use the dp in the data segment ? I tried like this but it gave an error when I tried to compile.
rect dd 0 dp(4)
I just want 4 duplicates of this 0 value.

Thanks in advance
Jannes
Title: Re: dp in data segment
Post by: Gunther on June 25, 2014, 07:24:22 PM
Jannes,

Quote from: gelatine1 on June 25, 2014, 07:15:57 PM
Hello, this is a very stupid question but I just can't figure it out. How should I use the dp in the data segment ? I tried like this but it gave an error when I tried to compile.
rect dd 0 dp(4)
I just want 4 duplicates of this 0 value.

Thanks in advance
Jannes

your question isn't clear for me. Do you mean the dup operator? If so, it's a syntax question.

Gunther
Title: Re: dp in data segment
Post by: gelatine1 on June 25, 2014, 07:35:29 PM
Ohhh Yes I think I meant dup and yes indeed it's a syntax question. I'm not sure how to use it.
Title: Re: dp in data segment
Post by: jj2007 on June 25, 2014, 07:43:30 PM
Here is an example. Launch the exe with Olly and see what it does...

include \masm32\include\masm32rt.inc

.data?
rc   RECT 5 dup(<>)

.code
start:
   mov eax, offset rc
   mov ecx, offset rc.top
   mov edx, rc[0*RECT].right
   mov edx, rc[1*RECT].right
   mov edx, rc[2*RECT].right
   exit

end start
Title: Re: dp in data segment
Post by: gelatine1 on June 25, 2014, 07:56:24 PM
Oh yes I see :)  If I want to declare 4 dwords containing 0 then I should use
rect dd 4 dup(0) instead of rect dd 0 dup(4).
Thanks for the help guys
Title: Re: dp in data segment
Post by: dedndave on June 25, 2014, 09:52:56 PM
that will work
however, for rectangles, we generally use a RECT structure

http://msdn.microsoft.com/en-us/library/dd162897%28v=vs.85%29.aspx (http://msdn.microsoft.com/en-us/library/dd162897%28v=vs.85%29.aspx)

most of the MS structures are defined for you in windows.inc
RECT STRUCT
  left    dd      ?
  top     dd      ?
  right   dd      ?
  bottom  dd      ?
RECT ENDS


now, you can do something similar to what Jochen showed you
however - his code creates 5 RECT structures   :biggrin:
you probably only need one

this will create an uninitialized RECT
we usually place it in the .DATA or .DATA? section
rc RECT <>

if you would like to, you may initialize the structure (.DATA section)
it has 4 members, so....
rc RECT <10,25,30,35>

you may access the members as
    mov     eax,rc.right

or, use a register for the address and
    mov     edx,offset rc
    mov     eax,[edx].RECT.right
Title: Re: dp in data segment
Post by: jj2007 on June 25, 2014, 10:26:22 PM
Quote from: dedndave on June 25, 2014, 09:52:56 PMor, use a register for the address and
    mov     edx,offset rc
    mov     eax,[edx].RECT.right

This is indeed a good solution because its encoding is much smaller than for a global rc.right (for example). Typically, you would use a non-volatile register such as esi, edi, ebx.
Title: Re: dp in data segment
Post by: Gunther on June 25, 2014, 11:06:06 PM
That's all not bad but back to the question of DUP. One can use, for example:

     db     128  dup (?)

That statement would reserve 128 bytes with arbitrary content.

Gunther
Title: Re: dp in data segment
Post by: MichaelW on June 26, 2014, 06:55:44 AM
Gunther,

I'm not sure how this is so, because the listing shows that the reserved bytes are in the .data section, but in my tests under Windows the reserved bytes were zeroed.

Title: Re: dp in data segment
Post by: nidud on June 26, 2014, 07:38:08 AM
deleted
Title: Re: dp in data segment
Post by: Gunther on June 27, 2014, 12:33:42 AM
Quote from: MichaelW on June 26, 2014, 06:55:44 AM
I'm not sure how this is so, because the listing shows that the reserved bytes are in the .data section, but in my tests under Windows the reserved bytes were zeroed.

Either a design decision or a feature of Windows. An error is unthinkable. But joke apart, it's interesting to know.

Gunther