Hi everyone,
So this morning I posted a confused question about assembly and I received some great genuine help, which I really appreciate.
And now I'm starting to get into assembly and am beginning to understand how it works.
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).
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:
- What exactly is happening in the .data section? Are those variables we're declaring?
- 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?
- 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.
- 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.
- 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?
- 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'?
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.
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?
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:
push 6
push 5
push 4
mov EBP, ESP
push 3
push 2
In this scenario, EBP now points to the address holding 4, but ESP now points to the address holding 2.
In a real application 6, 5, and 4 could have been function arguments, whereas 3 and 2 could be local variables within that function.