4

I'm currently learning assembly programming by following Kip Irvine's "Assembly Language for x86 Processor". In section 3.4.12, the author states:

The .DATA? directive declares uninitialized data. When defining a large block of uninitialized data, the .DATA? directive reduces the size of a compiled program. For example, the following code is declared efficiently:

.data
smallArray DWORD 10 DUP(0) ; 40 bytes
.data?
bigArray DWORD 5000 DUP(?) ; 20,000 bytes, not initialized

The following code, on the other hand, produces a compiled program 20,000 bytes larger:

.data
smallArray DWORD 10 DUP(0) ; 40 bytes
bigArray DWORD 5000 DUP(?) ; 20,000 bytes

I want to see the memory footprint of each version of the code after the program is compiled, so I can see the effect of .data? for myself, but I'm not sure how it can be done.

halfer
  • 19,824
  • 17
  • 99
  • 186
Thor
  • 9,638
  • 15
  • 62
  • 137
  • 2
    It's laid out in the link map. Use /Fm switch if compiling **and** linking with ml.exe, or /link if linking in a separate step using link.exe. – Paul Houle Jun 22 '17 at 04:31
  • 1
    [*Very* similar question](https://stackoverflow.com/questions/7137049/how-does-masm-data-directive-work-internally); I'm considering combining these two and marking this one as a duplicate to keep the information together in one place. – Cody Gray - on strike Jun 22 '17 at 07:33
  • @CodyGray I agree with you, they are very similar indeed – Thor Jun 22 '17 at 08:12
  • @CodyGray: Marked the other as a dup of this, since this now has a more detailed answer. – Peter Cordes Jun 28 '17 at 04:30

1 Answers1

5

I want to see the memory footprint of each version of the code after the program is compiled…

The difference is in the size of the compiled executable, not the size of its image in memory when it's being executed.

In brief: most modern operating systems have a way for an executable to declare a memory region as "zero filled". The executable only needs to say how big the region is, so it's much smaller than if it included a bunch of literal zeroes for that region.

  • hi duskwuff, love the golden retriever in your profile pic, i have a golden retriever too :) – Thor Jun 22 '17 at 08:13