News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

dp in data segment

Started by gelatine1, June 25, 2014, 07:15:57 PM

Previous topic - Next topic

gelatine1

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

Gunther

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
You have to know the facts before you can distort them.

gelatine1

Ohhh Yes I think I meant dup and yes indeed it's a syntax question. I'm not sure how to use it.

jj2007

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

gelatine1

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

dedndave

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

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

jj2007

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.

Gunther

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
You have to know the facts before you can distort them.

MichaelW

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.

Well Microsoft, here's another nice mess you've gotten us into.

nidud

#9
deleted

Gunther

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
You have to know the facts before you can distort them.