PDA

View Full Version : PC's


ads
01-05-2001, 07:25 AM
Please tell me whether PCs have seperate types of memory for instructions and data? If they do what differnt types are there, if not, how does the CPU distinguish between instuctions and data?

ixl
01-05-2001, 10:27 AM
Good question.
No, PCs do not have different areas for instructions and data. What is an "instruction" and what is "data" depends on how the bytes are interpreted. If you give a stream of numbers to something that wants to execute them, it will try to interpret them as instructions; if you do this with something that isn't a program, you get an error as a result.
This flexibility allows some files to be data in one context, and instructions in another. For example, a compiler operates on files that it considers "data", but produces instructions as a result that can be executed.

------------------
Charles M. Kozierok
Webslave, The PC Guide (http://www.PCGuide.com)
Comprehensive PC Reference, Troubleshooting, Optimization and Buyer's Guides...
Note: Please reply to my forum postings here on the forums. Thanks.

xor_chad
01-05-2001, 10:13 PM
Hey
Not to contradict Charles but although the system memory(L3) itself makes no distinction between the two, the CPUs memory(L1)itself does have a place for data and a place for instructions inside its registers.

The code itself is in Code Space and is controlled by the Instruction Pointer.

Local variables and function parameters are in the Stack Space and controlled by the Stack Pointer.

Global variables are in Global Name Space.

The rest of memory (mostly) is given to the Free Store, which is an area of memory that is not freed as the code goes in and out of scope.
This is the area that generally causes Memory Leaks when not explicitly released when the program ends.

Anyway I hope this helps if this is what you were curious about.

This is for the x86 based cpu that is loosely called the 'PC'.
Other architectures use different means and different names.

To understand the actual process would take a few pages but these are the few relevant register names. Laters...

------------------
Chad Wilson
C++/ASM Programmer
PC Support Technician

[This message has been edited by xor_chad (edited 01-05-2001).]

Beno
01-06-2001, 09:15 AM
I agree with Charles, this is a good question!!
http://www.PCGuide.com/ubb/biggrin.gif
When the CPU generates an instruction it comes out with an address to see where to locate the data that its looking for.
When the instruction is on the way to RAM it goes to L1 and L2 cache and the instruction is then put into a buffer (temporary holding bay) and then the instruction is split up into parts. If one of these parts, the tag part of the instructions matches any one of the tags in the L1 or L2 cache then it gets the data out of the cache slot instead of going all the way to RAM, and then gives it back to the ALU to play around with. This is why caches are so beneficial!!

Charles is right in that data and instructions are held in the same spot in memory when the computer is turned of - the hard drive. But when the computer is on, then the instructions are held in RAM, this is where programs are held and programs are instructions!! Data is also in RAM because if your writing something on a word processor and the power is cut then you loose all your data!! so therefore it holds both!!.............but like Charles said, its the way the data ( 0's and 1's ) are interpreted in where the magic of computing lies.

And if you want to get to the nitty gritty of it then Chad is also right but more in depth in terms of programming.
One more thing that might be of interest to you is that registers are extrememly fast memory that are holding places for instructions to make there computations.

Beno

------------------
Have a nice day

ixl
01-07-2001, 11:26 AM
No real disagreement here. Yes, some CPUs (not all) have separate instruction and data caches, and good that you pointed that out, thanks.
I would add though that even within the regular system memory, there is no distinction, really, between instructions and data. It depends on what is acting on them, and how.

------------------
Charles M. Kozierok
Webslave, The PC Guide (http://www.PCGuide.com)
Comprehensive PC Reference, Troubleshooting, Optimization and Buyer's Guides...
Note: Please reply to my forum postings here on the forums. Thanks.