News:

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

What does db 50 dup (?) mean?

Started by ragdogz, January 22, 2009, 09:17:53 PM

Previous topic - Next topic

ragdogz

Hi, i'm sorry i'm a newbie in assembly..
I have some source codes i got from internet. they work fine and i often play with them, including modifying them. the program read data from text file like this:

.data
username db "user",0


.data?
user db 50 dup (?)


can someone explain completely, what does db 50 dup (?) mean? what is it for? and there are some other lines similiarly like that one, example db 1024 dup (?), but if i change it to db 256 dup (?) then the program will be unstable..

Iczelion said this:

Quote from: Iczelion.data?
This section contains uninitialized data of your program. Sometimes you just want to preallocate some memory but don't want to initialize it. This section is for that purpose. The advantage of uninitialized data is: it doesn't take space in the executable file. For example, if you allocate 10,000 bytes in your .data? section, your executable is not bloated up 10,000 bytes. Its size stays much the same. You only tell the assembler how much space you need when the program is loaded into memory, that's all.

from what he said, that section is for telling the assembler how much space i need when the program is loaded into memory.
so, how do i calculate space i need in memory?

and there are some lines that doesnt mention space like this:

size dd ?

what does it mean? how much space i tell assembler by that dd? ?

thx for ur explanation..

cobold

Quotecan someone explain completely, what does db 50 dup (?) mean?

It means that you allocate 50 bytes of memory, and these 50 bytes are uninitialized, i.e. you don't know the content,
while

.data ; no question mark here - it is INITIALIZED data section
user db 50 dup(32) ; allocates also 50 bytes of memory, but these are initialized with space (32)

Quotewhat does it mean? how much space i tell assembler by that dd? ?
I think an example will help you to understand, space allocation at runtime:


.data?
    pMem    dd  ?   ; a pointer to a memory location, we don't know any value YET
    cByt    dd  ?   ; number of bytes to allocate
.code
  mov cByt,val(input())  ; user enters how many bytes we need (programmer can't know this before - so he left cByt UNINitialized :-)
    invoke GlobalAlloc,GMEM_FIXED,cByt ; now we allocate cByt of memory
    mov pMem,eax   ; funtion returns a pointer to that memory in eax, we save this pointer in pMem
....
....
    mov esi,pMem ; esi now points to our memory-block
    mov DWORD PTR [esi],0 ; that's how we access memory - in this case we mov 0 to the 1st DWORD of pMem
    mov DWORD PTR [esi+4] ; move 0 to 2nd DWORD of pMem



all clear now?

hth
Cobold

MichaelW

ragdogz,

For DUP, see the Operators section in Chapter 3 of the MASM Reference Guide here. And for DD, DW, DB, etc see Chapter 4 of the MASM Programmer's Guide.
eschew obfuscation

ragdogz

ok thx..
gimme some times to understand it properly and i'll post some next questions regarding this.. :bg