News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

DUP operator

Started by Kyoy, January 08, 2005, 02:11:42 PM

Previous topic - Next topic

Kyoy

I am kind of confused as to when to use them. Can someone show me when and how to apply using the DUP operator in Masm.

hutch--

128 bytes uninitialised data and 260 bytes of initialised to zero data.


  .data?
    buffer db 128 dup (?)

  .data
    nubuffer db 260 dup (0)
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Kyoy

Quote from: hutch-- on January 08, 2005, 02:28:25 PM
128 bytes uninitialised data and 260 bytes of initialised to zero data.


  .data?
    buffer db 128 dup (?)

  .data
    nubuffer db 260 dup (0)


Thanks. I know that. But when do you ever need to have 260 bytes of initialised to zero data? or 128 bytes of uninitialised data?

John

In an array or a buffer that will accept a string etc.

MichaelW

The 260 bytes would probably be for a path string (260 is the value of the MAX_PATH constant from WINDOWS.INC).
eschew obfuscation

hutch--

Here is a string array built at assembly time.

.data?
  st1 db 128 dup (?)
  st2 db 128 dup (?)
  st3 db 128 dup (?)
  st4 db 128 dup (?)

.data
  sarr dd st1,st2,st3,st4

Either adress the array as a whole with "sarr" or as individual members with st1 etc ...
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Kyoy

Well, in a program demonstrating the xor encryption in a book, i saw something like this

KEY = 239 ; any value between 1-255
BUFMAX = 128 ;maximum buffer size

.data
...
...
buffer BYTE BUFMAX+1 dup(0)
bufsize DWORD ?


That was where i got confused. Why is BUFMAX 128? Why can't the buffer size go beyond 128? I mean why does the buffer size needs to be 128 specifically.
Also at the .data portion, what does that buffer BYTE BUFMAX+1 dup(0) means? Why BUFMAX+1, why not just BUFMAX. Is the +1 necessary? and why is dup(0) used here. Heres where i got confused about the dup(0) issue.

Much appreciated if someone can clear this up, thanks.

John

To answer the first question would require us to have the book you are using. You would specify the size of the buffer depending on your own needs. In this case the buffer is actually one larger than BUFMAX so it would be 129. For the seond question, it is probably filled with 0's because that is the string terminator in Windows. That is also the most logical reason for the extra byte in the buffer.

Bieb

Quote from: hutch-- on January 09, 2005, 04:28:01 AM
Here is a string array built at assembly time.

.data?
  st1 db 128 dup (?)
  st2 db 128 dup (?)
  st3 db 128 dup (?)
  st4 db 128 dup (?)

.data
  sarr dd st1,st2,st3,st4

Either adress the array as a whole with "sarr" or as individual members with st1 etc ...


Hold on, what exactly are you doing here?  Are you filling the memory locations after sarr with the adresses of st1, etc.?

John

Yes, "sarr" is what can be used as an array that has st1, st2, st3, and st4 as it's members. The strings st1, st2, st3, and st4 can then be referenced through sarr or directly.

hutch--

Bieb,

Its one of those "cute" things that MASM will do if it knows the address at assembly time is substitute the name of the variable with its address while its being assembled. Comes in handy with labels and items created in the data sections and you can use it within the complex addressing modes for instruction addressing as well.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ic2

This is the best place to question about DUP...OPERATOR  so

My exe is 20.5kb ...  When i add this new buffer size with dup (?) or dup (0) I get the exact same results.

Buffer   BYTE   10000   DUP (?)

my exe size rises to 30.5kb

I thought DUP (?) mean it will not go to that size until after the program is EXECUTED.   - - - Un-Initialized

And that if we use DUP (0) it will automatically add that size to the program increasing the size of the exe even before execution..   - - - Initialized


hutch said:
Quote128 bytes uninitialised data and 260 bytes of initialised to zero data.


Forget it, I looked a little harder here and placed it in the proper place... .data?

Ehtyar

I've always found the fact that the size of your executable is directly effected by the amount of uninitialized data quite offensive. How is it that ms never thought of just allocating space at runtime for a value in the header that contained the size of uninitialized data?

Ehtyar.

ToutEnMasm

Hello,
initialised data are initialised by the number you have put between ().Can be 0 or anithing you want.
For example <>  is used for structure and initialised like this <Number or constant,,>.
When you use <> in initialised data,value is 0 by defaut.
Unitialised data stay in the same state when the memory is allocated.The last write of the memory has defined the value of the data.It's for that you use the ? because you are not abble to know what is write in it.It is only random write.
Unitialised data are useless and dangerous,better is initialising all data to 0 as a defaut value.Making that ,you can test the data to know if one action is performed or not.Null values are understanding by the API.Using unitialised data ,you can make a crash ,for example passing a structure to an API.
                                 ToutEnMasm

                                                     

Ehtyar

I can't imagine initializing as 0 would be any less effective in causing a crash. But the question is still not answered, why is it that uninitialized data still bloats your executable? or is there not one...

Ehtyar.