Reputation: 1331
We're learning about how a computer actually executes a C program in class. I'm very unclear about how the following pieces actually fit together: processor (or CPU), register files, runtime stack, program counter, virtual addresses, program memory.
Let me explain what I currently know or think I understand:
There exists a stack onto which instructions can be pushed so that the computer can execute said instructions. Questions: Where is this stack register located in regards to the CPU? Where are the instructions being pulled from?
This stack can hold registers like %eax, %ecx, %edx, etc. which sometimes holds numerical values and sometimes holds addresses which point to items stored in "memory". Question: Again where is this memory located?
There exists a program memory that contains executable machine code for the program, blocks of memory the user allocates, and a runtime stack for managing procedural calls and returns. Questions: Again, where is this program memory located in relationship to the CPU?
My thoughts are so jumbled right now I'm not even sure I'm asking the right questions or if these topics are even supposed to be related...a diagram of sorts would be really helpful because I just can't see how everything is supposed to fit together. I don't even know if what I'm saying is even remotely correct...
Upvotes: 2
Views: 1631
Reputation: 690
Basically, you need to have a look at the : Von Neumann Architecture
The picture on this site provides a good overview on the main components of a PC: http://www.doc.ic.ac.uk/~eedwards/compsys/memory/
However, I'll explain a bit of this stuff with focus on your questions (where does anything reside in relationship to the CPU):
CPU
CPU: A microchip that is often called the "brain" of a computer - it does the actual calculation stuff. A program is a simple "list" of instructions that is executed, beginning with the very first instruction.
ALU: (Arithmetic Logic Unit) Resides inside the CPU and actually executes the calculations
Registers: Memory cells that reside inside the CPU. Store values needed in the calculations (or their results)
Program Counter: A special register inside the CPU that contains a reference to the instruction that will be executed.
RAM (Memory) The RAM is the "working" memory of your computer.
The RAM is simply a large amount of cells to store values
The RAM is much faster than the hard disk. The RAM is much slower than the registers inside the CPU though
When you start a program, its instructions are loaded from your hard disk into the RAM
Programs often need to work on a lot of data (these are your variables, objects, etc. you use while programming) - these are also stored inside the RAM
A stack is a data structure that resides inside the RAM (at least in our PC's..). The stack holds local variables, function parameters and addresses of functions (If you call function B from function A, the address of the next instruction of function A is stored on the stack. So when the program finishes function B it can jump right back to the place where it left function A) (Search Wikipedia for "stack" ..)
The CPU (with its registers) and the RAM (data memory, stack, ...) are connected together with the BUS.
This is just an overview, it gets really taff when you look into the details - I hope it helps a bit, though :-)
Upvotes: 3