title: Assembly - .data, .code, and registers...?
body: <p>So this morning I posted a confused question about assembly and I received some great genuine help, which I really appreciate.</p>
  
  <p>And now I'm starting to get into assembly and am beginning to understand how it works.</p>
  
  <p>Things I feel I understand alright include the stack, interrupts, binary/hex, and in general what most of the basic operations do (jmp, push, mov, etc).</p>
  
  <p>Concepts that I'm struggling to understand and would like help with are below - it would be a huge help if you could address any of the following:</p>
  
  <ol>
  <li>What exactly is happening in the .data section? Are those variables we're declaring?</li>
  <li>If so, can we declare variables later in the code section? If not, why not? If so, how, and why do we use the data section then?</li>
  <li>What's a register? How does it compare to a variable? I mean I know it's a location that stores a small piece of information... but that sounds exactly like a variable to me.</li>
  <li>How do I make an array? I know this seems kind of random, but I'm curious as to how I'd go about doing something like this.</li>
  <li>Is there a list somewhere of common practices for what each register should be used for? I still don't get them completely, but have noticed some people saying, for example, that a certain register should be used to store 'return values' from procedures - is there a comprehensive or at least informative list of such practices?</li>
  <li>One of the reasons I'm learning assembly is to better understand what's going on behind my high level code. With that in mind - when I'm programming in c++, I'm often thinking about the stack and the heap. In assembly I know what the stack is - where's the 'heap'?</li>
  </ol>
  
  <p>Some info: I'm using masm32 with WinAsm as an IDE, and I'm working on Windows 7. I have a lot of prior experience programming in higher level languages such as c++/java.</p>
  
  <hr>
  
  <p>edit: Thanks for the help everyone, extremely informative as usual! Great stuff! One last thing though - I'm wondering what the difference is between the Stack Pointer, and the Base pointer, or ESP and EBP. Can someone help me out?</p>
  
  <p>edit: I think I get it now... ESP always points to the top of the stack. However, you can point EBP at whatever you want. ESP is automatically handled but you can do whatever you want with EBP. For example:</p>
  
  <pre><code>push 6
  push 5
  push 4
  mov EBP, ESP
  push 3
  push 2
  </code></pre>
  
  <p>In this scenario, EBP now points to the address holding 4, but ESP now points to the address holding 2.</p>
  
  <p>In a real application 6, 5, and 4 could have been function arguments, whereas 3 and 2 could be local variables within that function.</p>